-
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
Experimental tracing module (3/3): define and expose a instrumentHTTP
function
#2855
Experimental tracing module (3/3): define and expose a instrumentHTTP
function
#2855
Conversation
Codecov Report
@@ Coverage Diff @@
## experimental/tracing-module-client #2855 +/- ##
======================================================================
+ Coverage 76.60% 76.67% +0.07%
======================================================================
Files 222 222
Lines 16765 16796 +31
======================================================================
+ Hits 12843 12879 +36
+ Misses 3094 3085 -9
- Partials 828 832 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
9dbd43f
to
f6f06f5
Compare
765fa03
to
8ac172d
Compare
f6f06f5
to
e6452eb
Compare
8ac172d
to
001b855
Compare
10966dc
to
06bb82e
Compare
936303a
to
ba46f51
Compare
8ce5dff
to
1a7806b
Compare
ba46f51
to
f9fc8cd
Compare
1a7806b
to
9a2f2ec
Compare
f9fc8cd
to
8b7ab34
Compare
9a2f2ec
to
8419cb8
Compare
@codebien indeed, sorry for the noise... 🙇🏻 It should be fixed now 😸 (once CI completes) |
d255c80
to
22f1f70
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
Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
cmd/tests/tracing_module_test.go
Outdated
func TestTracingInstrumentHTTP_FailsOutsideOfInitContext(t *testing.T) { | ||
t.Parallel() | ||
tb := httpmultibin.NewHTTPMultiBin(t) | ||
|
||
script := tb.Replacer.Replace(` | ||
import tracing from "k6/experimental/tracing"; | ||
|
||
export default function() { | ||
tracing.instrumentHTTP({ | ||
propagator: "w3c", | ||
}) | ||
} | ||
`) | ||
|
||
ts := getSingleFileTestState(t, script, []string{}, 0) | ||
ts.ExpectedExitCode = 0 | ||
cmd.ExecuteWithGlobalState(ts.GlobalState) | ||
|
||
assert.Contains(t, ts.Stderr.String(), "instrumentHTTP can only be called in the init context") | ||
} | ||
|
||
func TestTracingInstrumentHTTP_CannotBeCalledTwice(t *testing.T) { | ||
t.Parallel() | ||
tb := httpmultibin.NewHTTPMultiBin(t) | ||
|
||
script := tb.Replacer.Replace(` | ||
import tracing from "k6/experimental/tracing"; | ||
|
||
tracing.instrumentHTTP({ | ||
propagator: "w3c", | ||
}) | ||
|
||
tracing.instrumentHTTP({ | ||
propagator: "w3c", | ||
}) | ||
|
||
export default function() { | ||
} | ||
`) | ||
|
||
ts := getSingleFileTestState(t, script, []string{}, 0) | ||
ts.ExpectedExitCode = 107 | ||
cmd.ExecuteWithGlobalState(ts.GlobalState) | ||
|
||
assert.Contains(t, ts.Stderr.String(), "instrumentHTTP can only be called once") | ||
} |
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.
I kind of prefer if those are not integration tests as they are more expensive and in this case there is no need for them IMO.
The functionality tested is pretty common :
- exception in an iteration does not abort the whole test
- an exception in the init context - does.
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.
Let me see if I can easily turn them into standard unit tests indeed. I've struggled with instrumentHTTP
depending on require in the past, but with the changes with made, it might not be such an issue anymore 👍🏻
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 if possible I would like to move some of the integration tests to not integration ones 🙇
Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
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.
I guess we do not have an integration test that instrumenting the API in one file will instrtument it across teh whole k6.
This likely is the most interesting integration test, so I think it is worth doing before merging
@mstoykov thanks a lot for your feedback 🙇🏻 I've replaced the relevant integration tests with unit tests. I've also added an integration test demonstrating |
assert.Equal(t, int64(8), atomic.LoadInt64(&gotRequests)) | ||
|
||
jsonResults, err := afero.ReadFile(ts.FS, "results.json") | ||
require.NoError(t, err) | ||
|
||
assertHasTraceIDMetadata(t, jsonResults) |
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.
Kind of the same comment about this not checking that all of those have tracing ids.
Maybe assertHasTraceIDMetadata
can have a number argument that is how many it expects 🤷.
Or to take the expected url(s) (as vararg not required argument) and check that all of those have trace id metadata sample.
I have left one comment that is not blocking IMO given that it is very unlikely breakage in that case (IMO) |
Thanks a lot for the reviews folks 🙇🏻 👏🏻 much appreciated! For the sake of getting a sense of achievement, I'll go ahead and merge this. I think your point on the 🚀 🚀 🚀 |
About
To keep Pull Requests as small as possible and reduce the review burden, this PR is the third one in a chain of three implementing the decided API design for the experimental tracing module.
warning ✋🏻 This PR is part of a PR chain, and is based on #2854
This second PR builds upon #2853 and #2854 and adds an
instrumentHTTP
function to k6/experimental/tracing.Using this function in their k6 scripts, once, users can automatically have all their calls to the
http
module's methods (http.{del,get,head,options,patch,post,put,request}
) automatically instrumented with tracing information, in the same fashion as described in #2854. Indeed, this function under the hood remaps thehttp
module's method to use theClient
's methods instead.The
instrumentHTTP
takes the same option set as theClient
as input but does not allow for reconfiguration, nor does it allow to perform non instrumented calls. As it is the intended behavior, once called, thehttp
module's methods are replaced with the instrumented ones.In action
To observe this example in action, I recommend running it with the --http-debug too. That way, you'll be able to observe the Traceparent header being added (note that when using the b3 or jaeger propagators, the header is named differently.
Review
The commits have been organized to be progressive and make sense as a sequence; thus, you should review them in order.
References
Previous: #2853 #2854