From 53ca37534555d5dd92d78763c049beb05365ed57 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 15 Dec 2021 14:33:44 +0100 Subject: [PATCH] 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 --- promql/engine.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/promql/engine.go b/promql/engine.go index acf59e15d..557416dbf 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -2321,7 +2321,12 @@ func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without case parser.SUM: if s.H != nil { group.hasHistogram = true - group.histogramValue.Add(s.H) + 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