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

Dimensions are order-sensitive #558

Open
arielb1 opened this issue Feb 17, 2025 · 3 comments
Open

Dimensions are order-sensitive #558

arielb1 opened this issue Feb 17, 2025 · 3 comments
Labels
C-core Component: core functionality such as traits, etc. E-simple Effort: simple. T-ergonomics Type: ergonomics. T-request Type: request.

Comments

@arielb1
Copy link

arielb1 commented Feb 17, 2025

This creates 2 different gauges, which is probably not what you want, since the order of the dimensions differs between the two:

            gauge!("my_gauge", "foo" => "0", "bar" => "1").increment(1);
            gauge!("my_gauge", "bar" => "1", "foo" => "0").increment(1);

I saw this happen when using a HashMap for dimensions, and the HashMap getting a different order every time. This behavior should at least be better documented.

@tobz
Copy link
Member

tobz commented Feb 19, 2025

Hmm, agreed.

This would be an exporter implementation detail, whether or not they dedupe labels and/or sort them... but it could stand be called out at a high-level as such, rather than leaving it open to assuming that metrics itself somehow dedupes/sorts labels for you.

If you're willing to contribute a PR, that would be great. It'll probably take me some time to get to it otherwise.

@tobz tobz added C-core Component: core functionality such as traits, etc. E-simple Effort: simple. T-ergonomics Type: ergonomics. T-request Type: request. labels Feb 19, 2025
@arielb1
Copy link
Author

arielb1 commented Feb 19, 2025

It's not obvious how an exporter would aggregate gauges post-facto. And if an exporter wants to make the calls to register_gauge return the same gauge for both orders, they can't use the Hash implementation on Key since it's order sensitive. For counters and histograms, there's at least an obvious aggregation method, tho people can still call Counter::absolute.

@tobz
Copy link
Member

tobz commented Feb 19, 2025

I was referring to doing it pre-facto. :)

Exporters aren't beholden by the hashing that happens implicitly in Key: they could use a newtype wrapper with order-insensitive hashing and deduplication, etc. Practically speaking, almost all exporters I've written or seen just use the existing Key hash, but it's not required to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-core Component: core functionality such as traits, etc. E-simple Effort: simple. T-ergonomics Type: ergonomics. T-request Type: request.
Projects
None yet
Development

No branches or pull requests

2 participants