Skip to content

Commit

Permalink
feat: update default retry
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF committed Jan 31, 2025
1 parent c3c0145 commit 510ff7c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
9 changes: 9 additions & 0 deletions docs/guides/retry-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ The schema of these retry attributes is as follows:
- `response_is_nil` - If the response is nil, should the request be retried. The default value is `true`.
- `status_forbidden` - If the status code is 403, should the request be retried. The default value is `false`.
- `status_not_found` - If the status code is 404, should the request be retried. The default value is `false`.

## Default resource-specific retry configuration

If you do not configure any retry values, the provider will use the following:

For the initial create/read/update/delete operation we will retry on HTTP 429 status codes for a maximum time of 2 minutes.

For the read-after-create operation we will retry on HTTP 404, 403 status codes as well as a nill response.
We will do this up to the operation timeout configured in the `timeouts {}` block.
16 changes: 8 additions & 8 deletions internal/clients/data_plane_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func isDataPlaneRetryable(ctx context.Context, retryclient DataPlaneClientRetrya

// ConfigureClientWithCustomRetry configures the client with a custom retry configuration if supplied.
// If the retry configuration is null or unknown, it will use the default retry configuration.
// If the supplied context has a deadline, it will use the deadline as the max elapsed time.
// If the supplied context has a deadline, it will use the deadline as the max elapsed time when a custom retry is provided.
func (client *DataPlaneClient) ConfigureClientWithCustomRetry(ctx context.Context, retry retry.RetryValue) DataPlaneRequester {
// configure default retry configuration
maxElapsed := 2 * time.Minute
Expand All @@ -529,11 +529,7 @@ func (client *DataPlaneClient) ConfigureClientWithCustomRetry(ctx context.Contex
)
errRegExps := []regexp.Regexp{}
statusCodes := retry.GetDefaultRetryableStatusCodes()
dataCallbackFuncs := []func(d interface{}) bool{
func(d interface{}) bool {
return d == nil
},
}
dataCallbackFuncs := []func(d interface{}) bool{}

if !retry.IsNull() && !retry.IsUnknown() {
tflog.Debug(ctx, "using custom retry configuration")
Expand All @@ -548,8 +544,12 @@ func (client *DataPlaneClient) ConfigureClientWithCustomRetry(ctx context.Contex
if retry.StatusNotFound.ValueBool() {
statusCodes = append(statusCodes, http.StatusNotFound)
}
if !retry.ResponseIsNil.ValueBool() {
dataCallbackFuncs = nil
if retry.ResponseIsNil.ValueBool() {
dataCallbackFuncs = []func(d interface{}) bool{
func(d interface{}) bool {
return d == nil
},
}
}
backOff = backoff.NewExponentialBackOff(
backoff.WithInitialInterval(retry.GetIntervalSecondsAsDuration()),
Expand Down
16 changes: 8 additions & 8 deletions internal/clients/resource_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func isRetryable(ctx context.Context, retryclient ResourceClientRetryableErrors,

// ConfigureClientWithCustomRetry configures the client with a custom retry configuration if supplied.
// If the retry configuration is null or unknown, it will use the default retry configuration.
// If the supplied context has a deadline, it will use the deadline as the max elapsed time.
// If the supplied context has a deadline, it will use the deadline as the max elapsed time when a custom retry is provided.
func (client *ResourceClient) ConfigureClientWithCustomRetry(ctx context.Context, retry retry.RetryValue) Requester {
// configure default retry configuration
maxElapsed := 2 * time.Minute
Expand All @@ -707,11 +707,7 @@ func (client *ResourceClient) ConfigureClientWithCustomRetry(ctx context.Context
)
errRegExps := []regexp.Regexp{}
statusCodes := retry.GetDefaultRetryableStatusCodes()
dataCallbackFuncs := []func(d interface{}) bool{
func(d interface{}) bool {
return d == nil
},
}
dataCallbackFuncs := []func(d interface{}) bool{}

if !retry.IsNull() && !retry.IsUnknown() {
tflog.Debug(ctx, "using custom retry configuration")
Expand All @@ -726,8 +722,12 @@ func (client *ResourceClient) ConfigureClientWithCustomRetry(ctx context.Context
if retry.StatusNotFound.ValueBool() {
statusCodes = append(statusCodes, http.StatusNotFound)
}
if !retry.ResponseIsNil.ValueBool() {
dataCallbackFuncs = nil
if retry.ResponseIsNil.ValueBool() {
dataCallbackFuncs = []func(d interface{}) bool{
func(d interface{}) bool {
return d == nil
},
}
}
backOff = backoff.NewExponentialBackOff(
backoff.WithInitialInterval(retry.GetIntervalSecondsAsDuration()),
Expand Down
2 changes: 1 addition & 1 deletion internal/retry/retryable_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
_ basetypes.ObjectTypable = RetryType{}
_ basetypes.ObjectValuable = RetryValue{}

defaultRetryableStatusCodes = []int{}
defaultRetryableStatusCodes = []int{429}
)

const (
Expand Down
9 changes: 9 additions & 0 deletions templates/guides/retry-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ The schema of these retry attributes is as follows:
- `response_is_nil` - If the response is nil, should the request be retried. The default value is `true`.
- `status_forbidden` - If the status code is 403, should the request be retried. The default value is `false`.
- `status_not_found` - If the status code is 404, should the request be retried. The default value is `false`.

## Default resource-specific retry configuration

If you do not configure any retry values, the provider will use the following:

For the initial create/read/update/delete operation we will retry on HTTP 429 status codes for a maximum time of 2 minutes.

For the read-after-create operation we will retry on HTTP 404, 403 status codes as well as a nill response.
We will do this up to the operation timeout configured in the `timeouts {}` block.

0 comments on commit 510ff7c

Please sign in to comment.