fix(promql): hand out no chunk when a push completes no position

`evaluate` opens the builder's span at the first position it has not handed out
yet, even when the push settled nothing. `emit` then called `cover_from` and
`cover_through` for the decided range, and `finish` built a zero-length series
instead of returning `None`, so a consumer received a chunk whose span claimed
progress the push had not made. With a grid of 10/20/30ms and a 10ms window, a
first chunk holding only `(5ms, 1.0)` reported a zero-length chunk while the
first grid point was still undecided.

Return `None` when the decided range is empty and this is not the last chunk. The
closing chunk is still handed out, empty when nothing is left to report, because
`is_last` is what ends a series.

`a_push_that_completes_nothing_hands_out_no_chunk` pins that single push, and
then checks the closing push still reports every position of the grid.

Signed-off-by: discord9 <discord9@users.noreply.github.com>
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
discord9
2026-10-19 15:34:24 +08:00
parent e7f3310828
commit efc8d07aa9
2 changed files with 37 additions and 0 deletions
+6
View File
@@ -580,6 +580,12 @@ impl RangeEvaluator {
return Ok(None);
};
let (start, end) = (state.emitted_end, state.completed);
// `evaluate` opens the builder's span at the first not-yet-handed-out position even when
// this push completed nothing, so finishing here would produce a zero-length chunk that
// claims progress the push did not make. Only the last chunk is handed out regardless.
if end == start && !is_last {
return Ok(None);
}
let mut metric = state.metric.clone();
if self.drops_metric_name {
metric.remove_all(&METADATA_LABELS);
+31
View File
@@ -799,6 +799,37 @@ fn empty_input_and_series_without_results() {
evaluator.finish().unwrap();
}
/// A push that completes nothing must not hand out a chunk.
///
/// `evaluate` opens the builder's span at the first position it has not handed out yet, even when
/// this push settled no position, so finishing unconditionally yields a zero-length series rather
/// than none. Handing that out would report progress the push did not make.
#[test]
fn a_push_that_completes_nothing_hands_out_no_chunk() {
let window = RangeWindow {
range_ms: 10,
offset_ms: 0,
anchor_ms: None,
};
let mut evaluator = probe_evaluator(1, grid(10, 10, 3), window);
// The only sample sits inside the first window, so the first point cannot be settled yet: no
// position is completed and the push has nothing to report.
let partial = chunk(&[(5, vec![Some(1.0)])], 1, 0, false);
assert!(
evaluator.push(&partial).unwrap().is_none(),
"a push that completed no position must not hand out a chunk"
);
// The closing push still hands one out, and it reports every position of the grid.
let closed = evaluator
.push(&chunk(&[(100, vec![Some(2.0)])], 1, 0, true))
.unwrap()
.expect("a series closes");
assert!(closed.is_last);
assert_eq!((closed.range().start(), closed.range().len()), (0, 3));
evaluator.finish().unwrap();
}
/// A series whose last sample is behind the end of the grid still closes, on a chunk holding no
/// positions: the remaining points have no values, and only the closing chunk tells the consumer
/// that the series is over rather than still waiting for input.