From 91eab63d383d81c06a633efee78035ed7ed7e58a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 6 Jun 2025 14:52:59 +0100 Subject: [PATCH] [Refactor] PromQL: Simplify detectHistogramStatsDecoding Restarting the depth-first walk on each leg of a binary expression is convoluted. ISTM the correct logic is to walk the path backwards to the first relevant function. Signed-off-by: Bryan Boreham --- promql/engine.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/promql/engine.go b/promql/engine.go index 1e01f21db6..0d83bab8bd 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -3864,19 +3864,13 @@ 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 errors.New("stop") - } - n, ok := (node).(*parser.VectorSelector) if !ok { return nil } - for _, p := range path { - call, ok := p.(*parser.Call) + for i := len(path) - 1; i > 0; i-- { // Walk backwards up the path. + call, ok := path[i].(*parser.Call) if !ok { continue }