promql: Add a guard against a nil histogram in sum aggregation

This can happen if the aggregation starts with a float and later
encounters a histogram. In that case, the newly encountered histogram
would have been added to a nil histogram.

This should be tested, of course, but that's best done within the
PromQL testing framework, which we still need to enable for histograms
(for which we have a TODO in the code and now also a card in the GH
project).

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2021-12-15 14:33:44 +01:00
parent 6f33ab2b35
commit 53ca375345
1 changed files with 6 additions and 1 deletions

View File

@ -2321,7 +2321,12 @@ func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without
case parser.SUM:
if s.H != nil {
group.hasHistogram = true
if group.histogramValue != nil {
group.histogramValue.Add(s.H)
}
// Otherwise the aggregation contained floats
// previously and will be invalid anyway. No
// point in copying the histogram in that case.
} else {
group.hasFloat = true
group.value += s.V