tikv / rust-prometheus

Prometheus instrumentation library for Rust applications
Apache License 2.0
1.07k stars 182 forks source link

Emit metrics sorted by the "natural" ordering of their label values #458

Open bisgardo opened 2 years ago

bisgardo commented 2 years ago

Is your feature request related to a problem? Please describe.

The gather method of Registry currently emits the gathered metrics ordered by their label values sorted lexicographically (code):

gather calls the Collect method of the registered Collectors and then gathers the collected metrics into a lexicographically sorted slice of MetricFamily protobufs.

If I understand correctly, the legend in Grafana will order the series in the order they're emitted by Prometheus?

If so, it could greatly improve readability if labels could be sorted by natural order, i.e.

node-1
node-2
...
node-10

rather than the lexicographic order

node-1
node-10
node-2
...

Describe the solution you'd like

Options, ordered by my preferences:

Describe alternatives you've considered

Post-sort the Vec<proto::MetricFamily> returned by gather. This is too hacky to see the light of day.

Additional context

None.