Skip to content

storage: add __opt_classic_from selector control and __stored_as__ debug label - #19905

Draft
bwplotka wants to merge 29 commits into
bwplotka/pr-18048-resolve-collisionsfrom
bwplotka/pr-18048-nhe-label-control
Draft

bwplotka wants to merge 29 commits into
bwplotka/pr-18048-resolve-collisionsfrom
bwplotka/pr-18048-nhe-label-control

Conversation

@bwplotka

@bwplotka bwplotka commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Stacked on top of:

Add per-selector control over NHCB-to-classic histogram conversion via the reserved __opt_classic_from matcher and optional __stored_as__ provenance output label:

  • __opt_classic_from="nhcb" (or !="none", default when --enable-feature=promql-nhcb-as-classic is set) converts NHCB histograms to classic series.
  • __opt_classic_from="none" (or ="", !="nhcb", !~"nhcb") disables conversion and returns stored classic series only.
  • __opt_classic_from="debug" (or =~"nhcb|debug") enables conversion and attaches __stored_as__="classic" or __stored_as__="nhcb" to returned series without merging or shadowing.
  • Any __opt_* matcher is stripped unconditionally on the PromQL engine path (Select and absent() / absent_over_time()) even when --enable-feature=promql-nhcb-as-classic is disabled, so rolling back the feature flag does not break queries containing __opt_classic_from.
NONE

rbizos and others added 18 commits September 18, 2026 12:14
this allows to query nhcb with _buckets, _sum or _count suffix and get
classic histograms

Signed-off-by: Raphael Bizos <[email protected]>
Signed-off-by: r.bizos <[email protected]>
Signed-off-by: Raphael Bizos <[email protected]>
This allows to preserve ordering and thus having sorted output

Signed-off-by: Raphael Bizos <[email protected]>
fixing lint as well

Signed-off-by: Raphael Bizos <[email protected]>
fixing typo on feature flag name

Co-authored-by: Bartlomiej Plotka <[email protected]>
Signed-off-by: rbizos <[email protected]>
Performance improvements
- added a cache to not create the labels per samble but rather per
serie
- use hash rather than label.String in the converter
- only convert _sum/_buckets/_count when needed (this significantly
improved the  _count/sum as buckets are the most expensive and were
built each time)

Signed-off-by: Raphael Bizos <[email protected]>
the typo was fixed on the code but not in the docs

Signed-off-by: Raphael Bizos <[email protected]>
Signed-off-by: Raphael Bizos <[email protected]>
- Stream classicSet and nhcbSet one NHCB series at a time in NHCBAsClassicQuerier instead of buffering all classic and converted NHCB series up front.
- Reuse ClassicSeriesCache formatted le strings, metric names, and positiveBuckets scratch buffer across series of the same metric while invalidating cached label sets when the full label set changes.
- Reuse per-bucket sample scratch slices in classicSeriesBuilder and pack converted fSampleSeries and fSample slices into two contiguous slabs per NHCB series.

Signed-off-by: Bartek Plotka <[email protected]>
perf(storage): stream NHCB to classic conversion and reduce allocations
@bwplotka
bwplotka force-pushed the bwplotka/pr-18048-nhe-label-control branch 3 times, most recently from c64f303 to bdab911 Compare October 3, 2026 21:01
rbizos and others added 8 commits October 4, 2026 12:08
promql: apply NHCB-as-classic conversion in the engine instead of a fanout leg
…icQuerier

Group stored classic and converted NHCB series by histogram identity (labels excluding __name__ and le) when both representations exist, while keeping pure NHCB SeriesSets streaming lazily one NHCB series at a time:
- Stored classic samples take precedence at matching timestamps, shadowing converted NHCB buckets across the group even when bucket layouts or le formatting differ.
- Disjoint time ranges across a migration cutover merge into a single continuous series, with staleness markers handled per representation.
- NHCB staleness markers, dropped custom buckets, and classic takeover timestamps emit StaleNaN on active converted series.
- Series are sorted by labels.Compare (per group when sortSeries=false, globally when sortSeries=true).

Signed-off-by: Bartek Plotka <[email protected]>
…llisions in NHCBAsClassicQuerier

- Ignore stored _bucket series without an le label when collecting classic bucket timestamps so a gauge/counter ending in _bucket does not shadow converted NHCB buckets.
- Lazily collect classic timestamps using a dedicated classicIt iterator only when an actual NHCB sample is encountered, avoiding unnecessary chunk scans when a float counter or exponential native histogram shares the base metric name.
- Mark active converted NHCB series stale if the base series transitions to a float sample (ValFloat).

Signed-off-by: Bartek Plotka <[email protected]>
@bwplotka
bwplotka force-pushed the bwplotka/pr-18048-nhe-label-control branch from bdab911 to b1142e1 Compare October 4, 2026 12:13
@bwplotka
bwplotka force-pushed the bwplotka/pr-18048-nhe-label-control branch 2 times, most recently from 75db62a to 8fd6547 Compare October 6, 2026 05:24
@bwplotka
bwplotka changed the base branch from bwplotka/pr-18048-nhe-as-classic to bwplotka/pr-18048-resolve-collisions October 6, 2026 05:24
…bug label

Allow overriding --enable-feature=promql-nhcb-as-classic per selector via the __opt_classic_from control label ('nhcb', 'none', 'debug') and expose the underlying storage encoding via __stored_as__ ('classic', 'nhcb') when debug is matched.

Unconditionally strip all __opt_* matchers on the PromQL engine path (Select and absent()/absent_over_time()) even when --enable-feature=promql-nhcb-as-classic is disabled so queries containing __opt_classic_from remain rollback-safe.

Signed-off-by: Bartek Plotka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants