Skip to content

Commit e5b7766

Browse files
authored
add ratelimit.None (#2562)
1 parent 10c4487 commit e5b7766

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "df6f67ad-cf63-4eb4-8c3c-35f3cc763f09",
3+
"type": "feature",
4+
"description": "Add no-op rate limiting implementation `ratelimit.None`, which allows disabling of client-side retry quota behavior.",
5+
"modules": [
6+
"."
7+
]
8+
}

aws/ratelimit/none.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ratelimit
2+
3+
import "context"
4+
5+
// None implements a no-op rate limiter which effectively disables client-side
6+
// rate limiting (also known as "retry quotas").
7+
//
8+
// GetToken does nothing and always returns a nil error. The returned
9+
// token-release function does nothing, and always returns a nil error.
10+
//
11+
// AddTokens does nothing and always returns a nil error.
12+
var None = &none{}
13+
14+
type none struct{}
15+
16+
func (*none) GetToken(ctx context.Context, cost uint) (func() error, error) {
17+
return func() error { return nil }, nil
18+
}
19+
20+
func (*none) AddTokens(v uint) error { return nil }

aws/retry/standard.go

+11
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ type StandardOptions struct {
123123

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

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

0 commit comments

Comments
 (0)