feat: add modern rate limiter option using go-github-ratelimit#3236
Open
mkushakov wants to merge 2 commits intointegrations:mainfrom
Open
feat: add modern rate limiter option using go-github-ratelimit#3236mkushakov wants to merge 2 commits intointegrations:mainfrom
mkushakov wants to merge 2 commits intointegrations:mainfrom
Conversation
Add rate_limiter provider option (legacy/modern). Modern uses go-github-ratelimit/v2 for automatic rate limit handling. Resolves integrations#2709, references integrations#849 integrations#1226.
|
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
deiga
suggested changes
Feb 27, 2026
Collaborator
deiga
left a comment
There was a problem hiding this comment.
This is great! Left a few comments :)
Comment on lines
+101
to
+107
| ValidateFunc: func(val any, key string) (warns []string, errs []error) { | ||
| v := val.(string) | ||
| if v != "legacy" && v != "modern" { | ||
| errs = append(errs, fmt.Errorf("%q must be either 'legacy' or 'modern', got: %s", key, v)) | ||
| } | ||
| return | ||
| }, |
Collaborator
There was a problem hiding this comment.
Suggested change
| ValidateFunc: func(val any, key string) (warns []string, errs []error) { | |
| v := val.(string) | |
| if v != "legacy" && v != "modern" { | |
| errs = append(errs, fmt.Errorf("%q must be either 'legacy' or 'modern', got: %s", key, v)) | |
| } | |
| return | |
| }, | |
| ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"legacy", "modern"})), |
| // read_delay_ms, write_delay_ms, and parallel_requests settings are ignored | ||
| // because rate limiting is handled automatically by the library. | ||
| func ModernRateLimitedHTTPClient(client *http.Client, retryDelay time.Duration, retryableErrors map[int]bool, maxRetries int) *http.Client { | ||
| client.Transport = NewEtagTransport(client.Transport) |
Collaborator
There was a problem hiding this comment.
Suggested change
| client.Transport = NewEtagTransport(client.Transport) | |
| client.Transport = NewEtagTransport(client.Transport) | |
| client.Transport = logging.NewLoggingHTTPTransport(client.Transport) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a new
rate_limiterprovider configuration option that allows users to choose between two rate limiting strategies for GitHub API calls.Resolves #2709
References #849, #1226
Motivation
The current provider uses a custom rate limiting implementation with configurable
read_delay_msandwrite_delay_msdelays. While functional, this approach:Retry-After,X-RateLimit-*)The
go-github-ratelimitlibrary provides automatic, header-based rate limit handling that respects GitHub's primary and secondary rate limits without manual configuration.Changes
Config (
config.go)RateLimiterfield toConfigstruct (accepts"legacy"or"modern")ModernRateLimitedHTTPClientfunction that usesgo-github-ratelimit/v2to create an HTTP client with automatic rate limit handlingAuthenticatedHTTPClientandAnonymousHTTPClientto dispatch to the appropriate rate limiter based on theRateLimitersettingProvider (
provider.go)rate_limiterschema field with validation ("legacy"or"modern", defaults to"legacy")rate_limitervalue into theConfigstruct inproviderConfigureDependencies
github.com/gofri/go-github-ratelimit/v2 v2.0.2Example Usage
When using
"modern", theread_delay_ms,write_delay_ms, andparallel_requestssettings are ignored — the library automatically detects and waits for rate limit resets using response headers.Testing
go build ./...— passesgo vet ./...— passes"legacy"to maintain backward compatibility — no existing configurations are affected