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

Counter HELP and TYPE lack _total suffix #194

Closed
link2xt opened this issue Apr 17, 2024 · 5 comments
Closed

Counter HELP and TYPE lack _total suffix #194

link2xt opened this issue Apr 17, 2024 · 5 comments

Comments

@link2xt
Copy link

link2xt commented Apr 17, 2024

When encoding counters, prometheus-client adds _total suffix to sample name:

self.write_suffix("total")?;

This suffix is however not added in HELP and TYPE lines. This is visible in tests, for example:

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

HELP and TYPE lines should have the same suffix, it is shown in example at https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-example:

# HELP http_requests_total The total number of HTTP requests.
# TYPE http_requests_total counter
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400"}    3 1395066363000

Because of this bug Grafana does not display help for counters. At the same time for gauge type metrics help is displayed.

@mxinden
Copy link
Member

mxinden commented Apr 17, 2024

This is inline with the OpenMetrics specification:

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

When exporting, are you setting the correct content type?

hyper::header::CONTENT_TYPE,
"application/openmetrics-text; version=1.0.0; charset=utf-8",

@mxinden
Copy link
Member

mxinden commented Apr 17, 2024

I don't feel strongly about following the specification. That said, I want to be either (a) consistent with the specification or (b) consistent with the other client implementations and ideally (a) and (b).

@link2xt
Copy link
Author

link2xt commented Apr 17, 2024

I set content type here:
https://github.com/deltachat/notifiers/blob/6ef14e3b891c878f0bfd990f8436aeb3ba9f60eb/src/metrics.rs#L87-L90

Go library seems to include _total into HELP and TYPE:
https://github.com/prometheus/client_golang/blob/d038ab96c0c7b9cd217a39072febd610bcdf1fd8/prometheus/promhttp/http_test.go#L141-L144

OpenMetrics is indeed different from Prometheus documentation and what Go library does :/

I found that incompatibilities are documented here:
https://github.com/prometheus/client_java/blob/058b39959dff82ef5fcb126834d5c392cc64df37/docs/content/otel/names.md
And here:
https://opentelemetry.io/docs/specs/otel/compatibility/prometheus_and_openmetrics/

So currently Rust client library follows OpenMetrics specification and this is different from what Prometheus expects.

@link2xt
Copy link
Author

link2xt commented Apr 17, 2024

OpenMetrics support is also on roadmap: https://prometheus.io/docs/introduction/roadmap/#adopt-openmetrics

I will try updating Prometheus to the latest version and file a Prometheus bug then.

@link2xt link2xt closed this as completed Apr 17, 2024
@link2xt
Copy link
Author

link2xt commented Apr 17, 2024

I have filed Prometheus bug: prometheus/prometheus#13944

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

2 participants