From d164790946a4b3a557c1bc1204ca6b4f8b78e57c Mon Sep 17 00:00:00 2001 From: ZverGuy Date: Thu, 5 Nov 2026 06:16:31 +0700 Subject: [PATCH] test(observability-proxy): pin the subquery lookahead exactly The subquery sizing was tested only as "at least two hours", so which step drives it, the fallback to the query step for an empty subquery step, and its refusals (an unreadable step, an unclosed bracket, a sum past the duration range) were not held by any test. Assisted-by: LLM Signed-off-by: ZverGuy --- .../observabilityproxy/metricsparams_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/observabilityproxy/metricsparams_test.go b/internal/observabilityproxy/metricsparams_test.go index 15067ed6c..75b88d7f3 100644 --- a/internal/observabilityproxy/metricsparams_test.go +++ b/internal/observabilityproxy/metricsparams_test.go @@ -480,6 +480,12 @@ func TestQueryLookahead(t *testing.T) { `x offset 5m-.5h`, `x offset 1h-1`, `x offset 5m-y`, + // A subquery step the scan cannot read, an unclosed bracket, and a + // sum past the duration range. + `rate(x[1h:5i])`, + `rate(x[1h:$__interval])`, + `rate(x[1h`, + `max_over_time(x[1h:100y])`, `rate(x[5m] offset 1h-30m)`, // vmselect evaluates rollup_candlestick one step ahead // (evalRollupFuncWithoutAt), whatever the offset. @@ -501,7 +507,16 @@ func TestQueryLookahead(t *testing.T) { // values back onto earlier points, so a series that starts after the // evaluation time can reach the answer. func TestQueryLookaheadSubquery(t *testing.T) { - + // One explicit subquery and one "(": two levels of two steps, at the + // subquery's step, or at the query's step when the subquery has none. + for q, want := range map[string]time.Duration{ + `max_over_time(x[1h:1h])`: 4 * time.Hour, + `max_over_time(x[1h:])`: 4 * time.Minute, + } { + if got, ok := queryLookahead(q, time.Minute); !ok || got != want { + t.Errorf("queryLookahead(%q) = %s, %v; want %s", q, got, ok, want) + } + } for _, q := range []string{`max_over_time(range_last(x)[1h:1h])`, `max_over_time(keep_next_value(x)[1h:1h])`} { got, ok := queryLookahead(q, time.Minute) if !ok || got < 2*time.Hour {