Replies: 3 comments
-
Unfortunately, a bank account is fundamentally a gauge, which is incompatible with rate(). I have read your message and you are aware of that, but I fundamentally think that even if we would allow unary negation of vectors, you would stumble accross other issues. As a workaround, you could try:
|
Beta Was this translation helpful? Give feedback.
-
Aah, a subquery is a nice workaround, thanks! |
Beta Was this translation helpful? Give feedback.
-
Note, however, that the counter reset semantics is probably different than what you expect. If a counter reset is detected, the PromQL engine assumes that the counter has started from zero again, as can be seen nicely in this test: prometheus/promql/testdata/functions.test Lines 86 to 94 in 5a4c373 This doesn't match the semantics of "top-up" behavior, even if the proposed Independent of the use case, I have been thinking lately about changing the semantics of PromQL (in a future release) so that operations that are only acting on single samples (unary negation, arithmetic with a scalar, comparison with a scalar, …) would return the timestamp unchanged rather than the timestamp of the evaluation (which is partially inspired by #8966 (comment), but also other thoughts about the fundamental structure of Prometheus sample values). Those "single sample" operations wouldn't need subqueries. (This would still not solve the original problem of #8966. For that, we needed new functions like |
Beta Was this translation helpful? Give feedback.
-
Proposal
Allow computing
rate()
,resets()
, andincrease()
for metrics that count down rather than up.One way to achieve this, would be to allow unary negation on range vectors. Currently
rate(-decreasing_metric[5m])
andrate(0 - decreasing_metric[5m])
cause a parse error, but if this were allowed, it would enable computing the rates of decreasing metrics. Note,-rate(decreasing_metric[5m])
is not at all the same thing!Negating a range vector would negate all of its values.
Use case. Why is this important?
I have an exporter that monitors the balance of an account. The balance is decreasing continuously, as a system is spending from the account. Periodically, the account gets topped up. I want to compute its spending rate, and only spending, regardless of when the account gets topped up. If I compute this using
delta
orderiv
, then if the account was topped up inside the time window selected for the range vector, then the spending rate is no longer accurate, and may even go negative.Beta Was this translation helpful? Give feedback.
All reactions