Skip to content

Commit cc7991d

Browse files
authored
Make Query requests idempotent (#1022)
* Make Query requests idempotent Address #1020. Signed-off-by: Tomáš Dohnálek <[email protected]> * Use empty header Signed-off-by: Tomáš Dohnálek <[email protected]> * Document issue with original documentation Signed-off-by: Tomáš Dohnálek <[email protected]>
1 parent 0bab4fd commit cc7991d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

api/prometheus/v1/api.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,14 @@ func (h *apiClientImpl) DoGetFallback(ctx context.Context, u *url.URL, args url.
11391139
return nil, nil, nil, err
11401140
}
11411141
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
1142+
// Following comment originates from https://pkg.go.dev/net/http#Transport
1143+
// Transport only retries a request upon encountering a network error if the request is
1144+
// idempotent and either has no body or has its Request.GetBody defined. HTTP requests
1145+
// are considered idempotent if they have HTTP methods GET, HEAD, OPTIONS, or TRACE; or
1146+
// if their Header map contains an "Idempotency-Key" or "X-Idempotency-Key" entry. If the
1147+
// idempotency key value is a zero-length slice, the request is treated as idempotent but
1148+
// the header is not sent on the wire.
1149+
req.Header["Idempotency-Key"] = nil
11421150

11431151
resp, body, warnings, err := h.Do(ctx, req)
11441152
if resp != nil && (resp.StatusCode == http.StatusMethodNotAllowed || resp.StatusCode == http.StatusNotImplemented) {

0 commit comments

Comments
 (0)