Skip to content

Commit 23258f8

Browse files
authored
Merge pull request #1011 from hashicorp/f-aws-sdk-go-v1-compatible-retry.MaxBackoff
AWS SDK for Go v2 `MaxBackoff` delay to match AWS SDK for Go v1 default
2 parents 4a8595f + 761ed31 commit 23258f8

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<!-- markdownlint-disable single-title -->
22
# v2.0.0 (Unreleased)
33

4+
# v2.0.0-beta.52 (2024-04-11)
5+
6+
BUG FIXES
7+
8+
* Updates dependencies.
9+
10+
ENHANCEMENTS
11+
12+
* Adds `MaxBackoff` parameter to configure the maximum backoff delay that is allowed to occur between retrying a failed request ([#1011](https://github.com/hashicorp/aws-sdk-go-base/pull/1011))
13+
414
# v2.0.0-beta.51 (2024-04-04)
515

616
BUG FIXES

aws_config.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func GetAwsConfig(ctx context.Context, c *Config) (context.Context, aws.Config,
174174
}
175175
}
176176

177-
resolveRetryer(baseCtx, c.TokenBucketRateLimiterCapacity, &awsConfig)
177+
resolveRetryer(baseCtx, c, &awsConfig)
178178

179179
if !c.SkipCredsValidation {
180180
if _, _, err := getAccountIDAndPartitionFromSTSGetCallerIdentity(baseCtx, stsClient(baseCtx, awsConfig, c)); err != nil {
@@ -187,7 +187,7 @@ func GetAwsConfig(ctx context.Context, c *Config) (context.Context, aws.Config,
187187

188188
// Adapted from the per-service-client `resolveRetryer()` functions in the AWS SDK for Go v2
189189
// e.g. https://github.com/aws/aws-sdk-go-v2/blob/main/service/accessanalyzer/api_client.go
190-
func resolveRetryer(ctx context.Context, tokenBucketRateLimiterCapacity int, awsConfig *aws.Config) {
190+
func resolveRetryer(ctx context.Context, c *Config, awsConfig *aws.Config) {
191191
retryMode := awsConfig.RetryMode
192192
if len(retryMode) == 0 {
193193
defaultsMode := resolveDefaultsMode(ctx, awsConfig)
@@ -201,24 +201,31 @@ func resolveRetryer(ctx context.Context, tokenBucketRateLimiterCapacity int, aws
201201
}
202202

203203
var standardOptions []func(*retry.StandardOptions)
204+
204205
if v, found, _ := awsconfig.GetRetryMaxAttempts(ctx, awsConfig.ConfigSources); found && v != 0 {
205206
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
206207
so.MaxAttempts = v
207208
})
208209
}
209210

210-
newRetryer := func(retryMode aws.RetryMode, standardOptions []func(*retry.StandardOptions), tokenBucketRateLimiterCapacity int) aws.RetryerV2 {
211-
var retryer aws.RetryerV2
211+
if maxBackoff := c.MaxBackoff; maxBackoff > 0 {
212+
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
213+
so.MaxBackoff = maxBackoff
214+
})
215+
}
212216

213-
if tokenBucketRateLimiterCapacity > 0 {
214-
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
215-
so.RateLimiter = ratelimit.NewTokenRateLimit(uint(tokenBucketRateLimiterCapacity))
216-
})
217-
} else {
218-
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
219-
so.RateLimiter = ratelimit.None
220-
})
221-
}
217+
if tokenBucketRateLimiterCapacity := c.TokenBucketRateLimiterCapacity; tokenBucketRateLimiterCapacity > 0 {
218+
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
219+
so.RateLimiter = ratelimit.NewTokenRateLimit(uint(tokenBucketRateLimiterCapacity))
220+
})
221+
} else {
222+
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
223+
so.RateLimiter = ratelimit.None
224+
})
225+
}
226+
227+
newRetryer := func(retryMode aws.RetryMode, standardOptions []func(*retry.StandardOptions)) aws.RetryerV2 {
228+
var retryer aws.RetryerV2
222229

223230
switch retryMode {
224231
case aws.RetryModeAdaptive:
@@ -240,7 +247,7 @@ func resolveRetryer(ctx context.Context, tokenBucketRateLimiterCapacity int, aws
240247
awsConfig.Retryer = func() aws.Retryer {
241248
return &networkErrorShortcutter{
242249
// Ensure that each invocation of this function returns an independent Retryer.
243-
RetryerV2: newRetryer(retryMode, slices.Clone(standardOptions), tokenBucketRateLimiterCapacity),
250+
RetryerV2: newRetryer(retryMode, slices.Clone(standardOptions)),
244251
}
245252
}
246253
}

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Config struct {
4747
IamEndpoint string
4848
Insecure bool
4949
Logger logging.Logger
50+
MaxBackoff time.Duration
5051
MaxRetries int
5152
NoProxy string
5253
Profile string

v2/awsv1shim/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1
1111
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6
1212
github.com/google/go-cmp v0.6.0
13-
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.51
13+
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.52
1414
github.com/hashicorp/go-cleanhttp v0.5.2
1515
github.com/hashicorp/terraform-plugin-log v0.9.0
1616
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.50.0

0 commit comments

Comments
 (0)