From 9b85354acd12834d24cf711c188d4c2246615d97 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 11 Aug 2023 16:37:53 +0000 Subject: [PATCH] remote-write: respect Retry-After header on 5xx errors If the server sent it to us, we should assume it knows better than we do and respect it. Signed-off-by: Bryan Boreham --- storage/remote/client.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/remote/client.go b/storage/remote/client.go index d493e414f4..fbb6804983 100644 --- a/storage/remote/client.go +++ b/storage/remote/client.go @@ -236,10 +236,8 @@ func (c *Client) Store(ctx context.Context, req []byte, attempt int) error { } err = fmt.Errorf("server returned HTTP status %s: %s", httpResp.Status, line) } - if httpResp.StatusCode/100 == 5 { - return RecoverableError{err, defaultBackoff} - } - if c.retryOnRateLimit && httpResp.StatusCode == http.StatusTooManyRequests { + if httpResp.StatusCode/100 == 5 || + (c.retryOnRateLimit && httpResp.StatusCode == http.StatusTooManyRequests) { return RecoverableError{err, retryAfterDuration(httpResp.Header.Get("Retry-After"))} } return err