diff --git a/promql/engine.go b/promql/engine.go index 64265060a..f3aa11c77 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -1012,7 +1012,7 @@ func scalarBinop(op itemType, lhs, rhs model.SampleValue) model.SampleValue { case itemPOW: return model.SampleValue(math.Pow(float64(lhs), float64(rhs))) case itemMOD: - if rhs != 0 { + if int(rhs) != 0 { return model.SampleValue(int(lhs) % int(rhs)) } return model.SampleValue(math.NaN()) @@ -1046,7 +1046,7 @@ func vectorElemBinop(op itemType, lhs, rhs model.SampleValue) (model.SampleValue case itemPOW: return model.SampleValue(math.Pow(float64(lhs), float64(rhs))), true case itemMOD: - if rhs != 0 { + if int(rhs) != 0 { return model.SampleValue(int(lhs) % int(rhs)), true } return model.SampleValue(math.NaN()), true diff --git a/promql/testdata/operators.test b/promql/testdata/operators.test index 2075e77d7..d9e96fa93 100644 --- a/promql/testdata/operators.test +++ b/promql/testdata/operators.test @@ -34,6 +34,10 @@ eval instant at 50m SUM(http_requests) BY (job) % 3 {job="api-server"} 1 {job="app-server"} 2 +eval instant at 50m SUM(http_requests) BY (job) % 0.3 + {job="api-server"} NaN + {job="app-server"} NaN + eval instant at 50m SUM(http_requests) BY (job) ^ 2 {job="api-server"} 1000000 {job="app-server"} 6760000 @@ -347,3 +351,13 @@ eval instant at 5m metricA + ignoring() metricB eval instant at 5m metricA + metricB {baz="meh"} 7 + +clear + +load 5m + finite{foo="bar"} 42 + almost_zero{foo="bar"} 0.123 + +# MOD by "almost zero" with vector. +eval instant at 5m finite % almost_zero + {foo="bar"} NaN \ No newline at end of file