Skip to content

Commit

Permalink
Allow to customize AWS SDK retry parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Mar 27, 2024
1 parent a7ae339 commit f51c3ab
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/cfg/conf_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ type S3Config struct {
RoleSessionName string
StsEndpoint string

SDKMaxRetries int
SDKMinRetryDelay time.Duration
SDKMaxRetryDelay time.Duration
SDKMinThrottleDelay time.Duration
SDKMaxThrottleDelay time.Duration

RequesterPays bool
Region string
RegionSet bool
Expand Down Expand Up @@ -120,6 +126,14 @@ func (c *S3Config) ToAwsConfig(flags *FlagStorage) (*aws.Config, error) {

awsConfig.S3ForcePathStyle = aws.Bool(!c.Subdomain)

awsConfig.Retryer = client.DefaultRetryer{
NumMaxRetries: c.SDKMaxRetries,
MinRetryDelay: c.SDKMinRetryDelay,
MaxRetryDelay: c.SDKMaxRetryDelay,
MinThrottleDelay: c.SDKMinThrottleDelay,
MaxThrottleDelay: c.SDKMaxThrottleDelay,
}

if c.Session == nil {
if s3Session == nil {
var err error
Expand Down
36 changes: 36 additions & 0 deletions internal/cfg/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,36 @@ MISC OPTIONS:
Name: "subdomain",
Usage: "Enable subdomain mode of S3",
},

cli.IntFlag{
Name: "sdk-max-retries",
Value: 3,
Usage: "Maximum number of AWS SDK request retries.",
},

cli.DurationFlag{
Name: "sdk-min-retry-delay",
Value: 30 * time.Millisecond,
Usage: "Minimum delay for AWS SDK retries of temporary request failures.",
},

cli.DurationFlag{
Name: "sdk-max-retry-delay",
Value: 300 * time.Second,
Usage: "Maximum delay for AWS SDK retries of temporary request failures.",
},

cli.DurationFlag{
Name: "sdk-min-throttle-delay",
Value: 500 * time.Millisecond,
Usage: "Minimum delay for AWS SDK retries of throttled requests (429, 502, 503, 504).",
},

cli.DurationFlag{
Name: "sdk-max-throttle-delay",
Value: 300 * time.Second,
Usage: "Maximum delay for AWS SDK retries of throttled requests.",
},
}

tuningFlags := []cli.Flag{
Expand Down Expand Up @@ -909,6 +939,12 @@ func PopulateFlags(c *cli.Context) (ret *FlagStorage) {

config.MultipartCopyThreshold = uint64(c.Int("multipart-copy-threshold")) * 1024 * 1024

config.SDKMaxRetries = c.Int("sdk-max-retries")
config.SDKMinRetryDelay = c.Duration("sdk-min-retry-delay")
config.SDKMaxRetryDelay = c.Duration("sdk-max-retry-delay")
config.SDKMinThrottleDelay = c.Duration("sdk-min-throttle-delay")
config.SDKMaxThrottleDelay = c.Duration("sdk-max-throttle-delay")

// KMS implies SSE
if config.UseKMS {
config.UseSSE = true
Expand Down

0 comments on commit f51c3ab

Please sign in to comment.