Skip to content
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

Add units to prometheus metric lines #535

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fayalalebrun
Copy link

This adds units to the prometheus exporter metric lines as the prometheus naming conventions specify:
https://prometheus.io/docs/practices/naming/

The units without a prometheus equivalent such as kilobytes or bytes_per_second were left as is in order to not lose information given by the user.

I also think _total should be appended to all counters. However, that is for a future pull request.

Closes #426.

This adds units to the prometheus exporter metric lines as the
prometheus naming conventions specify:
https://prometheus.io/docs/practices/naming/

The units without a prometheus equivalent such as kilobytes of
bytes_per_second were left as is in order to not lose information
given by the user.
Copy link
Member

@tobz tobz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So at a high-level, I'm not opposed to this although it will definitely need to live behind a flag to enable it, with it disabled by default.

Separately, though, I'm curious for your thoughts around how to close the gap between what this PR does and what the ideal semantic suffixing strategy is, as defined by the "Metric and label naming" guide.

For example, one thing is base units. The guide recommends avoiding using non-base units (i.e., prefer seconds over milliseconds/nanoseconds/etc) but in this PR, we're just tacking on whatever the defined unit is. Should we actually be adjusting the value to normalize it to seconds? And do a similar thing for bytes, etc.

(I originally commented about counters and _total but glossed over the fact you've already mentioned that in the PR description.)

@tobz tobz added C-exporter Component: exporters such as Prometheus, TCP, etc. T-enhancement Type: enhancement. labels Oct 19, 2024
@fayalalebrun
Copy link
Author

I think a flag is a good idea. But just to confirm, you do mean a runtime flag right?

I think it would be a good idea in general to normalize the units, though it will require some refactoring. Let me know if you would like me to add it here. What would make this process easier is if metrics stored the unit and the magnitude separately.

One incongruity here is the fact that counters can only take an integer value. For instance, this makes it such that counters in seconds do not make much sense. However, for example prometheus uses f64, sentry uses f64 and otlp allows for the use of either f64 or i64. Perhaps then this should change in metrics itself, as the limitation to integers does not match most metrics protocols. See:
https://docs.rs/sentry-core/0.32.3/sentry_core/metrics/type.CounterValue.html
https://docs.rs/opentelemetry-proto/latest/opentelemetry_proto/tonic/metrics/v1/struct.Sum.html

Another concern are the per second metrics. The advice from prometheus is to let the prometheus implementation compute the rate by itself. However, the prometheus guidance specifies the "power" unit, which is aggregated over time. So normalizing these but otherwise leaving them as-is could be an acceptable solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-exporter Component: exporters such as Prometheus, TCP, etc. T-enhancement Type: enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

metrics-exporter-prometheus should use units set by describe macro.
2 participants