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

is counter macro supports floating point values? #367

Closed
dzmitry-lahoda opened this issue May 1, 2023 · 8 comments
Closed

is counter macro supports floating point values? #367

dzmitry-lahoda opened this issue May 1, 2023 · 8 comments
Labels
C-core Component: core functionality such as traits, etc. E-simple Effort: simple. T-ergonomics Type: ergonomics.

Comments

@dzmitry-lahoda
Copy link

No description provided.

@dzmitry-lahoda
Copy link
Author

as i see openmetrics are u64 or f64 prometheus/OpenMetrics#262 .

for me allow f64 in counter! and may be casting u128 to f64 behind scenes is good option to try to support fintech/crypto domains

@tobz
Copy link
Member

tobz commented May 1, 2023

No, it does not.

This is an intentional choice to ensure that counters are monotonically increasing, which would not be guaranteed if floating-point values were accepted, as negative values could be given, leading to the overall counter value decreasing.

If floating-point values are desired, gauges can be used instead, as helpers such as increment_gauge already exist for working with gauges in a similar way to counters.

@tobz tobz closed this as completed May 1, 2023
@tobz tobz added C-core Component: core functionality such as traits, etc. E-simple Effort: simple. T-ergonomics Type: ergonomics. labels May 1, 2023
@dzmitry-lahoda
Copy link
Author

hm. gauge is awesome. will use. it is for tracking some long lived entity (in my case account).

but how to use gauge to track transfers? it may be huge amount gagues.

is any paper on itsq equivalence?

@dzmitry-lahoda
Copy link
Author

@tobz may you reconsdier you opinion?

@tamasfe
Copy link

tamasfe commented Jul 3, 2023

This is an intentional choice to ensure that counters are monotonically increasing, which would not be guaranteed if floating-point values were accepted, as negative values could be given, leading to the overall counter value decreasing.

If floating-point values are desired, gauges can be used instead, as helpers such as increment_gauge already exist for working with gauges in a similar way to counters.

Guaranteeing positive values at the type-level is nice, however using a gauge and pretending it's a counter is not ideal. Prometheus has builtin features to deal with counter resets that are not available for gauge metric types (e.g. you cannot use the rate() function).

So in order to record total request times, you'd have to either:

  • use integers and a smaller unit, this technically works but goes against prometheus' conventions
  • use something like deriv() on the gauge, but this won't account for resets

These hacks could be avoided either by:

  • allowing to override metric type (even in just the exporter), this is hacky but could work
  • allowing f64 counters, and clipping new values below 0 (or do nothing and leave negative values as a responsibility of the user)

@tobz
Copy link
Member

tobz commented Jul 5, 2023

@tamasfe It's unfortunate that our choice to constrain counters to u64 has suboptimal interactions with that aspect of Prometheus, but it's not something I'm ever going to change in metrics.

If people are primarily interacting with Prometheus, and want an experience that matches the Prometheus conventions more closely, both the prometheus and prometheus-client crates are suitable replacements for metrics.

@tamasfe
Copy link

tamasfe commented Jul 6, 2023

We've just switched from prometheus to use metrics due to the convenient API and the architecture and philosophy that is similar to tracing. I was confident that this issue could be easily resolved or worked around as the most (only?) widely used exporter seems to target Prometheus.

that matches the Prometheus conventions more closely

It's not just Prometheus, OpenTelemetry also recently chose to recommend seconds as the unit of measurement for durations after a long debate.

but it's not something I'm ever going to change in metrics.

I'd be happy to submit a PR for it.

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.
Projects
None yet
Development

No branches or pull requests

3 participants