Skip to content

Commit

Permalink
Return error rather than default a retry value (influxdata#6376)
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton authored and bitcharmer committed Oct 18, 2019
1 parent 9bf97fa commit 422e2d2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions plugins/outputs/influxdb_v2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 422e2d2

Please sign in to comment.