-
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
Function cannot read tag value from options.tags object directly #2278
Comments
Maybe noteworthy: Scenario-specific tags don't suffer from this: export const options = {
tags: { mytag: 'myvalue' },
scenarios: {
bug: {
executor: 'shared-iterations',
tags: { scntag: 'scnvalue' },
},
},
};
export default function() {
console.log(options.tags.mytag); // missing, prints undefined
console.log(options.scenarios.bug.tags.scntag); // correctly prints "scnvalue"
} This might be explained by the fact that scenario tags cannot be set via the CLI. |
Hi @knittl, The issue is that It does however implement marshalling to JSON which exposes the internal map so going to JSON and back to js object in practice makes it serialize the internal map and then that gets back as a simple map instead. In the case of the I am pretty sure that at least for one of all the options this adds a race condition or something - which is pretty bad. Arguably the instead of the complicated reflect based code we should just Currently, you should be able to use the new (as of v0.35.0) k6/execution.vu.tags to get the tags' value. I don't really know what the next step here is, but I kind of think it will be best if we first get the API to get the whole options in some okay form and then start to give warnings to people who try to use the |
@mstoykov, thanks for the answer. Is there a reason why it needs to be the internal type/wrapper and not a regular map? Or why this internal type cannot provide access to its inner map values? Thanks for the hint about Warning users when they try to read |
We just realized that we inadvertently fixed this as a side-benefit of the refactoring in #2631 😅 So it will be released in k6 v0.40.0 in a few weeks 🎉 That PR was a precursor for a much bigger metrics refactoring PR (#2594, which unfortunately got delayed for v0.41.0) and we just now realized it had other actual benefits it provided... 😅 In any case, I'd still advise any k6 users to use the much more predictable and accessible FWIW, another bugfix that will land in k6 v0.40.0 is #2571, which fixed the bug of having global variables in the main script being mistakenly made into superglobals for other imported files. This has been a problem for some users that relied on the bug (e.g. #2623) and importing |
Here's an interesting find I had yesterday: It is not possible to read a tag from the
options.tags
object directly. You will always end up withundefined
. However, if you serialise (JSON.stringify
) and parse again, you can access the values.I encountered the problem in an exported custom
handleSummary
function, but it is reproducible in the same way in the default function. Maybe there's a canonical (better) way to access the (user-defined) tags in thehandleSummary
function?Here is a simple snippet to reproduce this issue. I assume this is caused by the fact that
options.tags
can be updated by the runtime – e.g. command line flag--tag tagname=tagvalue
– and are not a "real" (?) JavaScript object, but rathergo
objects? So likely a go-js interop issue and not goja issue? Interestingly though, thatJSON.stringify
seems to be unaffected by this.I ran the above script in k6 versions 0.26.0 through 0.35.0 via Docker containers and all exhibit the same behavior. It's not a big problem, since I can work around the issue by roundtripping through JSON.stringify/parse, but it definitely is a surprising behavior which I wouldn't expect as a user.
If you need further info, please let me know.
The text was updated successfully, but these errors were encountered: