From acb6c1ae4b3c5524358d1066e89d40584b578db7 Mon Sep 17 00:00:00 2001 From: Filip Petkovski Date: Wed, 10 Jul 2024 11:55:26 +0200 Subject: [PATCH] Fix decoding buckets for native histograms in binops The optimizer which detects cases where histogram buckets can be skipped does not take into account binary expressions. This can lead to buckets not being decoded if a metric is used with both histogram_fraction/quantile and histogram_sum/count in the same expression. Signed-off-by: Filip Petkovski --- promql/engine.go | 6 ++++++ promql/promqltest/testdata/native_histograms.test | 3 +++ 2 files changed, 9 insertions(+) diff --git a/promql/engine.go b/promql/engine.go index bf19aac8b..25e67db63 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -3450,6 +3450,12 @@ func setOffsetForAtModifier(evalTime int64, expr parser.Expr) { // required for correctness. func detectHistogramStatsDecoding(expr parser.Expr) { parser.Inspect(expr, func(node parser.Node, path []parser.Node) error { + if n, ok := node.(*parser.BinaryExpr); ok { + detectHistogramStatsDecoding(n.LHS) + detectHistogramStatsDecoding(n.RHS) + return fmt.Errorf("stop") + } + n, ok := (node).(*parser.VectorSelector) if !ok { return nil diff --git a/promql/promqltest/testdata/native_histograms.test b/promql/promqltest/testdata/native_histograms.test index 1495a9e1d..6a8189a54 100644 --- a/promql/promqltest/testdata/native_histograms.test +++ b/promql/promqltest/testdata/native_histograms.test @@ -715,6 +715,9 @@ eval instant at 10m histogram_fraction(NaN, NaN, histogram_fraction_4) eval instant at 10m histogram_fraction(-Inf, +Inf, histogram_fraction_4) {} 1 +eval instant at 10m histogram_sum(scalar(histogram_fraction(-Inf, +Inf, sum(histogram_fraction_4))) * histogram_fraction_4) + {} 100 + clear # Counter reset only noticeable in a single bucket.