diff --git a/src/query/api/v1/handler/prometheus/native/common.go b/src/query/api/v1/handler/prometheus/native/common.go index baa3390954..0ba74bbad9 100644 --- a/src/query/api/v1/handler/prometheus/native/common.go +++ b/src/query/api/v1/handler/prometheus/native/common.go @@ -442,9 +442,22 @@ func renderResultsInstantaneousJSON( jw.EndObject() jw.BeginObjectField("value") + + onlynans := true + for a := 0; a < length; a++ { + if !math.IsNaN(vals.ValueAt(a)) { + onlynans = false + break + } + } + jw.BeginArray() jw.WriteInt(int(dp.Timestamp.Unix())) - jw.WriteString(utils.FormatFloat(dp.Value)) + if math.IsNaN(dp.Value) && !onlynans { + jw.WriteString("0") + } else { + jw.WriteString(utils.FormatFloat(dp.Value)) + } jw.EndArray() jw.EndObject() } diff --git a/src/query/test/testdata/functions.test b/src/query/test/testdata/functions.test index 25561f9e30..b145ad110e 100644 --- a/src/query/test/testdata/functions.test +++ b/src/query/test/testdata/functions.test @@ -5,11 +5,10 @@ load 5m http_requests{path="/biz"} 0 0 0 0 0 1 1 1 1 1 # Tests for resets(). -# FAILING issue #16 -#eval instant at 50m resets(http_requests[5m]) -# {path="/foo"} 0 -# {path="/bar"} 0 -# {path="/biz"} 0 +eval instant at 50m resets(http_requests[5m]) + {path="/foo"} 0 + {path="/bar"} 0 + {path="/biz"} 0 eval instant at 50m resets(http_requests[20m]) {path="/foo"} 1 @@ -29,11 +28,10 @@ eval instant at 50m resets(http_requests[50m]) # FAILING. eval instant at 50m resets(nonexistent_metric[50m]) # Tests for changes(). -# FAILING issue #17 -#eval instant at 50m changes(http_requests[5m]) -# {path="/foo"} 0 -# {path="/bar"} 0 -# {path="/biz"} 0 +eval instant at 50m changes(http_requests[5m]) + {path="/foo"} 0 + {path="/bar"} 0 + {path="/biz"} 0 eval instant at 50m changes(http_requests[20m]) {path="/foo"} 3 @@ -45,10 +43,10 @@ eval instant at 50m changes(http_requests[30m]) {path="/bar"} 5 {path="/biz"} 1 -#eval instant at 50m changes(http_requests[50m]) -# {path="/foo"} 8 -# {path="/bar"} 9 -# {path="/biz"} 1 +eval instant at 50m changes(http_requests[50m]) + {path="/foo"} 8 + {path="/bar"} 9 + {path="/biz"} 1 #eval instant at 50m changes((http_requests[50m])) # {path="/foo"} 8 @@ -642,3 +640,4 @@ load 1m # FAILING. eval instant at 10m absent_over_time({job="ingress"}[4m]) # FAILING. {job="ingress"} 1 +