-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Query requests idempotent #1022
Conversation
Address prometheus#1020. Signed-off-by: Tomáš Dohnálek <[email protected]>
Signed-off-by: Tomáš Dohnálek <[email protected]>
a1b532e
to
7016fd3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable. Let's document more, and I'm happy to accept it.
@@ -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["Idempotency-Key"] = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please at the docs directly here?
Transport only retries a request upon encountering a network error if the request is idempotent and either has no body or has its Request.GetBody defined. HTTP requests are considered idempotent if they have HTTP methods GET, HEAD, OPTIONS, or TRACE; or if their Header map contains an "Idempotency-Key" or "X-Idempotency-Key" entry. If the idempotency key value is a zero-length slice, the request is treated as idempotent but the header is not sent on the wire.
And a link to the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL.
I think we should squash before merging. Not sure if I am suppose to do that, or the Github's UI is used for it?
66ac0ad
to
ebe4b5b
Compare
Signed-off-by: Tomáš Dohnálek <[email protected]>
ebe4b5b
to
5588f73
Compare
@dohnto Amazing work. Thanks for taking care of it. |
Looking forward to having this change in a release. |
Address #1020.
Signed-off-by: Tomáš Dohnálek [email protected]
This was challenging to test. I used toxiproxy to inject connectivity issues. I build a custom Toxic which counts HTTP requests a closes every even request.
Without the header set, the conversation was following and my range query ended with
When I set the idempotency header, the conversation was equal to the case when GET is used - the connection is reopen and the request is retried.