Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

internal/gitserver: Improvement to RepoInfo method#39358

Merged
indradhanush merged 7 commits into
mainfrom
ig/gitserver-client-repoinfo
Jul 27, 2022
Merged

internal/gitserver: Improvement to RepoInfo method#39358
indradhanush merged 7 commits into
mainfrom
ig/gitserver-client-repoinfo

Conversation

@indradhanush

@indradhanush indradhanush commented Jul 25, 2022

Copy link
Copy Markdown
Contributor

This PR makes two functional improvements to the RepoInfo client method and a semantic one.

The functional improvements are:

  1. Limit length of map to max number of shards
  2. Do not hide response body for failed HTTP reqs

The semantic improvement is:

  1. Add comment and rename shard -> repoInfoReq

Note to reviewers

It's recommended to look at each commit sequentially to view the changes in an isolated way. This should make it easier to understand the changes in this PR vs looking at the entire diff at the same time.

The pain point with no response body for non 200 errors was first observer in this customer issue which also led to the other improvements as I was reading and understanding this code.

Test plan

  • Added tests.
  • Did end to end UI testing. Applied the following diff to the code to simulate 500 HTTP response.

image

UI should now look like this:

image

VS current behaviour without this PR:

image

Note for time travellers

Without strings.TrimSpace

image

With strings.TrimSpace

image

For reasons unknown now, we were making an unnecesarily high number of
requests since the `shards` map being created as a factor of number of
repos. But it should only ever be the total number of shards of
gitserver currently running.
I spent an unnecessarily high amount of time trying to "fix" this code
for what I thought was not the optimal way of collecting and sending
the API requests, until I had the aha moment and finally understood
why we're doing it this way.

As a result, added a comment to clarify this as well as renamed shard
to repoInfoReq as it doesn't look like that's the right name here and
confused me somewhat more when I was reading this code.
Currently, if the API server returns anythign but a 200 OK, we return
the HTTP status, but swallow the HTTP body. This will contain
important information that will be helpful to understand the error,
which is not possible as of now.
@cla-bot cla-bot Bot added the cla-signed label Jul 25, 2022
@indradhanush indradhanush marked this pull request as ready for review July 25, 2022 12:11
@indradhanush indradhanush changed the title internal/gitserver: Improvement to RepoInfo metho internal/gitserver: Improvement to RepoInfo method Jul 25, 2022
@sourcegraph-bot

sourcegraph-bot commented Jul 25, 2022

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff ac88f10...0033d5c.

Notify File(s)
@ryanslade internal/gitserver/client.go
internal/gitserver/client_test.go

@indradhanush indradhanush requested a review from a team July 25, 2022 12:40

@mollylogue mollylogue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thx for the detailed breakdown of the changes

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mollylogue mollylogue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question: have you tested what this looks like in the error scenario? Does the error now show up in the UI in addition to the status code?

@indradhanush

Copy link
Copy Markdown
Contributor Author

Quick question: have you tested what this looks like in the error scenario? Does the error now show up in the UI in addition to the status code?

@mollylogue I noticed that this method doesn't have any tests at all. I'm holding off merging until I write some tests. Yeah, at the moment only the 500 status code is seen.

@indradhanush

Copy link
Copy Markdown
Contributor Author

@mollylogue Now added tests with what we expected to see in the UI. I haven't tested the UI itself but the test should be sufficient since we're not changing the core behaviour.

@indradhanush indradhanush requested a review from a team July 27, 2022 11:05
@sashaostrikov

Copy link
Copy Markdown
Contributor

I haven't tested the UI itself but the test should be sufficient since we're not changing the core behaviour.

@indradhanush I suggest spending a bit extra time and test the UI too, more thorough testing is something we can do better as a team, especially taking BB Projects sync project's lessons learned into consideration 😅

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New changes LGTM!

Additional thanks for adding tests 🙏

I've added a note about testing the UI as well, for the sake of testing completeness :)

Also "reason" is better than "body".
@indradhanush

Copy link
Copy Markdown
Contributor Author

@sashaostrikov That's a good callout! Thank you. The UI test was fruitful as well. Made a small tweak to the error message and error message handling. 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants