Skip to content

Commit

Permalink
Merge pull request #328 from DopplerHQ/watsonian/requestattempts
Browse files Browse the repository at this point in the history
ENG-4848: Make HTTP request attempts configurable
  • Loading branch information
watsonian authored Aug 29, 2022
2 parents ca5ba4a + a2261cb commit ba8262c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func init() {
rootCmd.PersistentFlags().Bool("no-verify-tls", false, "do not verify the validity of TLS certificates on HTTP requests (not recommended)")
rootCmd.PersistentFlags().Bool("no-timeout", !http.UseTimeout, "disable http timeout")
rootCmd.PersistentFlags().DurationVar(&http.TimeoutDuration, "timeout", http.TimeoutDuration, "max http request duration")
rootCmd.PersistentFlags().IntVar(&http.RequestAttempts, "attempts", http.RequestAttempts, "number of http request attempts made before failing")
// DNS resolver
rootCmd.PersistentFlags().Bool("no-dns-resolver", !http.UseCustomDNSResolver, "use the OS's default DNS resolver")
if err := rootCmd.PersistentFlags().MarkDeprecated("no-dns-resolver", "the DNS resolver is disabled by default"); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ var UseTimeout = true

// TimeoutDuration how long to wait for a request to complete before timing out
var TimeoutDuration = 10 * time.Second

// RequestAttempts how many request attempts are made before giving up
var RequestAttempts = 5
2 changes: 1 addition & 1 deletion pkg/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func performRequest(req *http.Request, verifyTLS bool, params []queryParam) (int
var response *http.Response
response = nil

requestErr := retry(5, 100*time.Millisecond, func() error {
requestErr := retry(RequestAttempts, 100*time.Millisecond, func() error {
resp, err := client.Do(req)
if err != nil {
if resp != nil {
Expand Down

0 comments on commit ba8262c

Please sign in to comment.