Open roshaans opened 1 year ago
I have the same problem, though in my case I actually did overflow an i64. A u64 gauge would be perfect for me. Or, failing that, if IntCounter
had a set
method, that would work too.
All the Int*
types offer some basic additional sugar, but by their own design they can't cover all possibilities. And handling all the possible cases with custom types will result in a unmaintainable matrix.
If your usecases do not fit in what the i64
helpers provide, then I'd recommend to use the usual f64
methods instead as they are actually meant to cover a larger set of cases.
That said, maybe there is a way to accommodate the u64
without adding a lot of new dedicated types, given that the AtomicF64
in this crate internally uses an atomic u64
.
For our my case, f64
would be even worse. I have a counter, and I need to measure the difference between adjacent values, so f64
would result in a big precision loss.
But that's not something that this type of instrumentation can provide, nor a problem that we can solve in this library.
At the bottom of all this, values only exist as f64
and Prometheus doesn't do integers.
So does this crate already convert i64 types info f64 internally?
But, once again, f64
is really how the whole Prometheus universe works.
Lame. Well, that's what I'll do now. I'll just use the f64 Gauge type.
There are currently two types of Guage types supported by this library.
IntGauge
supports i64 values andgauge
supports f64 values. It would be great if there was aGuage
type that supported u64 values as well as u128 values.We currently cast our u64 value into an i64 type so we can use the
IntGuage
type. This approach can possibly throw an exception when the u64 value goes out of bounds and we would ideally like to avoid that.We considered using the simple
guage
type which supports f64 values but there seems to be a lot more performance overhead in using that according to the docs here.Regarding the need for a u128 type guage, we would like to store a timestamp in nanoseconds which requires this, but it would be better to prioritize the u64 type first.