app/vmselect/promql: return nan from a >bool b if a is nan in the same way as Prometheus does

This commit is contained in:
Aliaksandr Valialkin 2020-12-02 00:28:16 +02:00
parent adf45b730c
commit 4ef7158e89
3 changed files with 29 additions and 2 deletions

View file

@ -62,6 +62,9 @@ func newBinaryOpCmpFunc(cf func(left, right float64) bool) binaryOpFunc {
if cf(left, right) {
return 1
}
if math.IsNaN(left) {
return nan
}
return 0
}
return newBinaryOpFunc(cfe)

View file

@ -1782,10 +1782,32 @@ func TestExecSuccess(t *testing.T) {
})
t.Run(`time() > scalar`, func(t *testing.T) {
t.Parallel()
q := `time() > 123`
q := `time() > 1234`
r := netstorage.Result{
MetricName: metricNameExpected,
Values: []float64{1000, 1200, 1400, 1600, 1800, 2000},
Values: []float64{nan, nan, 1400, 1600, 1800, 2000},
Timestamps: timestampsExpected,
}
resultExpected := []netstorage.Result{r}
f(q, resultExpected)
})
t.Run(`time() >bool scalar`, func(t *testing.T) {
t.Parallel()
q := `time() >bool 1234`
r := netstorage.Result{
MetricName: metricNameExpected,
Values: []float64{0, 0, 1, 1, 1, 1},
Timestamps: timestampsExpected,
}
resultExpected := []netstorage.Result{r}
f(q, resultExpected)
})
t.Run(`nan >bool scalar1`, func(t *testing.T) {
t.Parallel()
q := `(time() > 1234) >bool 1450`
r := netstorage.Result{
MetricName: metricNameExpected,
Values: []float64{nan, nan, 0, 1, 1, 1},
Timestamps: timestampsExpected,
}
resultExpected := []netstorage.Result{r}

View file

@ -4,6 +4,8 @@
* BUGFIX: properly parse timestamps in OpenMetrics format - they are exposed as floating-point number in seconds instead of integer milliseconds
unlike in Prometheus exposition format. See [the docs](https://github.com/OpenObservability/OpenMetrics/blob/master/specification/OpenMetrics.md#timestamps).
* BUGFIX: return `nan` for `a >bool b` query when `a` equals to `nan` like Prometheus does. Previously `0` was returned in this case. This applies to any comparison operation
with `bool` modifier. See [these docs](https://prometheus.io/docs/prometheus/latest/querying/operators/#comparison-binary-operators) for details.
# [v1.48.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.48.0)