mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-07 14:47:11 +02:00
[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 <bjboreham@gmail.com>
This commit is contained in:
parent
8d0a747237
commit
91eab63d38
@ -3864,19 +3864,13 @@ func setOffsetForAtModifier(evalTime int64, expr parser.Expr) {
|
|||||||
// required for correctness.
|
// required for correctness.
|
||||||
func detectHistogramStatsDecoding(expr parser.Expr) {
|
func detectHistogramStatsDecoding(expr parser.Expr) {
|
||||||
parser.Inspect(expr, func(node parser.Node, path []parser.Node) error {
|
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)
|
n, ok := (node).(*parser.VectorSelector)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range path {
|
for i := len(path) - 1; i > 0; i-- { // Walk backwards up the path.
|
||||||
call, ok := p.(*parser.Call)
|
call, ok := path[i].(*parser.Call)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user