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

AWS SDK for Go v2 MaxBackoff delay to match AWS SDK for Go v1 default #1011

Merged
merged 6 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<!-- markdownlint-disable single-title -->
# v2.0.0 (Unreleased)

BUG FIXES

* Updates dependencies.

ENHANCEMENTS

* Adds `MaxBackoff` parameter to configure the maximum backoff delay that is allowed to occur between retrying a failed request

# v2.0.0-beta.51 (2024-04-04)

BUG FIXES
Expand Down
35 changes: 21 additions & 14 deletions aws_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func GetAwsConfig(ctx context.Context, c *Config) (context.Context, aws.Config,
}
}

resolveRetryer(baseCtx, c.TokenBucketRateLimiterCapacity, &awsConfig)
resolveRetryer(baseCtx, c, &awsConfig)

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

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

var standardOptions []func(*retry.StandardOptions)

if v, found, _ := awsconfig.GetRetryMaxAttempts(ctx, awsConfig.ConfigSources); found && v != 0 {
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
so.MaxAttempts = v
})
}

newRetryer := func(retryMode aws.RetryMode, standardOptions []func(*retry.StandardOptions), tokenBucketRateLimiterCapacity int) aws.RetryerV2 {
var retryer aws.RetryerV2
if maxBackoff := c.MaxBackoff; maxBackoff > 0 {
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
so.MaxBackoff = maxBackoff
})
}

if tokenBucketRateLimiterCapacity > 0 {
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
so.RateLimiter = ratelimit.NewTokenRateLimit(uint(tokenBucketRateLimiterCapacity))
})
} else {
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
so.RateLimiter = ratelimit.None
})
}
if tokenBucketRateLimiterCapacity := c.TokenBucketRateLimiterCapacity; tokenBucketRateLimiterCapacity > 0 {
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
so.RateLimiter = ratelimit.NewTokenRateLimit(uint(tokenBucketRateLimiterCapacity))
})
} else {
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
so.RateLimiter = ratelimit.None
})
}

newRetryer := func(retryMode aws.RetryMode, standardOptions []func(*retry.StandardOptions)) aws.RetryerV2 {
var retryer aws.RetryerV2

switch retryMode {
case aws.RetryModeAdaptive:
Expand All @@ -240,7 +247,7 @@ func resolveRetryer(ctx context.Context, tokenBucketRateLimiterCapacity int, aws
awsConfig.Retryer = func() aws.Retryer {
return &networkErrorShortcutter{
// Ensure that each invocation of this function returns an independent Retryer.
RetryerV2: newRetryer(retryMode, slices.Clone(standardOptions), tokenBucketRateLimiterCapacity),
RetryerV2: newRetryer(retryMode, slices.Clone(standardOptions)),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Config struct {
IamEndpoint string
Insecure bool
Logger logging.Logger
MaxBackoff time.Duration
MaxRetries int
NoProxy string
Profile string
Expand Down