-
Notifications
You must be signed in to change notification settings - Fork 787
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retry manager to reduce RateLimitExceeded errors
- Loading branch information
1 parent
1b242f8
commit 0ec72fc
Showing
3 changed files
with
105 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cloud | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws/retry" | ||
"time" | ||
) | ||
|
||
const ( | ||
// retryMaxAttempt sets max number of EC2 API call attempts. | ||
// Set high enough to ensure default sidecar timeout will cancel context long before we stop retrying. | ||
retryMaxAttempt = 50 | ||
// retryMaxBackoffAdaptive sets max backoff delay between retry attempts. | ||
// Set more aggressive than default of 20 seconds due to adaptive client-side throttling being enabled. | ||
retryMaxBackoffAdaptive = 15 * time.Second | ||
) | ||
|
||
// newAdaptiveRetryer restricts attempts of API calls that recently hit throttle errors. | ||
func newAdaptiveRetryer() *retry.AdaptiveMode { | ||
return retry.NewAdaptiveMode(func(ao *retry.AdaptiveModeOptions) { | ||
ao.StandardOptions = append(ao.StandardOptions, func(so *retry.StandardOptions) { | ||
so.MaxAttempts = retryMaxAttempt | ||
so.MaxBackoff = retryMaxBackoffAdaptive | ||
}) | ||
}) | ||
} | ||
|
||
type retryManager struct { | ||
createVolumeRetryer *retry.AdaptiveMode | ||
deleteVolumeRetryer *retry.AdaptiveMode | ||
attachVolumeRetryer *retry.AdaptiveMode | ||
detachVolumeRetryer *retry.AdaptiveMode | ||
modifyVolumeRetryer *retry.AdaptiveMode | ||
createSnapshotRetryer *retry.AdaptiveMode | ||
deleteSnapshotRetryer *retry.AdaptiveMode | ||
enableFastSnapshotRestoresRetryer *retry.AdaptiveMode | ||
|
||
// Restrict unbatchable describe calls when rate-limited so that batched calls are more likely to succeed. | ||
unbatchableDescribeVolumesModificationsRetryer *retry.AdaptiveMode | ||
} | ||
|
||
// newRetryManager initializes a new instance of retryManager that will dictate the retry strategies of EC2 API calls. | ||
func newRetryManager() *retryManager { | ||
return &retryManager{ | ||
createVolumeRetryer: newAdaptiveRetryer(), | ||
attachVolumeRetryer: newAdaptiveRetryer(), | ||
deleteVolumeRetryer: newAdaptiveRetryer(), | ||
detachVolumeRetryer: newAdaptiveRetryer(), | ||
modifyVolumeRetryer: newAdaptiveRetryer(), | ||
createSnapshotRetryer: newAdaptiveRetryer(), | ||
deleteSnapshotRetryer: newAdaptiveRetryer(), | ||
enableFastSnapshotRestoresRetryer: newAdaptiveRetryer(), | ||
unbatchableDescribeVolumesModificationsRetryer: newAdaptiveRetryer(), | ||
} | ||
} |