-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Optionally add OM unit #1392
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
base: main
Are you sure you want to change the base?
Optionally add OM unit #1392
Conversation
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
|
Hey @vesari , just passing by to ask if there is anything we could do to unblock you 👋 |
@ArthurSens hello! I think I'm just using a Go version which is too new, I plan on fixing that later today. Thanks a lot for checking on me, much appreciated! :) |
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
ArthurSens
left a 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.
If we decide to support units, let's think of alternative that isn't breaking changes to downstream projects :)
prometheus/example_metricvec_test.go
Outdated
| func NewInfoVec(name, help string, labelNames []string) *InfoVec { | ||
| desc := prometheus.NewDesc(name, help, labelNames, nil) | ||
| func NewInfoVec(name, help, unit string, labelNames []string) *InfoVec { | ||
| desc := prometheus.NewDesc(name, help, unit, labelNames, nil) |
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.
Similar problem here, we can't change Public function's signatures
tutorial/whatsup/go.mod
Outdated
| module github.com/prometheus/client_golang/tutorial | ||
|
|
||
| go 1.20 | ||
| go 1.21 |
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 believe we want to keep 1.20 until the next go release
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.
Oops. Yes, absolutely. Just a leftover from when I reverted the changes I had made before common was fixed in this sense.
Of course! I'll await your decision whether to support them and, if so, I'll be happy to continue working on it the way you suggested :) |
It's hard for me to give a fair judgement here (because of my difficult history with OM). Having said that, the OM approach to units strikes me as weird. I understand the historical Prometheus approach of "including the unit in the metric name" as a pragmatic solution to the lack of proper metadata support in Prometheus. It should be noted that it always has been just a convention. OM added the unit metadata field, presumably because others asked for it (the OTel data model didn't exist back then, but I assume that the presence of a unit field in OTel comes from the same school of thinking). Now you might think, if OM has it as an explicit field, you don't have to include it in the metric name anymore. But OM did the opposite: If there is a unit field, the same string MUST be in the metric name, otherwise it is not valid OM. Personally, I think it should be possible to include the unit in the metric name (for those that like that for all the situation where you do not want to lookup the metadata even if you could), but given that others want to live in a world where metadata is always available at your fingertips, enforcing it in the metric name feels redundant. Sadly, OTel took its guidance for Prometheus compatibility from OM, so the way the OTel data model is converted to Prometheus is already following the OM requirements, although there was never a Prometheus consensus about it. Looping back to the question: How should we deal with the situation in client_golang? Given how far unit support has already seeped into various parts of the wider ecosystem, it's tough to say "this is all f*** up, let's just ignore it". How "1st class" adding the unit should be, is up to debate. I definitely wouldn't require all users to now add a unit. It should be an option for those that want it. WRT to |
|
Thank you all very much for your considerations and suggestions! In order not to enforce that the unit is also in the metric name when the unit field is populated, the logic in |
|
To be clear: @ArthurSens @bwplotka @kakkoyun should make the call here. I'm just providing my personal context. |
|
Hi @vesari! The team met recently and one of the things we discussed was whether we accept OpenMetrics units or not. Reading the OpenMetrics specification, we can read[1][2]: We clearly understand that units are required by OpenMetrics 1.0, and we clearly understand that units must be used as metric name suffixes. However, at this point, if we accept this the only benefit would be to say "We're OpenMetrics 1.0 compatible". Being OpenMetrics 1.0 compatible is not a bad thing per se, but Prometheus hasn't used the Unit metadata for anything yet, so it brings Client_golang users little benefit while making our API a bit more complex. If in the future Prometheus introduces the usage of Unit metadata, e.g. to properly sum metrics with different but compatible units (one in seconds and the other in milliseconds), we'd be happy to resurrect this. In the name of the team, we apologize for taking this long to make a decision. Your work was quite involved, spreading contributions across multiple repositories and communicating with several stakeholders. We'd be happy to continue working with you if that's also of your interest :) |
|
Maybe we could start brainstorming how to use the unit metadata in Prometheus? Although this would be a high-complexity project that I would also need a lot of time to understand properly😬 |
@ArthurSens, no worries at all, I totally understand. Of course I’d be delighted to continue working with the team, thanks for suggesting that! |
Either this or anything the team deem useful. Whatever you think needs attention, I’ll be happy to work on :) Feel free to DM me on Slack if necessary. Thank you! |
|
As agreed with @bwplotka, we want to add units eventually, but this needs more thought on how to avoid adding significant boilerplate to all users for that; help wanted, closing for now. |
|
We might want to ressurect this PR now that prometheus/proposals#39 adds a purpose to units in Prometheus :) |
|
I'll be happy to do so |
|
@kakkoyun ignore the request for review for now, as it was sent automatically once I reopened the PR. There's still a lot to catch up on here and work to do. |
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
bwplotka
left a 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.
This is amazing. Solid work, thanks for finding way to not break compatibility.
Added a few suggestions and ideas, hope those help! Overall this goes in a good direction 👍🏽
| enc = expfmt.NewEncoder(w, contentType) | ||
| encOpts = append(encOpts, expfmt.WithCreatedLines()) | ||
| } | ||
| if opts.EnableOpenMetricsUnit { |
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.
Do we need this manual flag?
Why can't we simply add UNIT line if someone enabled OM? Shouldn't this be safe?
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.
We added flag for EnableOpenMetricsTextCreatedSamples because we believe CT line is potentially breaking to the ecosystem (lot's of problems). But with UNIT metadata, I'd expect OM compatible parsers to either ignore it or parse. Even TEXT formats should work, because it's just a # .. comment.
The only potential risk is the slight increase of payload size, but this is actually limited by the user who need to manually add Unit: <....> fields to their metric definitions, no?
| encOpts = append(encOpts, expfmt.WithCreatedLines()) | ||
| } | ||
| if opts.EnableOpenMetricsUnit { | ||
| encOpts = append(encOpts, expfmt.WithUnit()) |
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 wonder, does this print UNIT line if UNIT is unknown (empty string?)
Can we ensure this does NOT add UNIT if it's unknown? Just to safe space and limit the risks mentioned in https://github.com/prometheus/client_golang/pull/1392/files#r2580622660
| EnableOpenMetricsTextCreatedSamples bool | ||
| // EnableOpenMetricsUnit enables unit metadata in the OpenMetrics output format. | ||
| // This is only applicable when OpenMetrics format is negotiated. | ||
| EnableOpenMetricsUnit bool |
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.
again, I wonder if we could skip this (reduce complexity and effort for everyone, users already need to manually add Unit field).
| } | ||
|
|
||
| wantMsg := `error gathering metrics: error collecting metric Desc{fqName: "invalid_metric", help: "not helpful", constLabels: {}, variableLabels: {}}: collect error | ||
| wantMsg := `error gathering metrics: error collecting metric Desc{fqName: "invalid_metric", help: "not helpful", unit: "", constLabels: {}, variableLabels: {}}: collect error |
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.
Can we ensure everywhere we don't print empty string? (and just skip it?). It does not give a lot of info in an empty string form
| // For constLabels, the label values are constant. Therefore, they are fully | ||
| // specified in the Desc. See the Collector example for a usage pattern. | ||
| func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, constLabels Labels) *Desc { | ||
| func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, constLabels Labels, unit ...string) *Desc { |
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.
Here, I wonder if we don't want to break compatibility. 🤔 It's V2 and I wished we marked it as experimental somewhere visibility (it was meant to experiment on a new API). However, I bet downstream ecosystem already started using it.
I'd suggest, (see A, B options in https://github.com/prometheus/client_golang/pull/1392/files#r2580668173)
- For
NewDescwe do (B) - For V2 we do (A) ?
| // label names. | ||
| xxh.Reset() | ||
| xxh.WriteString(help) | ||
| xxh.WriteString(optionalUnitValue(unit...)) |
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's eval unit as soon as we have it from descV2Opts or something
| } | ||
| return fmt.Sprintf( | ||
| "Desc{fqName: %q, help: %q, constLabels: {%s}, variableLabels: {%s}}", | ||
| "Desc{fqName: %q, help: %q, unit: %q, constLabels: {%s}, variableLabels: {%s}}", |
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.
ditto, optionally print it?
| sampleBuf = append(sampleBuf, metrics.Sample{Name: d.Name}) | ||
| sampleMap[d.Name] = &sampleBuf[len(sampleBuf)-1] | ||
|
|
||
| // Extract unit from the runtime/metrics name (e.g., "/gc/heap/allocs:bytes" -> "bytes") |
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.
That's nice!
Co-authored-by: Bartlomiej Plotka <[email protected]> Signed-off-by: Arianna Vespri <[email protected]>
Co-authored-by: Bartlomiej Plotka <[email protected]> Signed-off-by: Arianna Vespri <[email protected]>
Signed-off-by: Arianna Vespri <[email protected]>
Thank you very much, I'm working on addressing your requests for changes and your observations. I'll get back to you once I'm done :) |
This PR adds support for unit for Open Metrics. It is ready for review, but not ready to merge (see my long comment below). Fixes #684.