-
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 API for user-specified high-cardinality metrics metadata #2766
Comments
After some internal discussion there is some agreement on a stop-gappy solution that let's users set metadata from JS code, but skips over the problems above. ProposalAdd That property behaves exactly as the current Additional API changes:Add Future APIs that do something with metrics and are per VU can use this as potential place to be added as well. But that is outside the scope of this discussion. Async caveats:Same as with import exec from "k6/execution";
export default async () => {
exec.vu.tags["someTag"] = "value"
await asyncCall() // not only is this call tagged with `"someTag"`, but anything that runs while it is awaited
delete exec.vu.tags["someTag"]
} In order to be able to use import exec from "k6/execution";
function helper(tagName, tagValue) {
try { // theorethically this can also reset to the old value
exec.vu.tags[tagName] = tagValue
return asyncCall()
} finally {
delete exec.vu.tags[tagName]
}
}
export default async () => {
await helper("someTag", "someValue")
} If you want to implement something like On a per call basis you can have somethign with lambda as in import exec from "k6/execution";
function helper(f, tagName, tagValue) {
try { // theorethically this can also reset to the old value
exec.vu.tags[tagName] = tagValue
return f() // f here is a call returning a promise
} finally {
delete exec.vu.tags[tagName]
}
}
export default async () => {
await f(()=> {
return asyncCall("with", "some", "arguments")
}, "someTag", "someValue"
}) |
A bare minimum API to set and get metadata set for the whole VU. It is added on top of the vu property and on top of a new `metrics` one so. If `k6/execution` is imported as `exec` - `exec.vu.metrics.metadata["foo"]` will get you the currently set metadata for `foo` the same way `exec.vu.tags["bar"]` will get you the value of the tag `bar`. Setting metadata is the same. It also adds `exec.vu.metrics.tags` which is the same as `exec.vu.tags` for consistency. While leaving the old one for backwards compatibility. This also includes dropping the ability to list metadata keys and values from `exec.vu.tags`. This was likely left in by mistake. This is a breaking change due to the fact that before that `iter` and `vu` could've been accessed this way but this will now need to be done through the new `exec.vu.metrics.metadata`. Closes #2766
A bare minimum API to set and get metadata set for the whole VU. It is added on top of the vu property and on top of a new `metrics` one so. If `k6/execution` is imported as `exec` - `exec.vu.metrics.metadata["foo"]` will get you the currently set metadata for `foo` the same way `exec.vu.tags["bar"]` will get you the value of the tag `bar`. Setting metadata is the same. It also adds `exec.vu.metrics.tags` which is the same as `exec.vu.tags` for consistency. While leaving the old one for backwards compatibility. This also includes dropping the ability to list metadata keys and values from `exec.vu.tags`. This was likely left in by mistake. This is a breaking change due to the fact that before that `iter` and `vu` could've been accessed this way but this will now need to be done through the new `exec.vu.metrics.metadata`. Closes #2766 Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com> Co-authored-by: Ivan Mirić <ivan.miric@grafana.com>
Feature Description
k6 v0.41.0 added a
Metadata
property for storing high-cardinality metadata to allmetric.Sample
values that is not part of theSample
'sTimeSeries
:k6/metrics/sample.go
Lines 19 to 33 in e14f14d
However, we decided (#2584 (comment)) to not merge the originally proposed JS APIs from #2654 that allowed users to set whatever metadata values they wanted from their scripts, since they presented a somewhat confusing UX. The
Sample.Metadata
property is currently only accessible from Go code, either the built-in k6 modules and outputs or from xk6 extensions.I am adding this issue as a placeholder, so it can be referenced by other issues. We still haven't reached a consensus how (and even if) the
Metadata
should be made accessible from user scripts.A major use case for this feature is distributed tracing (#2128), though it doesn't necessarily need JS code to be able to access and set custom metrics metadata. If anyone has another use cases that will benefit from this feature, please share them here.
Suggested Solution (optional)
No consensus and firm proposals yet. There are various ideas with different pros and cons, and this deserves a broader discussion. Some of them:
metrics.withMetadata(metaObj, callback)
API similar togroup()
, though that has its own problems with async APIs (group
doesn't work with async calls well #2728)metadata
property in all of the calls where we currently supporttags
has the problem that it's yet another custom thing that needs to be implemented in every protocol, it is ambiguous (is the "metadata" property about the call and not its metrics?) and it conflicts with the already existingmetadata
property in gRPC calls.We are discussing this internally, but if someone has API proposals or ideas, please share them here.
Already existing or connected issues / PRs (optional)
The text was updated successfully, but these errors were encountered: