From 59bf3d442bb019f4da384468ebaebbca1825943e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=B2=20Harry=20=F0=9F=8C=8A=20John=20=F0=9F=8F=94?= Date: Tue, 17 Jun 2025 10:47:48 -0700 Subject: [PATCH] PromQL: Fix native histogram last_over_time with offset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 🌲 Harry 🌊 John 🏔 --- promql/functions.go | 2 +- promql/promqltest/testdata/native_histograms.test | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/promql/functions.go b/promql/functions.go index 7f35c9d5b2..7e3099ec60 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -747,7 +747,7 @@ func funcLastOverTime(vals []parser.Value, _ parser.Expressions, enh *EvalNodeHe h = el.Histograms[len(el.Histograms)-1] } - if h.H == nil || h.T < f.T { + if h.H == nil || (len(el.Floats) > 0 && h.T < f.T) { return append(enh.Out, Sample{ Metric: el.Metric, F: f.F, diff --git a/promql/promqltest/testdata/native_histograms.test b/promql/promqltest/testdata/native_histograms.test index edca4eec4b..dcf1547eda 100644 --- a/promql/promqltest/testdata/native_histograms.test +++ b/promql/promqltest/testdata/native_histograms.test @@ -1319,3 +1319,12 @@ eval instant at 10m histogram_sub_3{idx="0"} - ignoring(idx) histogram_sub_3{idx {} {{schema:0 count:-30 sum:-1111.1 z_bucket:-2 z_bucket_w:0.001 buckets:[-1 0 -1 -2 -1 -1 -1] n_buckets:[0 2 -2 -2 -7 0 0 0 0 -5 -5 -2]}} clear + +# Test native histograms with last_over_time subquery +load 2m + http_request_duration_seconds{pod="nginx-1"} {{schema:0 count:3 sum:14.00 buckets:[1 2]}}x20 + +eval range from 0s to 60s step 15s last_over_time({__name__="http_request_duration_seconds"} @ start()[1h:1m] offset 1m16s) + {__name__="http_request_duration_seconds", pod="nginx-1"} {{count:3 sum:14 buckets:[1 2]}}x4 + +clear