Skip to content

Commit

Permalink
add ratelimit.None (#2562)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws authored Mar 18, 2024
1 parent 10c4487 commit e5b7766
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changelog/df6f67adcf634eb48c3c35f3cc763f09.json
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit e5b7766

Please sign in to comment.