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

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

Open
bisgardo opened this issue Sep 9, 2022 · 0 comments
Open

Comments

@bisgardo
Copy link

bisgardo commented Sep 9, 2022

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:

  • Add a switch/option to gather to opt into natural ordering.
  • Allow support for passing a custom sorting function. On the one hand there are also only so many reasonable ways to sort strings that it might seem like overkill. But it also allows users to decide for themselves what library to use - and mean that this library doesn't need to ship nor depend on one. And one could of course also imagine esoteric use cases like sorting by Roman numerals or whatever.
  • Use natural ordering by default (with or without option to use lexicographic). I would do this for a new project, but changing existing default behavior might be undesired.

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.

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

1 participant