From ccbce0c51f05751c7432a3a281fe98587ffa3a1c Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Fri, 30 Sep 2016 10:46:58 +0200 Subject: [PATCH] promql: handle NaN in changes() correctly --- promql/functions.go | 2 +- promql/testdata/functions.test | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/promql/functions.go b/promql/functions.go index 41ff6fe7b..607421470 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -788,7 +788,7 @@ func funcChanges(ev *evaluator, args Expressions) model.Value { prev := model.SampleValue(samples.Values[0].Value) for _, sample := range samples.Values[1:] { current := sample.Value - if current != prev { + if current != prev && !(math.IsNaN(float64(current)) && math.IsNaN(float64(prev))) { changes++ } prev = current diff --git a/promql/testdata/functions.test b/promql/testdata/functions.test index cfabb3c9b..a04933110 100644 --- a/promql/testdata/functions.test +++ b/promql/testdata/functions.test @@ -50,6 +50,15 @@ eval instant at 50m changes(http_requests[50m]) eval instant at 50m changes(nonexistent_metric[50m]) +clear + +load 5m + x{a="b"} NaN NaN NaN + x{a="c"} 0 NaN 0 + +eval instant at 15m changes(x[15m]) + {a="b"} 0 + {a="c"} 2 clear