-
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
js/k6/exec: Set VU Tags #2172
js/k6/exec: Set VU Tags #2172
Conversation
js/modules/k6/execution/execution.go
Outdated
if enabled, ok := o.SystemTags[key]; ok && enabled { | ||
return false | ||
} |
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.
The way systemTags.Map is implemented enabled
is always true
if it's in the map (ok is true). Was your idea that you should not be able to set a tag with the same name as a system tag if it's not enabled ... because I don't think this is needed if someone wants to set a tag ... they probably should be able to, even if it collides with some of ours ... if anything for most cases unless it's disabled we will likely overwrite it somewhere down the codepath, for at least some of them
4023685
to
6404b50
Compare
Pushed some basic code for supporting the lock. WDYT? I will wait for a consensus about the API before polishing more. |
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.
The basic TagMap seems fine to me, so we can continue polishing it.
It seems because of the usage of lib.State.CloneTags() in most places it won't be as big of a change as I expected 😅
3790391
to
d3e4d1f
Compare
Added the full test coverage for the TagMap API and removed the useless check for system tags. Ready for a new review. |
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 in general, I don't see how this will break.
I might've tried sync.Map
but I don't think it matters enough and we can always redo it in the future
I thought about it, but the case of this PR doesn't seem to fit very well for it. From the sync.Map doc:
It would require k6 specific benchmarks. Maybe, can we can consider to open an issue and iterate on it if we will identify a requirement? |
@mstoykov Added the json test but we should be sure that we are fine with #2172 (comment) |
Just a note on |
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.
Mostly LGTM and I'm fine with merging it if you make a v0.36.0 issue about https://github.com/grafana/k6/pull/2172/files#r740787612
Though fixing that should probably be easy, so it might be a bit better if you do it in this PR 🤷♂️
@na-- I prefer to address it now, I will try it today 👍 |
Pushed changes as defined in #2172 (comment) |
// In any other case, if the Throw option is set then an error is raised | ||
// otherwise just a Warning is written. | ||
func (o *tagsDynamicObject) Set(key string, val goja.Value) bool { | ||
switch val.ExportType().Kind() { //nolint:exhaustive |
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.
Doesn't the default
case make this linter compliment?
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.
apparently not, seems it prefer explicit cases
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.
func TestVUTags(t *testing.T) { | ||
t.Parallel() | ||
|
||
setupExecModule := func(t *testing.T) (*ModuleInstance, *goja.Runtime, *testutils.SimpleLogrusHook) { // nolint:unparam |
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.
@mstoykov regarding linter, this also is not totally clear to me, maybe it's spotting a bug that I'm not seeing
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.
You are not using I just saw where you do .... 🤔t
I think
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.
from my local experiments ... it seems like unparam
can't find that you actually use the hook(the last result) in one of the cases and that is what is being.
If you add it to first subcase and assert that it's empty it fixed itself 🤷
Also maybe (not necessary in this PR you can move this to the outside in a function and not actually have sub tests with but just a bunch of single tests as this just adds indentation currently.
I also have started to make these functions to return a struct with the things so that you don't have to constantly add 1 more returned thing whenever we add one more thing we need.
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 👏
I would just like to point out that for some system tags setting them through this will have effects.
Like for example setting name
will work for HTTP requests, but setting url
(and having it still enabled in system tags) will not, and probably most others in such a situation. But for example vu
or scenario
will always be overwritten.
This definitely needs some documentation and likely at least a discussion (in an issue) on what needs to be done if anything
Extended the k6/execution API to allow the get or set of a Tag in the VU state.
I will add it to the documentation, @mstoykov can you open an issue for it, please? (I'm not sure to know all the possible cases so I will be for sure not exhaustive in describing the issue, and probably you already have a better vision about possible implementations). |
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 version looks much more neat. Nice work 😄
Extended the
k6/execution
API to allow the get or set of a Tag in the VU's state.This part of the Stage tagging work, but it can be considered as an independent feature.