Skip to content

promql[nhcb]: nhcb as classic histogram feature flag - #18048

Merged
bwplotka merged 45 commits into
prometheus:mainfrom
rbizos:feature/native_histograms_compat_layer
Oct 27, 2026
Merged

bwplotka merged 45 commits into
prometheus:mainfrom
rbizos:feature/native_histograms_compat_layer

Conversation

@rbizos

@rbizos rbizos commented Feb 9, 2026 •

Copy link
Copy Markdown
Contributor

this allows to query nhcb with _buckets, _sum or _count suffix and get classic histograms

Which issue(s) does the PR fix:

#16948

Does this PR introduce a user-facing change?

[FEATURE] NHCB: query NHCB as classic histograms with promq-nhcb-as-classic feature flag

What does this PR introduces

This PR adds a feature flag promq-nhcb-as-classic that will allow to query NHCH as directly with the different prefixes (_bucket, _sum, _count)

Example

The following example is running with the following command

./prometheus --config.file prometheus.yml --enable-feature=promq-nhcb-as-classic

And a global config like such:

global:
  convert_classic_histograms_to_nhcb: true

We can query normally a NHCB:
image

We can then query it as a classic histogram by adding the _bucket prefix (or any of the 2 other prefix)

image

@beorn7

beorn7 commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Note: I really need to get through my old review backlog. I don't think I'm urgently required on this one. I'll queue it for review, but it will take time to get to it. Please don't wait for me. (And if you think you really depend on me here, let me know.)

@krajorama krajorama left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for this, this is looking promising.
Please add some documentation for the feature flag.

Do I understand correctly that it has the limitation that if we are in some migration state where some classic histograms are still there, but others are not, we might end up not returning all data?

E.g. let's suppose you have two classic histogam metrics, you stop scraping one of them. The code in (q *NHCBAsClassicQuerier) Select will see that there are some results for classic histograms and return that, meaning that the other metric isn't considered and will be missing from the result even if it has an NHCB version.

The other thing I'm wondering about if it has some unintended interaction with other parts of PromQL, for example the delayed name removal. Since we're effectively changing the metric name we're looking up. I would hope not, but something to check.

Comment thread storage/nhcb_querier.go Resolved
Comment thread storage/nhcb_querier.go Resolved
@bwplotka

Copy link
Copy Markdown
Member

Amazing! Thanks 💪🏽

@rbizos - do you want to call-in into some 30m sync around this with @MichaHoffmann ?

@bwplotka

Copy link
Copy Markdown
Member

Related to #16948

Comment thread storage/nhcb_querier.go Resolved
@bwplotka bwplotka changed the title [NHCB] nhcb as classic histogram feature flag promql[nhcb]: nhcb as classic histogram feature flag Feb 12, 2026
@rbizos
rbizos force-pushed the feature/native_histograms_compat_layer branch 3 times, most recently from 61156e2 to f689942 Compare February 23, 2026 16:47
@bwplotka

Copy link
Copy Markdown
Member

FYI: Testing it out, planning to create a small demo for KubeCon (:

@rbizos

rbizos commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

Nice :) I would have gladly joined

Comment thread cmd/prometheus/main.go Resolved
@bwplotka

Copy link
Copy Markdown
Member

Interactive demo for KubeCon: #18339

@bwplotka

bwplotka commented Mar 31, 2026 •

Copy link
Copy Markdown
Member

I only heard positive feedback about this (e.g. @ArthurSens @jan--f, our talk audience, also Cortex folks from Apple).

The only downsides came from @beorn7 @krajorama around demotivating users to actually change queries (there are AI SKILL.md for this being built) with this feature. Then from @krajorama around scale risk and TCO for LTS projects.

  • In terms of migration demotivation: I ack this and I definitely feel the pain and amount of work that has been done to migrate already. This is not wasted, eventually everyone has to migrate. This feature only allows to delay that in time and avoid double writes and transparent NHCB use.
  • In terms of scale: I think we could try estimate the impact and risk for this feature on LTS project scale (e.g. Thanos, Cortex, Mimir). This could be a simple list in this PR (cc @krajorama). We could also be very clear this feature is local to Prometheus likely.

Anything else to do? Probably some test coverage and documentation (also rebase).

I'd expand this for native histograms too, but it can be negotiated later on (:

@jan--f

jan--f commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Is there a plan if and how we could deprecate and eventually remove the old histograms? That could perhaps inform how long a feature as proposed here would stick around?

@rbizos

rbizos commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

I understand fully the migration demotivation and having an intermediary step feels like some people might stop there. But not supporting the bucket syntax feels like a big breaking change (could this be like in Prometheus 4 ?)

@rbizos
rbizos force-pushed the feature/native_histograms_compat_layer branch from e33d659 to f7ed5f1 Compare October 21, 2026 19:55
@rbizos
rbizos force-pushed the feature/native_histograms_compat_layer branch from f7ed5f1 to 7033fc7 Compare October 21, 2026 20:11
@rbizos

rbizos commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@bwplotka This should be ready to review as we discussed earlier, I merged main from upstream, added collision tests (that demonstrate for some need to be implemented) and renamed everything from NHCB to NativeHistogram for futurproofness. The failing test is a timeout and is unrelated

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Some initial comments 💪🏽

Comment thread cmd/prometheus/main.go Resolved
Comment thread docs/feature_flags.md Resolved
Comment thread storage/native_histograms_as_classic.go Resolved
Comment thread cmd/prometheus/main.go Resolved
Comment thread storage/native_histograms_as_classic.go Resolved
Comment thread storage/native_histograms_as_classic.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread storage/native_histograms_as_classic.go Resolved
Comment thread docs/feature_flags.md Resolved
rbizos and others added 7 commits October 23, 2026 16:28
Co-authored-by: Bartlomiej Plotka <[email protected]>
Signed-off-by: rbizos <[email protected]>
Signed-off-by: Raphael Bizos <[email protected]>
i.e. __name__="_sum"

also simplified the base metric extraction to drop unreachable error
cod

Signed-off-by: Raphael Bizos <[email protected]>
Co-authored-by: Bartlomiej Plotka <[email protected]>
Signed-off-by: rbizos <[email protected]>
Co-authored-by: Bartlomiej Plotka <[email protected]>
Signed-off-by: rbizos <[email protected]>
@rbizos
rbizos force-pushed the feature/native_histograms_compat_layer branch from dab344e to a21c860 Compare October 26, 2026 15:41
This would just push the switch nhcb.(type) to the calling side and add
inconsistancy with the rest of the files functions
This reverts commit e3ee095.

Signed-off-by: Raphael Bizos <[email protected]>
Signed-off-by: Raphael Bizos <[email protected]>
Signed-off-by: Raphael Bizos <[email protected]>
@rbizos
rbizos force-pushed the feature/native_histograms_compat_layer branch from e58f639 to 191fc5f Compare October 26, 2026 16:06

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 💪🏽

Thanks for this first iteration - one nit and good to go

Comment thread cmd/prometheus/main.go Resolved
Comment thread docs/feature_flags.md Resolved
rbizos and others added 2 commits October 27, 2026 11:53
Co-authored-by: Bartlomiej Plotka <[email protected]>
Signed-off-by: rbizos <[email protected]>
@bwplotka
bwplotka merged commit b5ec1f6 into prometheus:main Oct 27, 2026
39 checks passed
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.

7 participants