From 24c08642cd85b84b6c689f569c7a0b110eaef534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Dohn=C3=A1lek?= Date: Thu, 7 Apr 2022 13:46:32 +0200 Subject: [PATCH] Make Query requests idempotent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address #1020. Signed-off-by: Tomáš Dohnálek --- api/prometheus/v1/api.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/prometheus/v1/api.go b/api/prometheus/v1/api.go index 857512fb8..b68b69c25 100644 --- a/api/prometheus/v1/api.go +++ b/api/prometheus/v1/api.go @@ -1138,6 +1138,9 @@ func (h *apiClientImpl) DoGetFallback(ctx context.Context, u *url.URL, args url. return nil, nil, nil, err } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + // Underlying `net.http` library automatically retries` idempotent requests when connectivity issues are hit. + // POST requests are not considered idempotent by default, so we need to explicitly mark them as such. + req.Header.Set("Idempotency-Key", "TODO") resp, body, warnings, err := h.Do(ctx, req) if resp != nil && (resp.StatusCode == http.StatusMethodNotAllowed || resp.StatusCode == http.StatusNotImplemented) {