- implement RetryRoundTripper Refs: #64 Reviewed-on: #68 Reviewed-by: Marcel_Henselin <marcel.henselin@stackit.cloud> Co-authored-by: Andre Harms <andre.harms@stackit.cloud> Co-committed-by: Andre Harms <andre.harms@stackit.cloud>
This commit is contained in:
parent
20e9b3ca4c
commit
d5644ec27f
3 changed files with 512 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
|
|
@ -45,6 +46,17 @@ var (
|
|||
_ provider.Provider = &Provider{}
|
||||
)
|
||||
|
||||
const (
|
||||
// maxRetries is the maximum number of retries for a failed HTTP request.
|
||||
maxRetries = 3
|
||||
// initialDelay is the initial delay before the first retry attempt.
|
||||
initialDelay = 2 * time.Second
|
||||
// maxDelay is the maximum delay between retry attempts.
|
||||
maxDelay = 90 * time.Second
|
||||
// perTryTimeout is the timeout for each individual HTTP request attempt.
|
||||
perTryTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
// Provider is the provider implementation.
|
||||
type Provider struct {
|
||||
version string
|
||||
|
|
@ -466,7 +478,7 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
|
|||
providerData.Experiments = experimentValues
|
||||
}
|
||||
|
||||
roundTripper, err := sdkauth.SetupAuth(sdkConfig)
|
||||
baseRoundTripper, err := sdkauth.SetupAuth(sdkConfig)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
@ -477,6 +489,14 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
|
|||
return
|
||||
}
|
||||
|
||||
roundTripper := core.NewRetryRoundTripper(
|
||||
baseRoundTripper,
|
||||
maxRetries,
|
||||
initialDelay,
|
||||
maxDelay,
|
||||
perTryTimeout,
|
||||
)
|
||||
|
||||
// Make round tripper and custom endpoints available during DataSource and Resource
|
||||
// type Configure methods.
|
||||
providerData.RoundTripper = roundTripper
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue