Skip to content
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

Permit toggling rate limit check by consumers #3386

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

manicminer
Copy link

@manicminer manicminer commented Dec 13, 2024

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
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.21%. Comparing base (2b8c7fa) to head (9b253b9).
Report is 200 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.

Copy link
Collaborator

@gmlewis gmlewis left a comment

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?

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

This comment was marked as resolved.

@DiegoDev2
Copy link
Contributor

DiegoDev2 commented Dec 14, 2024

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

I'm sorry, I got confused

@manicminer
Copy link
Author

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

Copy link
Collaborator

@gmlewis gmlewis left a comment

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.

// 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
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?

Copy link
Contributor

@tomfeigin tomfeigin Dec 24, 2024

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:

func ContextWithBypassRateLimitCheck(ctx context.Context) context.Context {
    return context.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

// 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
Contributor

@tomfeigin tomfeigin Dec 24, 2024

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:

func ContextWithBypassRateLimitCheck(ctx context.Context) context.Context {
    return context.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsReview PR is awaiting a review before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants