-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix wrong context is used to decide pushing metrics or not. #1261
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1261 +/- ##
==========================================
+ Coverage 75.42% 75.42% +<.01%
==========================================
Files 150 150
Lines 10883 10884 +1
==========================================
+ Hits 8208 8209 +1
Misses 2209 2209
Partials 466 466
Continue to review full report at Codecov.
|
8804297
to
db4b2f9
Compare
db4b2f9
to
4169f7a
Compare
4169f7a
to
4722cb3
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.
LGTM, but let's not merge this just yet
Made it as v0.27.0 |
Test for error message contains string instead of euqal.
Go 1.13 and below has a bug that client timeout will not be propagated to http request context. That bug was fixed already and will be present in go1.14 (golang/go#31657). Currently, we set Timeout in our Client, but do not use it else where. It will not affect the request context for now, but does when go1.14 release. To make it compatible and works correctly with other go versions, we set the request context explicitly with the timeout. Update #1260
4722cb3
to
d9c2ec1
Compare
The purpose of PushIfNotCancelled is pushing the sample if the passing context is done. But its name will make confusion, because a timeout context also causes the context cancelled. So changing the name to PushIfNotDone to make it clearer. While at it, also change the select/ctx.Done pattern to ctx.Err variant. It saves us some lines of code and maybe slightly better performance.
PushIfNotDone is intended to use with VU context instead of request context. This is a bug in current code base, but it is not triggered due to the bug in Go net/http. A request context can be in cancelled state due to be cancelled or timeouted. PushIfNotDone won't see the difference and will skip pushing metrics for timeouted requests. Fixing it by passing VU context to PushIfNotDone instead of request ctx. Fixes #1260
d9c2ec1
to
64f0614
Compare
Go 1.13 and below has a bug that client timeout will not be propagated
to http request context. That bug was fixed already and will be present
in go1.14 (golang/go#31657).
With current go master, our TestSetupTeardownThresholds fails. The
reason is that we only push sample if the request context not done. When
the bug in Go stdlib was not fixed, our own http Client.Timeout is not
passed to request context, so when client makes request, it does not
aware about the request context, and always push the sample.
Now when Client.Timeout is passed to request context, as long as the
client finish the request, the request context is consider done, and we
do not push the sample anymore.
Further more, we are using the wrong context for PushIfNotCancelled.
It's intended to use with VU context instead of the request context.
In summary, to fix it:
Fixed #1260