mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix issue where avg
over mixed exponential and custom buckets, or incompatible custom buckets, produces incorrect results or panics
Signed-off-by: Charles Korn <charles.korn@grafana.com>
This commit is contained in:
parent
5ee94f49a2
commit
f07b3ae67b
|
@ -2868,10 +2868,14 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, q float64, inputMatrix
|
||||||
toAdd, err := left.Sub(right)
|
toAdd, err := left.Sub(right)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleAggregationError(err, e, inputMatrix[si].Metric.Get(model.MetricNameLabel), &annos)
|
handleAggregationError(err, e, inputMatrix[si].Metric.Get(model.MetricNameLabel), &annos)
|
||||||
|
group.abandonHistogram = true
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
_, err = group.histogramValue.Add(toAdd)
|
_, err = group.histogramValue.Add(toAdd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleAggregationError(err, e, inputMatrix[si].Metric.Get(model.MetricNameLabel), &annos)
|
handleAggregationError(err, e, inputMatrix[si].Metric.Get(model.MetricNameLabel), &annos)
|
||||||
|
group.abandonHistogram = true
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise the aggregation contained floats
|
// Otherwise the aggregation contained floats
|
||||||
|
@ -2968,6 +2972,8 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, q float64, inputMatrix
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
|
case aggr.abandonHistogram:
|
||||||
|
continue
|
||||||
case aggr.hasHistogram:
|
case aggr.hasHistogram:
|
||||||
aggr.histogramValue = aggr.histogramValue.Compact(0)
|
aggr.histogramValue = aggr.histogramValue.Compact(0)
|
||||||
case aggr.incrementalMean:
|
case aggr.incrementalMean:
|
||||||
|
|
|
@ -776,6 +776,9 @@ load 6m
|
||||||
eval_warn range from 0 to 12m step 6m sum(metric)
|
eval_warn range from 0 to 12m step 6m sum(metric)
|
||||||
{} {{sum:7 count:5 buckets:[2 3 2]}} {{schema:-53 sum:16 count:3 custom_values:[5 10] buckets:[1 2]}} _
|
{} {{sum:7 count:5 buckets:[2 3 2]}} {{schema:-53 sum:16 count:3 custom_values:[5 10] buckets:[1 2]}} _
|
||||||
|
|
||||||
|
eval_warn range from 0 to 12m step 6m avg(metric)
|
||||||
|
{} {{sum:3.5 count:2.5 buckets:[1 1.5 1]}} {{schema:-53 sum:8 count:1.5 custom_values:[5 10] buckets:[0.5 1]}} _
|
||||||
|
|
||||||
clear
|
clear
|
||||||
|
|
||||||
# Test incompatible custom bucket schemas.
|
# Test incompatible custom bucket schemas.
|
||||||
|
@ -789,3 +792,6 @@ load 6m
|
||||||
# T=12: incompatible followed by compatible, should be ignored and emit a warning
|
# T=12: incompatible followed by compatible, should be ignored and emit a warning
|
||||||
eval_warn range from 0 to 12m step 6m sum(metric)
|
eval_warn range from 0 to 12m step 6m sum(metric)
|
||||||
{} _ {{schema:-53 sum:2 count:2 custom_values:[5 10] buckets:[2]}} _
|
{} _ {{schema:-53 sum:2 count:2 custom_values:[5 10] buckets:[2]}} _
|
||||||
|
|
||||||
|
eval_warn range from 0 to 12m step 6m avg(metric)
|
||||||
|
{} _ {{schema:-53 sum:1 count:1 custom_values:[5 10] buckets:[1]}} _
|
||||||
|
|
Loading…
Reference in a new issue