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

add ratelimit.None helper for disabling retry quotas #2562

Merged
merged 1 commit into from Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelog/df6f67adcf634eb48c3c35f3cc763f09.json
@@ -0,0 +1,8 @@
{
"id": "df6f67ad-cf63-4eb4-8c3c-35f3cc763f09",
"type": "feature",
"description": "Add no-op rate limiting implementation `ratelimit.None`, which allows disabling of client-side retry quota behavior.",
"modules": [
"."
]
}
20 changes: 20 additions & 0 deletions aws/ratelimit/none.go
@@ -0,0 +1,20 @@
package ratelimit

import "context"

// None implements a no-op rate limiter which effectively disables client-side
// rate limiting (also known as "retry quotas").
//
// GetToken does nothing and always returns a nil error. The returned
// token-release function does nothing, and always returns a nil error.
//
// AddTokens does nothing and always returns a nil error.
var None = &none{}

type none struct{}

func (*none) GetToken(ctx context.Context, cost uint) (func() error, error) {
return func() error { return nil }, nil
}

func (*none) AddTokens(v uint) error { return nil }
11 changes: 11 additions & 0 deletions aws/retry/standard.go
Expand Up @@ -123,6 +123,17 @@ type StandardOptions struct {

// Provides the rate limiting strategy for rate limiting attempt retries
// across all attempts the retryer is being used with.
//
// A RateLimiter operates as a token bucket with a set capacity, where
// attempt failures events consume tokens. A retry attempt that attempts to
// consume more tokens than what's available results in operation failure.
// The default implementation is parameterized as follows:
// - a capacity of 500 (DefaultRetryRateTokens)
// - a retry caused by a timeout costs 10 tokens (DefaultRetryCost)
// - a retry caused by other errors costs 5 tokens (DefaultRetryTimeoutCost)
// - an operation that succeeds on the 1st attempt adds 1 token (DefaultNoRetryIncrement)
//
// You can disable rate limiting by setting this field to ratelimit.None.
RateLimiter RateLimiter

// The cost to deduct from the RateLimiter's token bucket per retry.
Expand Down