-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add secondary rate limit handling (prevent remote requests) and fix primary rate limit categories #2635
Conversation
I have just realized that the hook must get the client as a parameter (and it's reflected in the tests, where I use the wrong client for the retry). I'll push a fix for that. |
Codecov Report
@@ Coverage Diff @@
## master #2635 +/- ##
==========================================
+ Coverage 98.05% 98.07% +0.02%
==========================================
Files 130 130
Lines 11257 11302 +45
==========================================
+ Hits 11038 11085 +47
+ Misses 150 148 -2
Partials 69 69
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Hmmm... I'm not sure I'm happy about these changes, and I've got a heavy workload right now. Please give me a week to mull this over. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @gal-legit .
I think this will be beneficial, but was initially unhappy with the added complexity in BareDo.
Let's move forward with the PR, and I apologize for the delay.
Please see if you can handle the currently-uncovered code path with a unit test if possible, and thank you for the very comprehensive tests you have already added!
hey @gal-legit, thanks for the feedback! I feel you - this PR adds complexity and new behavior to the client, and I don't feel too comfortable with adding this "mess" to the very elegant and clean style of the client. I think that we can actually benefit from the delay. Check out secondaryRateLimitWaiter here. Let me know what you think, and I'll continue from there. |
Ah, genius! I think handling it in an external-to-this-repo RoundTripper is a thing of beauty! Thank you, @gal-legit ! |
@gmlewis cool! I'll do the separation and update the PR with all the fixes and reference when it's ready. |
Hmmm... would that tie this "go-github" repo to the external RoundTripper repo? |
|
OK, cool... I think I understand, but it will become more clear as I see the PR update. |
I have the new repo ready (https://github.com/gofri/go-github-ratelimit), |
Woohoo! I gave it its very first GitHub star! 😄 |
@gmlewis I pushed the new version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @gal-legit !
Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
@gmlewis oops, done |
We keep getting linter errors.
It looks like you need to make a versioned release (0.0.1 maybe?) of your new external package, then update this PR to explicitly pull in that version in the |
It looks like there is a problem on Windows... I think it may have to do with how time comparisons are performed in your test.
Please check out time.Equal and see if you can fix this. |
@gmlewis |
I find it bizarre that only the Windows version of the test caught the issue, and not the Linux build!?!?!? OK, thanks. I have to step out but hopefully will get back to this PR later tonight. |
LOL, I found it a bit embarrassing for me, being a Linux kernel engineer. |
Cool! I'd love to ask you about your favorite distros, but this is probably not the right forum. 😂 |
github/github_test.go
Outdated
@@ -1136,6 +1141,36 @@ func TestDo_rateLimit(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestDo_rateLimitCategory(t *testing.T) { | |||
if c := category(http.MethodGet, "/"); c != coreCategory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason that this is not a table-driven test?
I'm OK leaving it as-is if you want... since it would probably be the same number of lines, but I often find that table-driven tests are easier to read because you can just look at the data all in one place.
But no biggie... I'm fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I just tried to follow TestRateLimits & TestRateLimits_overQuota,
but I fixed it to be table-driven (and fixed those two while at it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @gal-legit !
One minor tweak please, plus one question, otherwise LGTM.
After the tweak, we should be ready for an LGTM+Approval from any other contributor to the repo before merging.
github/github_test.go
Outdated
_, err = client.Do(ctx, req, nil) | ||
|
||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_, err = client.Do(ctx, req, nil) | |
if err == nil { | |
if _, err := client.Do(ctx, req, nil); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it'd be a bit misleading to put it inside the if statement because we use err later (casting to *AbuseRateLimitError), but I fixed it anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @gal-legit !
github/github_test.go
Outdated
category rateLimitCategory | ||
}{ | ||
{ | ||
http.MethodGet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a tiny nit, and if you don't want to do this, I'm fine...
but in this repo we prefer to label the fields for clarity-at-a-quick-glance (e.g. method: http.MethodGet,
, etc.).
I'm going to go ahead and approve, but if you want to update, great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, np, I'll do that.
p.s. Ubuntu for desktop, RHEL/fedora-based for server 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @gal-legit !
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thank you, @valbeat ! |
Notes:
fixes #2633
Edit:
Following the conversation in this PR, the actual changes are: