mirror of
https://github.com/prometheus/prometheus
synced 2024-12-27 09:02:53 +00:00
Fix special value handling in division and modulo.
This fixes https://github.com/prometheus/prometheus/issues/597
This commit is contained in:
parent
6b0ef506f3
commit
b2651027fc
@ -637,15 +637,12 @@ func evalScalarBinop(opType BinOpType,
|
||||
case Mul:
|
||||
return lhs * rhs
|
||||
case Div:
|
||||
if rhs != 0 {
|
||||
return lhs / rhs
|
||||
}
|
||||
return clientmodel.SampleValue(math.Inf(int(rhs)))
|
||||
return lhs / rhs
|
||||
case Mod:
|
||||
if rhs != 0 {
|
||||
return clientmodel.SampleValue(int(lhs) % int(rhs))
|
||||
}
|
||||
return clientmodel.SampleValue(math.Inf(int(rhs)))
|
||||
return clientmodel.SampleValue(math.NaN())
|
||||
case EQ:
|
||||
if lhs == rhs {
|
||||
return 1
|
||||
@ -691,15 +688,12 @@ func evalVectorBinop(opType BinOpType,
|
||||
case Mul:
|
||||
return lhs * rhs, true
|
||||
case Div:
|
||||
if rhs != 0 {
|
||||
return lhs / rhs, true
|
||||
}
|
||||
return clientmodel.SampleValue(math.Inf(int(rhs))), true
|
||||
return lhs / rhs, true
|
||||
case Mod:
|
||||
if rhs != 0 {
|
||||
return clientmodel.SampleValue(int(lhs) % int(rhs)), true
|
||||
}
|
||||
return clientmodel.SampleValue(math.Inf(int(rhs))), true
|
||||
return clientmodel.SampleValue(math.NaN()), true
|
||||
case EQ:
|
||||
if lhs == rhs {
|
||||
return lhs, true
|
||||
|
@ -1157,6 +1157,46 @@ func TestExpressions(t *testing.T) {
|
||||
expr: `999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`,
|
||||
output: []string{`scalar: +Inf @[%v]`},
|
||||
},
|
||||
{
|
||||
expr: `1 / 0`,
|
||||
output: []string{`scalar: +Inf @[%v]`},
|
||||
},
|
||||
{
|
||||
expr: `-1 / 0`,
|
||||
output: []string{`scalar: -Inf @[%v]`},
|
||||
},
|
||||
{
|
||||
expr: `0 / 0`,
|
||||
output: []string{`scalar: NaN @[%v]`},
|
||||
},
|
||||
{
|
||||
expr: `1 % 0`,
|
||||
output: []string{`scalar: NaN @[%v]`},
|
||||
},
|
||||
{
|
||||
expr: `http_requests{group="canary", instance="0", job="api-server"} / 0`,
|
||||
output: []string{
|
||||
`{group="canary", instance="0", job="api-server"} => +Inf @[%v]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
expr: `-1 * http_requests{group="canary", instance="0", job="api-server"} / 0`,
|
||||
output: []string{
|
||||
`{group="canary", instance="0", job="api-server"} => -Inf @[%v]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
expr: `0 * http_requests{group="canary", instance="0", job="api-server"} / 0`,
|
||||
output: []string{
|
||||
`{group="canary", instance="0", job="api-server"} => NaN @[%v]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
expr: `0 * http_requests{group="canary", instance="0", job="api-server"} % 0`,
|
||||
output: []string{
|
||||
`{group="canary", instance="0", job="api-server"} => NaN @[%v]`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
storage, closer := newTestStorage(t)
|
||||
|
Loading…
Reference in New Issue
Block a user