diff --git a/promql/engine.go b/promql/engine.go index 2feb6c3c92..91257eae37 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -3891,20 +3891,34 @@ func detectHistogramStatsDecoding(expr parser.Expr) { return nil } + pathLoop: for i := len(path) - 1; i >= 0; i-- { // Walk backwards up the path. + if _, ok := path[i].(*parser.SubqueryExpr); ok { + // If we ever see a subquery in the path, we + // will not skip the buckets. We need the + // buckets for correct counter reset detection. + n.SkipHistogramBuckets = false + break pathLoop + } call, ok := path[i].(*parser.Call) if !ok { - continue + continue pathLoop } switch call.Func.Name { case "histogram_count", "histogram_sum", "histogram_avg": + // We allow skipping buckets preliminarily. But + // we will continue through the path to see if + // we find a subquery (or a histogram function) + // further up (the latter wouldn't make sense, + // but no harm in detecting it). n.SkipHistogramBuckets = true case "histogram_quantile", "histogram_fraction": + // If we ever see a function that needs the + // whole histogram, we will not skip the + // buckets. n.SkipHistogramBuckets = false - default: - continue + break pathLoop } - break } return errors.New("stop") })