Return error rather than default a retry value (#6376)

This commit is contained in:
Greg 2019-09-10 12:46:47 -06:00 committed by Daniel Nelson
parent d7c85768a4
commit 88b60a2e9b
1 changed files with 14 additions and 3 deletions

View File

@ -240,17 +240,28 @@ func (c *httpClient) writeBatch(ctx context.Context, bucket string, metrics []te
return nil
case http.StatusUnauthorized, http.StatusForbidden:
return fmt.Errorf("failed to write metric: %s", desc)
case http.StatusTooManyRequests, http.StatusServiceUnavailable:
case http.StatusTooManyRequests:
retryAfter := resp.Header.Get("Retry-After")
retry, err := strconv.Atoi(retryAfter)
if err != nil {
retry = 0
return errors.New("rate limit exceeded")
}
if retry > defaultMaxWait {
retry = defaultMaxWait
}
c.retryTime = time.Now().Add(time.Duration(retry) * time.Second)
return fmt.Errorf("Waiting %ds for server before sending metric again", retry)
return fmt.Errorf("waiting %ds for server before sending metric again", retry)
case http.StatusServiceUnavailable:
retryAfter := resp.Header.Get("Retry-After")
retry, err := strconv.Atoi(retryAfter)
if err != nil {
return errors.New("server responded: service unavailable")
}
if retry > defaultMaxWait {
retry = defaultMaxWait
}
c.retryTime = time.Now().Add(time.Duration(retry) * time.Second)
return fmt.Errorf("waiting %ds for server before sending metric again", retry)
}
// This is only until platform spec is fully implemented. As of the