Merge pull request #2156 from prometheus/beorn7/promql

Fix MOD binop for scalars and vectors
This commit is contained in:
Björn Rabenstein 2016-11-03 19:54:57 +01:00 committed by GitHub
commit e072e7f903
2 changed files with 16 additions and 2 deletions

View file

@ -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

View file

@ -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