1
0
mirror of https://github.com/prometheus/prometheus synced 2025-03-22 03:06:45 +00:00

promql: return NaN from irate() if second-last sample is NaN ()

promql: return NaN from `irate()` if either of last two samples is NaN

Signed-off-by: Charles Korn <charles.korn@grafana.com>

---------

Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
Charles Korn 2025-03-14 01:06:17 +11:00 committed by GitHub
parent a4a4ef6a52
commit c88d0b0e0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions
promql
functions.go
promqltest/testdata

View File

@ -367,10 +367,11 @@ func instantValue(vals []parser.Value, args parser.Expressions, out Vector, isRa
}
switch {
case ss[1].H == nil && ss[0].H == nil:
if !isRate || ss[1].F >= ss[0].F {
// Gauge or counter without reset.
if !isRate || !(ss[1].F < ss[0].F) {
// Gauge, or counter without reset, or counter with NaN value.
resultSample.F = ss[1].F - ss[0].F
}
// In case of a counter reset, we leave resultSample at
// its current value, which is already ss[1].
case ss[1].H != nil && ss[0].H != nil:

View File

@ -218,6 +218,7 @@ clear
load 5m
http_requests_total{path="/foo"} 0+10x10
http_requests_total{path="/bar"} 0+10x5 0+10x5
http_requests_nan{} 1 NaN NaN 5 11
http_requests_histogram{path="/a"} {{sum:2 count:2}}+{{sum:3 count:3}}x5
http_requests_histogram{path="/b"} 0 0 {{sum:1 count:1}} {{sum:4 count:4}}
http_requests_histogram{path="/c"} 0 0 {{sum:1 count:1}} {{sum:4 count:4 counter_reset_hint:gauge}}
@ -235,6 +236,9 @@ eval instant at 30m irate(http_requests_total[50m])
{path="/foo"} .03333333333333333333
{path="/bar"} 0
eval range from 0 to 20m step 5m irate(http_requests_nan[15m1s])
{} _ NaN NaN NaN 0.02
eval instant at 20m irate(http_requests_histogram{path="/a"}[20m])
{path="/a"} {{sum:0.01 count:0.01 counter_reset_hint:gauge}}
@ -288,6 +292,7 @@ clear
load 5m
http_requests{path="/foo"} 0 50 100 150
http_requests{path="/bar"} 0 50 100 50
http_requests_nan{} 1 NaN NaN 5 11
http_requests_histogram{path="/a"} {{sum:2 count:2 counter_reset_hint:gauge}}+{{sum:1 count:3 counter_reset_hint:gauge}}x5
http_requests_histogram{path="/b"} 0 0 {{sum:1 count:1 counter_reset_hint:gauge}} {{sum:2 count:2 counter_reset_hint:gauge}}
http_requests_histogram{path="/c"} 0 0 {{sum:1 count:1}} {{sum:2 count:2 counter_reset_hint:gauge}}
@ -300,6 +305,9 @@ eval instant at 20m idelta(http_requests[20m])
{path="/foo"} 50
{path="/bar"} -50
eval range from 0 to 20m step 5m idelta(http_requests_nan[15m1s])
{} _ NaN NaN NaN 6
eval instant at 20m idelta(http_requests_histogram{path="/a"}[20m])
{path="/a"} {{sum:1 count:3 counter_reset_hint:gauge}}