Skip to content
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

Merged
merged 6 commits into from
Dec 17, 2019

Conversation

cuonglm
Copy link
Contributor

@cuonglm cuonglm commented Dec 4, 2019

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:

  • We explicitly pass the timeout to request context, instead of setting in Client.Timeout.
  • Use VU context instead of request context for whether pushing metrics or not.

Fixed #1260

@cuonglm cuonglm requested review from mstoykov, imiric and na-- December 4, 2019 08:57
@codecov-io
Copy link

codecov-io commented Dec 4, 2019

Codecov Report

Merging #1261 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
stats/thresholds.go 93.25% <ø> (ø) ⬆️
js/modules/k6/k6.go 91.48% <100%> (ø) ⬆️
js/modules/k6/ws/ws.go 83.53% <100%> (ø) ⬆️
lib/netext/httpext/request.go 97.35% <100%> (+0.01%) ⬆️
stats/stats.go 80.55% <100%> (-0.18%) ⬇️
lib/netext/httpext/transport.go 96.25% <100%> (+0.04%) ⬆️
js/modules/k6/metrics/metrics.go 94.73% <100%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de39513...64f0614. Read the comment docs.

@cuonglm cuonglm force-pushed the fix/http-request-timeout branch from 8804297 to db4b2f9 Compare December 5, 2019 13:08
@cuonglm cuonglm changed the title Fix Client.Timeout is not propagated to http request context WIP: Fix Client.Timeout is not propagated to http request context Dec 5, 2019
@cuonglm cuonglm force-pushed the fix/http-request-timeout branch from db4b2f9 to 4169f7a Compare December 6, 2019 08:35
@cuonglm cuonglm changed the title WIP: Fix Client.Timeout is not propagated to http request context Fix wrong context is used to decide pushing metrics or not. Dec 6, 2019
@cuonglm cuonglm force-pushed the fix/http-request-timeout branch from 4169f7a to 4722cb3 Compare December 6, 2019 09:14
na--
na-- previously approved these changes Dec 6, 2019
Copy link
Member

@na-- na-- left a 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

@cuonglm cuonglm added this to the v0.27.0 milestone Dec 6, 2019
@cuonglm
Copy link
Contributor Author

cuonglm commented Dec 6, 2019

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
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
@cuonglm cuonglm force-pushed the fix/http-request-timeout branch from d9c2ec1 to 64f0614 Compare December 17, 2019 00:45
@cuonglm cuonglm merged commit a0d9f54 into master Dec 17, 2019
@cuonglm cuonglm deleted the fix/http-request-timeout branch December 17, 2019 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request context is passed to PushIfNotCancelled instead of VU context
4 participants