Skip to content

Permit toggling rate limit check by consumers - #3386

Merged
gmlewis merged 2 commits into
google:masterfrom
manicminer:togglable-rate-limit-check-bypass
Jan 7, 2025
Merged

Permit toggling rate limit check by consumers#3386
gmlewis merged 2 commits into
google:masterfrom
manicminer:togglable-rate-limit-check-bypass

Conversation

@manicminer

@manicminermanicminer commented Dec 13, 2024

Copy link
Copy Markdown
Contributor

Export BypassRateLimitCheck to allow toggling of rate limit checks by consumers.

I am handling rate-limited retries with my own RoundTripper, and the built-in checks are preventing me from doing so because it simply errors early instead of attempting a request and handling backoff separately. This change simply exports the context key used internally by the package, so that downstream consumers can disable this pre-emptive check.

manicminer added a commit to manicminer/gitlab-migrator that referenced this pull request Dec 13, 2024
@codecov

codecovBot commented Dec 13, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.21%. Comparing base (2b8c7fa) to head (9b253b9).
Report is 215 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #3386 +/- ##
==========================================
- Coverage 97.72% 92.21% -5.51% 
==========================================
Files 153 173 +20 Lines 13390 14770 +1380 ==========================================
+ Hits 13085 13620 +535 - Misses 215 1060 +845 
Partials 90 90 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, @manicminer !
Right before line 804 in github/github.go, could you please add a comment that demonstrates how an end-user would override this feature in their own code?

@gmlewisgmlewis added the NeedsReview PR is awaiting a review before merging. label Dec 13, 2024
DiegoDev2

This comment was marked as resolved.

@DiegoDev2

DiegoDev2 commented Dec 14, 2024

Copy link
Copy Markdown
Contributor

hi, did you update the unit tests here ? @manicminer

I'm sorry, I got confused

@manicminer

Copy link
Copy Markdown
ContributorAuthor

@DiegoDev2 Thanks for the review! I've added a go doc comment for this constant.

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, @manicminer !
LGTM.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

Comment threadgithub/github.go
// BypassRateLimitCheck prevents a pre-emptive check for exceeded primary rate limits
// Specify this by providing a context with this key, e.g.
// context.WithValue(context.Background(), github.BypassRateLimitCheck, true)
BypassRateLimitCheck requestContext = iota

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.

Why is BypassRateLimitCheck exported? Can't it remain bypassRateLimitCheck?

@tomfeigintomfeiginDec 24, 2024

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.

Oh I missed that you wanted to trigger this from outside the library.
I suggest that there will be wrapper functions like:

funcContextWithBypassRateLimitCheck(ctx context.Context) context.Context {
returncontext.WithValue(ctx, bypassRateLimitCheck, struct{}{})
}

You don't even need to export the getter function for this value.

Anyway, as the code is now is fine

Comment threadgithub/github.go
// BypassRateLimitCheck prevents a pre-emptive check for exceeded primary rate limits
// Specify this by providing a context with this key, e.g.
// context.WithValue(context.Background(), github.BypassRateLimitCheck, true)
BypassRateLimitCheck requestContext = iota

@tomfeigintomfeiginDec 24, 2024

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.

Oh I missed that you wanted to trigger this from outside the library.
I suggest that there will be wrapper functions like:

funcContextWithBypassRateLimitCheck(ctx context.Context) context.Context {
returncontext.WithValue(ctx, bypassRateLimitCheck, struct{}{})
}

You don't even need to export the getter function for this value.

Anyway, as the code is now is fine

@manicminer

Copy link
Copy Markdown
ContributorAuthor

Thanks for the reviews! Could this be merged? It looks like the codecov check is a false negative / unrelated to this PR?

SCR-20250107-lqsa

@gmlewisgmlewis removed the NeedsReview PR is awaiting a review before merging. label Jan 7, 2025
@gmlewis

Copy link
Copy Markdown
Collaborator

Thank you, @tomfeigin and @manicminer !
Merging.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@manicminer@DiegoDev2@gmlewis@tomfeigin