metrics-rs / metrics

A metrics ecosystem for Rust.
MIT License
1.1k stars 151 forks source link

Prometheus exporter: Histogram metric using "quantile" instead of "le" #385

Closed yanns closed 1 year ago

yanns commented 1 year ago

Related to https://github.com/Ptrskay3/axum-prometheus/issues/24

When we install a recorder: https://github.com/Ptrskay3/axum-prometheus/blob/da7630a48107996cd0b6f01a757256957cb91b55/src/lib.rs#L463-L473, the prometheus exporter is using the label quantile.

In Prometheus, the standard label is le.

Should we stick to the prometheus standard by default?

tobz commented 1 year ago

This isn't actually an issue with metrics-exporter-prometheus. The linked issue sort of gets there but doesn't quite explain the why, which has clearly left the other users in the issue confused.

Prometheus supports both aggregated histograms and aggregated summaries. Histograms are emitted in a bucketed fashion (le) and summaries are emitted in a quantile fashion (quantile). This is all normal and straightforward.

metrics has no concept of "histograms" vs "summaries": it only cares about "histograms" insofar as being a set of unsampled observations. In turn, metrics-exporter-prometheus has to make a choice for how to represent them by default, which is as aggregated summaries. The crate author, in the linked issue, shows the inverse of this, where they're specifically setting one metric to be emitted as an aggregated histogram instead.

In summary (heh), if you want all histograms in metrics to be emitted as aggregated histograms in metrics-exporter-prometheus, then you need to specifically configure the recorder, as the crate author mentions, by using PrometheusBuilder::set_buckets.