From fe750dacc4ab3dac7e618baec0fc4b9ab30c5a76 Mon Sep 17 00:00:00 2001 From: Sebastian Rivera Date: Tue, 21 Jun 2022 17:24:50 -0400 Subject: [PATCH 1/2] Expose RetryServerErrors as a part of the config object. The client exposes a receiver method called RetryServerErrors which toggles a flag, c.retryServerErrors, that enables/disables the retry logic in the http client. This means however, you could only enable the retry logic once the client was created, meaning any failed metadata request in `NewClient()` would not be retried. We've extended the interface of the client config object to allow enabling `c.retryServerErrors` during client init `NewClient()`. --- tfe.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tfe.go b/tfe.go index 5de213310..9f8a5c293 100644 --- a/tfe.go +++ b/tfe.go @@ -66,17 +66,21 @@ type Config struct { // RetryLogHook is invoked each time a request is retried. RetryLogHook RetryLogHook + + // RetryServerErrors enables the retry logic in the client. + RetryServerErrors bool } // DefaultConfig returns a default config structure. func DefaultConfig() *Config { config := &Config{ - Address: os.Getenv("TFE_ADDRESS"), - BasePath: DefaultBasePath, - Token: os.Getenv("TFE_TOKEN"), - Headers: make(http.Header), - HTTPClient: cleanhttp.DefaultPooledClient(), + Address: os.Getenv("TFE_ADDRESS"), + BasePath: DefaultBasePath, + Token: os.Getenv("TFE_TOKEN"), + Headers: make(http.Header), + HTTPClient: cleanhttp.DefaultPooledClient(), + RetryServerErrors: false, } // Set the default address if none is given. @@ -196,6 +200,7 @@ func NewClient(cfg *Config) (*Client, error) { if cfg.RetryLogHook != nil { config.RetryLogHook = cfg.RetryLogHook } + config.RetryServerErrors = cfg.RetryServerErrors } // Parse the address to make sure its a valid URL. @@ -216,10 +221,11 @@ func NewClient(cfg *Config) (*Client, error) { // Create the client. client := &Client{ - baseURL: baseURL, - token: config.Token, - headers: config.Headers, - retryLogHook: config.RetryLogHook, + baseURL: baseURL, + token: config.Token, + headers: config.Headers, + retryLogHook: config.RetryLogHook, + retryServerErrors: config.RetryServerErrors, } client.http = &retryablehttp.Client{ From 8bf7b8e2bf7c807a95a1ff05e36b852fe9e97b1e Mon Sep 17 00:00:00 2001 From: Sebastian Rivera Date: Thu, 23 Jun 2022 13:53:07 -0400 Subject: [PATCH 2/2] Update Changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a66ed07f1..e027d33a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v1.4.0 (Unreleased) + +## Enhancements +* Adds `RetryServerErrors` field to the `Config` object by @sebasslash [#439](https://github.com/hashicorp/go-tfe/pull/439) + # v1.3.0 ## Enhancements