8000 feat: Add DisableRateLimitCheck option to client by stevehipwell · Pull Request #3607 · google/go-github · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Add DisableRateLimitCheck option to client #3607

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

Merged
merged 3 commits into from
Jun 30, 2025

Conversation

stevehipwell
Copy link
Contributor

This PR adds the DisableRateLimitCheck option to the client to disable all client level rate limit logic. It also updates the documentation on the rate limit logic.

Fixes #3585

@gmlewis apologies if there are quality issues with this PR, my VS Code is broken for this codebase so I put off the work as long as I could.

@gmlewis gmlewis changed the title feat: add DisableRateLimitCheck option to client feat: Add DisableRateLimitCheck option to client Jun 27, 2025
Copy link
codecov bot commented Jun 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.33%. Comparing base (efe572e) to head (ad32dc4).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3607   +/-   ##
=======================================
  Coverage   91.33%   91.33%           
=======================================
  Files         184      184           
  Lines       16166    16169    +3     
=======================================
+ Hits        14765    14768    +3     
  Misses       1227     1227           
  Partials      174      174           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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, @stevehipwell!
A couple minor tweaks, please, then we should be ready for merging after getting a second LGTM+Approval from any other contributor to this repo.

@alexandear - might you have time for a code review? Thank you!

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Jun 27, 2025
@stevehipwell
Copy link
Contributor Author

@gmlewis I've fixed the issues you found.

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, @stevehipwell!
LGTM.

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

README.md Outdated
log.Println("hit rate limit")
var rateErr *github.RateLimitError
if errors.As(err, &rateError) {
log.Printf("hit primary rate limit, used %d of %d\n", rateErr.Rate.Used, rateErr.rate.Limit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Printf("hit primary rate limit, used %d of %d\n", rateErr.Rate.Used, rateErr.rate.Limit)
log.Printf("hit primary rate limit, used %d of %d\n", rateErr.Rate.Used, rateErr.Rate.Limit)

Comment on lines +211 to +212
To detect a primary API rate limit error, you can check if the error is a
`RateLimitError`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To detect a primary API rate limit error, you can check if the error is a
`RateLimitError`.
To detect a primary API rate limit error, you can check if the error is a `github.RateLimitError`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really? The text in this block appears to be formatted at 80 characters so that's what I've stuck to.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we need to strictly stick to 80 characters. Many lines in the README already exceed that limit - for example:

GitHub Apps authentication can be provided by different pkgs like [bradleyfalzon/ghinstallation](https://github.com/bradleyfalzon/ghinstallation)

Also, we currently don’t have any linter or formatting rule that enforces a line length limit in the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This block was limited to 80 characters and I've kept it this way other than where there is a link (inspired by the Google Go formatting doc). Given that there is no linting or formatting rules and the README isn't consistent I don't think there is any value in being pedantic here (personally I prefer unbounded line lengths).

Comment on lines +222 to +223
To detect an API secondary rate limit error, you can check if the error is an
`AbuseRateLimitError`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To detect an API secondary rate limit error, you can check if the error is an
`AbuseRateLimitError`.
To detect an API secondary rate limit error, you can check if the error is an `github.AbuseRateLimitError`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

README.md Outdated
log.Println("hit secondary rate limit")
var rateErr *github.AbuseRateLimitError
if errors.As(err, &rateError) {
log.Printf("hit secondary rate limit, retry after %v\n", rateErr.RetryAfter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Printf("hit secondary rate limit, retry after %v\n", rateErr.RetryAfter)
log.Printf("hit secondary rate limit, retry after %v\n", rateErr.RetryAfter)

You can use [gofri/go-github-ratelimit](https://github.com/gofri/go-github-ratelimit) to handle
secondary rate limit sleep-and-retry for you, as well as primary rate limit abuse-prevention and callback triggering.
If you need to make a request even if the rate limit has been hit you can use
the `BypassRateLimitCheck` method to bypass the rate limit check and make the
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add github. for consistency:

Suggested change
the `BypassRateLimitCheck` method to bypass the rate limit check and make the
the `github.BypassRateLimitCheck` method to bypass the rate limit check and make the

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree.

["About secondary rate limits"](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits).
If the client is an [OAuth app](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api#primary-rate-limit-for-oauth-apps)
you can use the apps higher rate limit to request public data by using the
`UnauthenticatedRateLimitedTransport` to make calls as the app instead of as
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`UnauthenticatedRateLimitedTransport` to make calls as the app instead of as
`github.UnauthenticatedRateLimitedTransport` to make calls as the app instead of as

Comment on lines +174 to +175
// DisableRateLimitCheck stops the client checking for rate limits or tracking
// them. This is different to setting BypassRateLimitCheck in the context,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// DisableRateLimitCheck stops the client checking for rate limits or tracking
// them. This is different to setting BypassRateLimitCheck in the context,
// DisableRateLimitCheck stops the client checking for rate limits or tracking them.
// This is different to setting BypassRateLimitCheck in the context,

return &Response{
Response: err.Response,
}, err
if !c.DisableRateLimitCheck {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a unit test for this new field?

@alexandear
Copy link
Contributor

Please resolve the conflicts when you have a chance.

Also, feel free to ignore all of my comments except the one about adding a unit test - that one is a must-have.

@gmlewis gmlewis added waiting for reply and removed NeedsReview PR is awaiting a review before merging. labels Jun 30, 2025
@stevehipwell stevehipwell force-pushed the client-rate-limit-bypass branch from 4928013 to ad32dc4 Compare June 30, 2025 12:23
@stevehipwell
Copy link
Contributor Author

@alexandear I've added a unit test for the new disable feature and one for the existing bypass feature that didn't have one.

@gmlewis I rebased to fix the merge conflict, I hope that's OK (I've left the commit structure as it was).

@gmlewis
Copy link
Collaborator
gmlewis commented Jun 30, 2025

Thank you, @stevehipwell and @alexandear!
Merging.

@gmlewis gmlewis merged commit d96da2e into google:master Jun 30, 2025
7 checks passed
@stevehipwell stevehipwell deleted the client-rate-limit-bypass branch June 30, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for disabling the rate limit checks at the client level
3 participants
0