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