Repository navigation
storage: stop histogram conversion on query cancellation - #20288
Conversation
rbizos
left a comment
There was a problem hiding this comment.
Cancellation is only checked between samples in convertSeries, but this call can process and emit every bucket of a single NHCB before returning. Should cancellation be checked within the bucket conversion loop as well ? Maybe this is enough though
| func TestNativeHistogramsAsClassicQuerier_Cancellation(t *testing.T) { | ||
| const numSamples = 64 | ||
| h := makeNHCB([]float64{1, 2}, []int64{1, 2, 1}) | ||
| for _, floatHistogram := range []bool{false, true} { |
There was a problem hiding this comment.
The nested loops create a Cartesian product of histogram type, selector, and cancellation point, making it hard to tell which combinations are essential. Could these be expressed as a smaller table of named cancellation scenarios, with NHCB and float-NHCB coverage handled as two clear subtests? Keep separate cases only where a selector exercises distinct cancellation behavior.
There was a problem hiding this comment.
Yes, the full Cartesian product is unnecessary: the sample-boundary check is shared by bucket, count and sum conversion. Rejected buckets need a separate scenario because they produce no output, while the other selectors can share the cancellation-boundary scenarios. The current test still uses the nested matrix.
There was a problem hiding this comment.
Replaced the Cartesian product with named cancellation scenarios under separate NHCB and float-NHCB subtests. Rejected buckets retain their own scenario because they produce no output; count and sum use existing boundary scenarios rather than repeating every cancellation point.
| return nil | ||
| } | ||
| series := s.builder.buildSeries(dst, s.leMatchers) | ||
| if err := s.ctx.Err(); err != nil { |
There was a problem hiding this comment.
s.ctx.Err() is already checked right before s.builder.buildSeries on line 501, and buildSeries only copies in-memory slices, so this second check after buildSeries can be dropped.
There was a problem hiding this comment.
Agreed. The pre-build cancellation check is sufficient for this cooperative boundary: buildSeries copies the in-memory histories and does not advance the source iterator.
There was a problem hiding this comment.
Dropped the post-build check. The cancellation check immediately before buildSeries remains, as do the checks between samples and when advancing the series set.
7fa1f84 to
6acc6fe
Compare
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
6acc6fe to
a89b156
Compare
saswatamcode
left a comment
There was a problem hiding this comment.
Thanks, this makes sense!
Which issue(s) does the PR fix:
Follow-up to #18048. Carry the query context into NHCB-to-classic conversion and check it between samples, before materializing output, and when advancing the converted series set. This stops a cancelled query from draining the remaining history, even when
lematchers reject every bucket.Cancellation is cooperative: an in-progress iterator operation, individual histogram conversion or materialization must still finish. This applies with
promql-native-histograms-as-classicenabled.The cancellation tests use named scenarios under separate NHCB and float-NHCB subtests rather than a selector-by-cancellation-point matrix. They cover cancellation before iteration, during conversion, before materialization, and between output series, plus rejected bucket matchers. The PromQL integration test covers cancellation and query timeouts with local TSDB primary and secondary storage. An iterator-error control checks that storage errors still propagate.
Go tests for NHCB-to-classic conversion in storage and its PromQL integration passed with race detection. Uncancelled timing overhead remains inconclusive in local paired measurements; no timing-preservation guarantee is claimed.
Related work: #19881, #19886 and #20277 also change this conversion path; this change addresses cancellation within a single history.
Release notes for end users (ALL commits must be considered).
Case and evidence
Made by Perfloop. To ask for a change, comment or review in plain words. How Perfloop handles pull requests.