-
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
k6/metrics: Warn on metric names not compatible with Prometheus #3066
Conversation
While I was writing this I started wondering if an alternative approach of checking this after the initial init context run might not be more beneficial. The major problem is the registry can't currently return all the metric names, but it will let us catch extensions registering "bad" names |
Codecov Report
@@ Coverage Diff @@
## registry-fetch-all #3066 +/- ##
=====================================================
Coverage ? 76.73%
=====================================================
Files ? 229
Lines ? 17130
Branches ? 0
=====================================================
Hits ? 13145
Misses ? 3141
Partials ? 844
Flags with carried forward coverage won't be shown. Click here to find out more. |
Yeah, I see value into this. I prefer an approach that includes extensions so we don't create shadow zones.
Do you mean something like this? b485b22 |
@codebien yeah that seems like a thing I can use. Is that PR likely to be merged soon ™️ . If not can we pull this function out and then rebase both of our PRs on top of it? |
Not really
If you want to use it, sure. Creating the PR. |
db92213
to
b6b2214
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 (with test fixed), just a minor comment
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
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.
Compiling the regex outside of newBundle
is the only blocker for me.
But I have a general concern about this change. Shouldn't we only limit metric names if the Prometheus or OTel outputs are used? That is, wouldn't it make more sense to have this warning and eventual failure in the outputs themselves? It seems unnecessary to break metric names for all k6 users, even if they're not using Prometheus/OTel.
If we want to suggest people stick to this restriction anyway, then just a warning would be enough, without the breaking change in v0.48.0. But even a general warning would be annoying if someone is not using Prometheus/OTel.
js/bundle.go
Outdated
// TODO: this is to be removed once this is not a warning and it can be moved to the registry | ||
func (b *Bundle) checkMetricNamesForPrometheusCompatibility() { | ||
const ( | ||
nameRegexString = "^[a-zA-Z_][a-zA-Z0-9_]{1,128}$" |
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 didn't see a length limit on Prometheus' metric names in their documentation, but OTel limits it to 63 chars.
I'm not sure if we should follow whatever Prometheus' limit is, or OTel's, but 63 chars is way too restricting. So... neither?
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.
To be honest I did copy our length restriction mostly as this change is supposed to tighten the name in a way to be usable by as many outside systems as possible. And it still needs to actually be subset of what we currently support.
I didn't see that 🤦
To be honest 63 characters are quite a lot for a metric name to be honest.
MyReallyCoolCounterThatCountsRedEyedPuppies is only 43.
So to be honest I am okay with us going even down to 63 characters 🤷
cc @dgzlopes any thoughts?
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.
True, 63 chars ought to be enough for anybody.:tm: :smile:
It's probably a safe limit to impose. Even the browser's long Web Vital metrics like webvital_first_contentful_paint_good
is 36 chars, and going much above that would be messy to show in our CLI and Cloud UIs.
So if we want to be strict with OTel compatibility, we might also limit it to 63.
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.
By default, Prometheus has no limits (I think) (related: prometheus/prometheus#1235 (comment))
Is there any technical reason for us to set a limit?
I will change that if my comment there is not enough - I really have no problem with that.
I feel like I have not explained the change very well. Most systems working with metrics have some metric name restrictions. Of all of the Prometheus and Otel seem to be the one that get the most traction. Anyone who uses k6 and custom metrics and output to one of those systems will have some problems if k6 allows characters that are not supported by the other system. AFAIK the current k6 name restriction is mostly what it is because that is what we came up with. So this PR tries to make it so that k6 metric names will be supported by any output system irregardless of whether the users use them or not. As the issues says we will pivot in case there is a lot of user feedback that they want spaces (for example, also the character that started this). In practice this warning is a way to ask users for feedback in case they really want to keep something, until we actually deprecate it. cc @dgzlopes if you want to add more. |
If this is the attempt, then I would like to insert a call to action in the message explicitly requesting negative feedback. Something like: |
I think you covered all 👍 |
@mstoykov Yeah, I see the benefit of restricting this to some common set of characters that would be compatible with most metric backends. I was just wondering whether it made sense to force the change on users who don't use outputs that would be impacted by this. But OK, no blockers from me. Let's just agree on the length. |
@codebien I think the message is already long enough. And if users see a message that tells them that something that they need will not work in 2-3 versions, I would expect that:
We have been getting reports of this kind for a while without a big message, so I prefer to not make the message even longer. |
Eventually, we will store k6-cloud time-series data in Mimir, so we should enforce the metric name restrictions for all k6 tests (not only for those that use Prometheus output). 👍 from me. |
This adds a warning for custom metrics that are not Prometheus compatible. The warning is in the js/bundle mostly for convenience. It is a place we already have a registry and a logger and we go through only once. As this is temporary warning until we enforce stricter metric names I don't think it is good idea to refactor the registry to support this for a little while. Updates #3065
34e263e
to
1d9c60c
Compare
Documentation added in grafana/k6-docs#1205 |
This adds a warning for custom metrics that are not Prometheus compatible.
The warning is in the k6/metrics as the alternative was threading a logger in the registry specifically for this and then removing it.
The major downside of this is that extension can still register incompatible metric names without any warnings.
Updates #3065