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

Metric names are incorrectly generated #51

Open
08d2 opened this issue Mar 9, 2022 · 8 comments
Open

Metric names are incorrectly generated #51

08d2 opened this issue Mar 9, 2022 · 8 comments

Comments

@08d2
Copy link

08d2 commented Mar 9, 2022

The problem is demonstrated by the following comment

//! let expected = "# HELP my_counter This is my counter.\n".to_owned() +
//!                "# TYPE my_counter counter\n" +
//!                "my_counter_total 1\n" +
//!                "# EOF\n";

The HELP and TYPE lines should use my_counter_total, not my_counter.

@08d2
Copy link
Author

08d2 commented Mar 9, 2022

It is somewhat surprising that the metric name provided to counter constructors will have _total appended to it automatically. It would be cool if that were better documented, and ideally only happened if the provided metric name didn't already end in _total.

@mxinden
Copy link
Member

mxinden commented Mar 11, 2022

The HELP and TYPE lines should use my_counter_total, not my_counter.

Not according to the OpenMetrics specification:

https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#counter-1

It is somewhat surprising that the metric name provided to counter constructors will have _total appended to it automatically. It would be cool if that were better documented, and ideally only happened if the provided metric name didn't already end in _total.

Good idea. For the former, would you mind extending the documentation @08d2? For the latter, let's move the discussion to #52.

@08d2
Copy link
Author

08d2 commented Mar 18, 2022

Not according to the OpenMetrics specification

I don't know anything about OpenMetrics, really, and I don't consider it any kind of authority. I can observe that the "_created" thing described in your link is not valid for Prometheus, though.

edit: Ah, reading more carefully....

# TYPE foo counter
foo_total 17.0

AFAIK, this is not compatible with the Prometheus exposition format. For Prometheus, the identifier after e.g. TYPE and HELP tokens must be the actual name of the metric. And HELP is mandatory.

# TYPE foo_total counter
# HELP foo_total Total number of foo events.
foo_total 17.0

@08d2 08d2 changed the title Text encoding has inconsistent metric names Metric names are incorrectly generated Mar 25, 2022
@mxinden
Copy link
Member

mxinden commented Jun 3, 2022

AFAIK, this is not compatible with the Prometheus exposition format.

Note that you need to set the right content type in order for Prometheus parse the output of a scrape in the Open Metrics format.

.content_type("application/openmetrics-text; version=1.0.0; charset=utf-8")

@nox
Copy link
Contributor

nox commented Oct 10, 2022

We have ~100 unsuffixed metrics at work and we are trying to move away from prometheus and to switch to prometheus-client, this automatic suffixing is an issue, we don't want to change dozens of dashboards because a library forces counter renames on us. Would you accept a PR adding a LegacyUnsuffixedCounter<A> type to this crate?

@mxinden
Copy link
Member

mxinden commented Oct 12, 2022

Would you accept a PR adding a LegacyUnsuffixedCounter<A> type to this crate?

That sounds reasonable. I would suggest we add the above type under a feature flag (e.g. prometheus-legacy-format).

Note that I would see this as a small helper to enable folks to migrate to the OpenMetrics format eventually. I don't see this as a long term solution for downstream users. Do you agree with that mind set @nox?

//CC @RichiH in case you have opinions.

@RichiH
Copy link
Member

RichiH commented Oct 12, 2022

I can understand the resistance to changing names, but also note that following best current practices earlier rather than later is usually Least Bad, long term.

The proposed seems like a partial undoing of one specific thing, not a full Prometheus exposition format 0.0.4; that's arguably the worst of both worlds globally, even though it may appear to make sense locally.

All that being said, no strong opinions on if this is implemented or not.

@08d2
Copy link
Author

08d2 commented Oct 19, 2022

Note that I would see this as a small helper to enable folks to migrate to the OpenMetrics format eventually.

OpenMetrics remains an experiment, not a standard. Prometheus client libraries should default to the core exposition formats, and leave OpenMetrics as an opt-in alternative.

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

No branches or pull requests

4 participants