promql: fix issues with comparison binary operations with bool modifier and native histograms (#15413)
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (0) (push) Waiting to run
CI / Build Prometheus for common architectures (1) (push) Waiting to run
CI / Build Prometheus for common architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (0) (push) Waiting to run
CI / Build Prometheus for all architectures (1) (push) Waiting to run
CI / Build Prometheus for all architectures (10) (push) Waiting to run
CI / Build Prometheus for all architectures (11) (push) Waiting to run
CI / Build Prometheus for all architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (3) (push) Waiting to run
CI / Build Prometheus for all architectures (4) (push) Waiting to run
CI / Build Prometheus for all architectures (5) (push) Waiting to run
CI / Build Prometheus for all architectures (6) (push) Waiting to run
CI / Build Prometheus for all architectures (7) (push) Waiting to run
CI / Build Prometheus for all architectures (8) (push) Waiting to run
CI / Build Prometheus for all architectures (9) (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run

* Fix issue where comparison operations with `bool` modifier and native histograms return histograms rather than 0 or 1

* Don't emit anything for comparisons between floats and histograms when `bool` modifier is used

* Don't emit anything for comparisons between floats and histograms when `bool` modifier is used between a vector and a scalar

---------

Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
Charles Korn 2024-11-19 19:13:34 +11:00 committed by GitHub
parent 45db23617a
commit 62e6e55c07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 302 additions and 0 deletions

View file

@ -2607,9 +2607,11 @@ func (ev *evaluator) VectorBinop(op parser.ItemType, lhs, rhs Vector, matching *
floatValue, histogramValue, keep, err := vectorElemBinop(op, fl, fr, hl, hr, pos)
if err != nil {
lastErr = err
continue
}
switch {
case returnBool:
histogramValue = nil
if keep {
floatValue = 1.0
} else {
@ -2728,6 +2730,7 @@ func (ev *evaluator) VectorscalarBinop(op parser.ItemType, lhs Vector, rhs Scala
float, histogram, keep, err := vectorElemBinop(op, lf, rf, lh, rh, pos)
if err != nil {
lastErr = err
continue
}
// Catch cases where the scalar is the LHS in a scalar-vector comparison operation.
// We want to always keep the vector element value as the output value, even if it's on the RHS.

View file

@ -508,3 +508,302 @@ eval instant at 1m 10 atan2 20
eval instant at 1m 10 atan2 NaN
NaN
clear
# Test comparison operations with floats and histograms.
load 6m
left_floats 1 2 _ _ 3 stale 4 5 NaN Inf -Inf
right_floats 4 _ _ 5 3 7 -1 20 NaN Inf -Inf
left_histograms {{schema:3 sum:4 count:4 buckets:[1 2 1]}} {{schema:3 sum:4.5 count:5 buckets:[1 3 1]}} _ _ {{schema:3 sum:4.5 count:5 buckets:[1 3 1]}}
right_histograms {{schema:3 sum:4 count:4 buckets:[1 2 1]}} {{schema:3 sum:4 count:4 buckets:[1 2 1]}} {{schema:3 sum:4 count:4 buckets:[1 2 1]}} _ _
right_floats_for_histograms 0 -1 2 3 4
eval range from 0 to 60m step 6m left_floats == right_floats
left_floats _ _ _ _ 3 _ _ _ _ Inf -Inf
eval range from 0 to 60m step 6m left_floats == bool right_floats
{} 0 _ _ _ 1 _ 0 0 0 1 1
eval range from 0 to 60m step 6m left_floats == does_not_match
# No results.
eval range from 0 to 24m step 6m left_histograms == right_histograms
left_histograms {{schema:3 sum:4 count:4 buckets:[1 2 1]}} _ _ _ _
eval range from 0 to 24m step 6m left_histograms == bool right_histograms
{} 1 0 _ _ _
eval_info range from 0 to 24m step 6m left_histograms == right_floats_for_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms == bool right_floats_for_histograms
# No results.
eval range from 0 to 60m step 6m left_floats != right_floats
left_floats 1 _ _ _ _ _ 4 5 NaN _ _
eval range from 0 to 60m step 6m left_floats != bool right_floats
{} 1 _ _ _ 0 _ 1 1 1 0 0
eval range from 0 to 24m step 6m left_histograms != right_histograms
left_histograms _ {{schema:3 sum:4.5 count:5 buckets:[1 3 1]}} _ _ _
eval range from 0 to 24m step 6m left_histograms != bool right_histograms
{} 0 1 _ _ _
eval_info range from 0 to 24m step 6m left_histograms != right_floats_for_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms != bool right_floats_for_histograms
# No results.
eval range from 0 to 60m step 6m left_floats > right_floats
left_floats _ _ _ _ _ _ 4 _ _ _ _
eval range from 0 to 60m step 6m left_floats > bool right_floats
{} 0 _ _ _ 0 _ 1 0 0 0 0
eval_info range from 0 to 24m step 6m left_histograms > right_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms > bool right_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms > right_floats_for_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms > bool right_floats_for_histograms
# No results.
eval range from 0 to 60m step 6m left_floats >= right_floats
left_floats _ _ _ _ 3 _ 4 _ _ Inf -Inf
eval range from 0 to 60m step 6m left_floats >= bool right_floats
{} 0 _ _ _ 1 _ 1 0 0 1 1
eval_info range from 0 to 24m step 6m left_histograms >= right_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms >= bool right_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms >= right_floats_for_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms >= bool right_floats_for_histograms
# No results.
eval range from 0 to 60m step 6m left_floats < right_floats
left_floats 1 _ _ _ _ _ _ 5 _ _ _
eval range from 0 to 60m step 6m left_floats < bool right_floats
{} 1 _ _ _ 0 _ 0 1 0 0 0
eval_info range from 0 to 24m step 6m left_histograms < right_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms < bool right_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms < right_floats_for_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms < bool right_floats_for_histograms
# No results.
eval range from 0 to 60m step 6m left_floats <= right_floats
left_floats 1 _ _ _ 3 _ _ 5 _ Inf -Inf
eval range from 0 to 60m step 6m left_floats <= bool right_floats
{} 1 _ _ _ 1 _ 0 1 0 1 1
eval_info range from 0 to 24m step 6m left_histograms <= right_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms <= bool right_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms <= right_floats_for_histograms
# No results.
eval_info range from 0 to 24m step 6m left_histograms <= bool right_floats_for_histograms
# No results.
# Vector / scalar combinations with scalar on right side
eval range from 0 to 60m step 6m left_floats == 3
left_floats _ _ _ _ 3 _ _ _ _ _ _
eval range from 0 to 60m step 6m left_floats != 3
left_floats 1 2 _ _ _ _ 4 5 NaN Inf -Inf
eval range from 0 to 60m step 6m left_floats > 3
left_floats _ _ _ _ _ _ 4 5 _ Inf _
eval range from 0 to 60m step 6m left_floats >= 3
left_floats _ _ _ _ 3 _ 4 5 _ Inf _
eval range from 0 to 60m step 6m left_floats < 3
left_floats 1 2 _ _ _ _ _ _ _ _ -Inf
eval range from 0 to 60m step 6m left_floats <= 3
left_floats 1 2 _ _ 3 _ _ _ _ _ -Inf
eval range from 0 to 60m step 6m left_floats == bool 3
{} 0 0 _ _ 1 _ 0 0 0 0 0
eval range from 0 to 60m step 6m left_floats == Inf
left_floats _ _ _ _ _ _ _ _ _ Inf _
eval range from 0 to 60m step 6m left_floats == bool Inf
{} 0 0 _ _ 0 _ 0 0 0 1 0
eval range from 0 to 60m step 6m left_floats == NaN
# No results.
eval range from 0 to 60m step 6m left_floats == bool NaN
{} 0 0 _ _ 0 _ 0 0 0 0 0
eval_info range from 0 to 24m step 6m left_histograms == 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms == 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms != 3
# No results.
eval range from 0 to 24m step 6m left_histograms != 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms > 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms > 0
# No results.
eval range from 0 to 24m step 6m left_histograms >= 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms >= 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms < 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms < 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms <= 3
# No results.
eval range from 0 to 24m step 6m left_histograms <= 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms == bool 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms == bool 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms != bool 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms != bool 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms > bool 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms > bool 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms >= bool 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms >= bool 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms < bool 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms < bool 0
# No results.
eval_info range from 0 to 24m step 6m left_histograms <= bool 3
# No results.
eval_info range from 0 to 24m step 6m left_histograms <= bool 0
# No results.
# Vector / scalar combinations with scalar on left side
eval range from 0 to 60m step 6m 3 == left_floats
left_floats _ _ _ _ 3 _ _ _ _ _ _
eval range from 0 to 60m step 6m 3 != left_floats
left_floats 1 2 _ _ _ _ 4 5 NaN Inf -Inf
eval range from 0 to 60m step 6m 3 < left_floats
left_floats _ _ _ _ _ _ 4 5 _ Inf _
eval range from 0 to 60m step 6m 3 <= left_floats
left_floats _ _ _ _ 3 _ 4 5 _ Inf _
eval range from 0 to 60m step 6m 3 > left_floats
left_floats 1 2 _ _ _ _ _ _ _ _ -Inf
eval range from 0 to 60m step 6m 3 >= left_floats
left_floats 1 2 _ _ 3 _ _ _ _ _ -Inf
eval range from 0 to 60m step 6m 3 == bool left_floats
{} 0 0 _ _ 1 _ 0 0 0 0 0
eval range from 0 to 60m step 6m Inf == left_floats
left_floats _ _ _ _ _ _ _ _ _ Inf _
eval range from 0 to 60m step 6m Inf == bool left_floats
{} 0 0 _ _ 0 _ 0 0 0 1 0
eval range from 0 to 60m step 6m NaN == left_floats
# No results.
eval range from 0 to 60m step 6m NaN == bool left_floats
{} 0 0 _ _ 0 _ 0 0 0 0 0
eval range from 0 to 24m step 6m 3 == left_histograms
# No results.
eval range from 0 to 24m step 6m 0 == left_histograms
# No results.
eval range from 0 to 24m step 6m 3 != left_histograms
# No results.
eval range from 0 to 24m step 6m 0 != left_histograms
# No results.
eval range from 0 to 24m step 6m 3 < left_histograms
# No results.
eval range from 0 to 24m step 6m 0 < left_histograms
# No results.
eval range from 0 to 24m step 6m 3 < left_histograms
# No results.
eval range from 0 to 24m step 6m 0 < left_histograms
# No results.
eval range from 0 to 24m step 6m 3 > left_histograms
# No results.
eval range from 0 to 24m step 6m 0 > left_histograms
# No results.
eval range from 0 to 24m step 6m 3 >= left_histograms
# No results.
eval range from 0 to 24m step 6m 0 >= left_histograms
# No results.
clear