Skip to content

Prometheus: Add setting for recommended metric names #596

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

michelhe
Copy link
Contributor

This commit adds a setting to PrometheusBuilder to add the '_total' suffix to counter names, compatible with Prometheus naming best practices.

This is useful for migrating from the [prometheus-client] crate, (where the counter suffix is enforced) without breaking existing dashboards.

prometheus-client

This commit adds a setting to PrometheusBuilder to add the '_total'
suffix to counter names, compatible with [Prometheus naming best practices](https://prometheus.io/docs/practices/naming/).

This is useful for migrating from the [prometheus-client] crate, (where
the counter suffix is enforced) without breaking existing dashboards.

[prometheus-client](https://docs.rs/prometheus-client/latest/prometheus_client/)

Signed-off-by: Michel Heily <[email protected]>
@tobz
Copy link
Member

tobz commented Jul 17, 2025

👋🏻

I'd rather see this updated here:

Some(Unit::Count) | None => {}

Having two distinct settings for controlling metric name suffixes is too much. I think we would just add this for the Unit::Count case, though.

@michelhe
Copy link
Contributor Author

👋🏻

I'd rather see this updated here:

Some(Unit::Count) | None => {}

Having two distinct settings for controlling metric name suffixes is too much. I think we would just add this for the Unit::Count case, though.

Only Unit::Count isn't enough to allow migration from prometheus-client . That crate formats unit-less counters with _total suffix and counters with unit information with the _{unit}_total suffix, following the Prometheus naming best practices document to the word.

See these lines from the above link:

http_requests_total (for a unit-less accumulating count)
process_cpu_seconds_total (for an accumulating count with unit)

If you don't want yet another setting, maybe we can have a set_prometheus_client_compat_mode that implictly enables the unit suffix as well?

@tobz
Copy link
Member

tobz commented Jul 18, 2025

Blah, sometimes I really dislike how prescriptive Prometheus is... 😅

Alright, yeah: I think what I ultimately want to work towards is being able to get rid of these opt-in ways of adding the unit suffixes, adding the _total suffix, etc... so I like your idea of an all-in-one method.

Some thoughts:

  • I'd call it with_recommend_naming, but keep the existing signature as you have it
  • have with_recommended_naming also enable unit suffixes, as you mentioned
  • add #[deprecated(since = "0.18.0", note = "users should prefer `with_recommended_naming` which automatically enables unit suffixes")] to set_enable_unit_suffix

Then in 0.19.0, I can remove set_enable_unit_suffix and mark with_recommended_naming as deprecated, and in 0.20.0, remove with_recommended_naming and just make it the default behavior. 😌

@michelhe
Copy link
Contributor Author

Yep, Sounds good to me overall — I like the direction.

My only concern is around deprecating or changing the default behavior too aggressively — there might be users who currently only enable unit suffixes, and if their dashboards are tied to that, it could be hard or even impossible for them to update (e.g. if the app is deployed to customers).

If breaking changes are introduced - might be worth keeping a way to retain the current behavior, even if it's opt-in.

@michelhe michelhe changed the title Prometheus: Add compatibility mode for counter names Prometheus: Add setting for recommended metric names Jul 18, 2025
@michelhe
Copy link
Contributor Author

I pushed the changes you suggested, and also had to fix some stuff in formatting.rs.

Mainly, the fix I made in 80960de could be breaking existing metric names for users who use unit-suffixes :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants