From a577a0a542c01e863e6d53effd23457031b97e47 Mon Sep 17 00:00:00 2001 From: Filip Petkovski Date: Fri, 26 Jan 2024 10:04:02 +0100 Subject: [PATCH] Fix last_over_time for native histograms The last_over_time retains a histogram sample without making a copy. This sample is now coming from the buffered iterator used for windowing functions, and can be reused for reading subsequent samples as the iterator progresses. I would propose copying the sample in the last_over_time function, similar to how it is done for rate, sum_over_time and others. Signed-off-by: Filip Petkovski --- promql/functions.go | 2 +- promql/testdata/native_histograms.test | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/promql/functions.go b/promql/functions.go index aef73e7f2..a0a118c11 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -603,7 +603,7 @@ func funcLastOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNod } return append(enh.Out, Sample{ Metric: el.Metric, - H: h.H, + H: h.H.Copy(), }), nil } diff --git a/promql/testdata/native_histograms.test b/promql/testdata/native_histograms.test index b74886f73..5f0945d32 100644 --- a/promql/testdata/native_histograms.test +++ b/promql/testdata/native_histograms.test @@ -224,3 +224,14 @@ eval instant at 5m histogram_fraction(0, 4, balanced_histogram) # the first populated bucket after the span of empty buckets. eval instant at 5m histogram_quantile(0.5, balanced_histogram) {} 0.5 + +# Add histogram to test sum(last_over_time) regression +load 5m + incr_sum_histogram{number="1"} {{schema:0 sum:0 count:0 buckets:[1]}}+{{schema:0 sum:1 count:1 buckets:[1]}}x10 + incr_sum_histogram{number="2"} {{schema:0 sum:0 count:0 buckets:[1]}}+{{schema:0 sum:2 count:1 buckets:[1]}}x10 + +eval instant at 50m histogram_sum(sum(incr_sum_histogram)) + {} 30 + +eval instant at 50m histogram_sum(sum(last_over_time(incr_sum_histogram[5m]))) + {} 30