diff --git a/src/query/src/promql/native_compile.rs b/src/query/src/promql/native_compile.rs index 1d5a0801e84..831f10eab6d 100644 --- a/src/query/src/promql/native_compile.rs +++ b/src/query/src/promql/native_compile.rs @@ -270,6 +270,13 @@ fn lookback_millis(lookback: u128) -> Result { /// range they name, so they are resolved against `stmt.start` and `stmt.end` here. The offset is not /// folded in: [`RangeWindow`] keeps anchor and offset apart and ends the window at /// `anchor_ms - offset_ms` at run time. +/// +/// An anchor decouples the window's read range from the statement's: it reads +/// `(anchor_ms - offset_ms - range_ms, anchor_ms - offset_ms]`, which for an anchor like `@ 1234` can +/// lie entirely outside `[stmt.start - range_ms, stmt.end]`. Whoever binds the scan therefore has to +/// derive its range from the window's anchor, offset and range rather than from `stmt.start` and +/// `stmt.end`; a scan bound to the statement alone leaves such a window with no samples, and the +/// query silently returns empty instead of failing. fn selector_anchor_ms(at: &Option, stmt: &EvalStmt) -> Result> { match at { None => Ok(None), diff --git a/src/query/src/promql/native_compile/tests.rs b/src/query/src/promql/native_compile/tests.rs index 59cac16f6df..1918ce3ec2e 100644 --- a/src/query/src/promql/native_compile/tests.rs +++ b/src/query/src/promql/native_compile/tests.rs @@ -269,6 +269,9 @@ fn an_anchor_on_a_window_resolves_to_absolute_milliseconds() { ("rate(x[5m] @ 1234)", 1_234_000), // A sub-second anchor resolves to the millisecond it names. ("rate(x[5m] @ 1.234)", 1_234), + // Prometheus allows a pre-epoch anchor: `signed_millis_since_epoch` takes `Err(earlier)`, + // where a `duration_since(UNIX_EPOCH).unwrap_or_default()` helper would silently give 0. + ("rate(x[5m] @ -1.5)", -1_500), // The statement here is UNIX_EPOCH..100s, which is what `start()` and `end()` mean. ("rate(x[5m] @ start())", 0), ("rate(x[5m] @ end())", 100_000), @@ -309,11 +312,6 @@ fn end_resolves_to_the_statement_end_not_the_last_grid_point() { last_point, 100_000, "the test's own grid does not stop before the statement end" ); - assert_ne!( - op.window.anchor_ms, - Some(last_point), - "`@ end()` bound the last grid point rather than the statement's end" - ); } /// An anchor and an offset are bound apart: the window ends at `anchor - offset`, which the