Skip to content

Commit

Permalink
Merge pull request #113 from DopplerHQ/tom_log_retries
Browse files Browse the repository at this point in the history
Log failed http request retry attempts
  • Loading branch information
Piccirello authored Jul 29, 2020
2 parents 8891424 + 35bcb9f commit 9f1b477
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func performRequest(req *http.Request, verifyTLS bool, params []queryParam) (int
}
}

startTime := time.Now()
var response *http.Response
response = nil

Expand Down Expand Up @@ -159,6 +160,11 @@ func performRequest(req *http.Request, verifyTLS bool, params []queryParam) (int
}

if isRetry(resp.StatusCode) {
// start logging retries after 10 seconds so it doesn't feel like we've frozen
// we subtract 1 millisecond so that we always win the race against a request that exhausts its full 10 second time out
if time.Now().After(startTime.Add(10 * time.Second).Add(-1 * time.Millisecond)) {
utils.Log(fmt.Sprintf("Request failed with HTTP %d, retrying", resp.StatusCode))
}
return errors.New("Request failed")
}

Expand Down

0 comments on commit 9f1b477

Please sign in to comment.