Skip to content

Unroll NHCBs to Classic Histograms func for RW - #17166

Merged
krajorama merged 12 commits into
prometheus:mainfrom
Naman-B-Parlecha:NamanParlecha/NHCBtoCH
Oct 30, 2025
Merged

krajorama merged 12 commits into
prometheus:mainfrom
Naman-B-Parlecha:NamanParlecha/NHCBtoCH

Conversation

@Naman-B-Parlecha

@Naman-B-Parlecha Naman-B-Parlecha commented Sep 9, 2025 •

Copy link
Copy Markdown
Contributor

Which issue(s) does the PR fix:

Does this PR introduce a user-facing change?

[FEATURE]: Conversion func for NHCBs to Classic Histograms

Implements conversion from Native Histogram Custom Buckets (NHCB) to classic histogram format for Remote Write compatibility and migration scenario

The PR consists of func that handles the conversion of Histograms

@Naman-B-Parlecha Naman-B-Parlecha changed the title Naman parlecha/nhc bto ch Option to unroll nhcbs to classic histograms for RW Sep 9, 2025

@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.

Nice! Some pointers.

Comment thread storage/remote/queue_manager.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread storage/remote/queue_manager.go Resolved
Comment thread storage/remote/queue_manager.go Resolved
@Naman-B-Parlecha
Naman-B-Parlecha force-pushed the NamanParlecha/NHCBtoCH branch 2 times, most recently from e5b1d0c to 524e3d7 Compare September 15, 2025 18:28

@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.

NOTEs after pair review:

For this PR, we could just allow conflicts (send duplicated series via RW) and document this behaviour. I don't think we can handle those conflicts here, they would need to be handled on TSDB Append.

  • We agreed to perhaps split this PR into two/three for easier review.

Comment thread config/config.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread storage/remote/queue_manager.go Resolved
Comment thread storage/remote/queue_manager.go Resolved
@Naman-B-Parlecha
Naman-B-Parlecha force-pushed the NamanParlecha/NHCBtoCH branch 4 times, most recently from ff74632 to 8d791b1 Compare September 17, 2025 09:59
@Naman-B-Parlecha Naman-B-Parlecha changed the title Option to unroll nhcbs to classic histograms for RW Unroll NHCBs to Classic Histograms func for RW Sep 17, 2025
@Naman-B-Parlecha

Naman-B-Parlecha commented Sep 17, 2025 •

Copy link
Copy Markdown
Contributor Author

Hey!!
@perebaj I have split the PR into 2 parts - #17205 (Consisting of Experimental Flag) and the current PR holding the conversion logic.

Also, I had a question (more like a confusion)

As @bwplotka mentioned - here

This also is expensive, because we created builder every time. We likely have to pass the pointer to the open builder instead.

Which i was trying to work upon. So i started using builder from the queue_manager as seen here

But i was concerned about it having labels that would be important and to not disturb other parts of the codebase i thought of reset the label builder but also roll it back to original labels to maintain what it holds - reference.

I was confused here whether i was doing it correctly or is there a better way of using the builder in such cases?

WDYT??

cc: @bwplotka

@Naman-B-Parlecha
Naman-B-Parlecha marked this pull request as ready for review September 17, 2025 11:44
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert_test.go Resolved
@Naman-B-Parlecha

Copy link
Copy Markdown
Contributor Author

Hey @perebaj the PR is read for another round of review!!
PTAL

Signed-off-by: Naman-B-Parlecha <[email protected]>

@perebaj perebaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggesting removing some comments and improve the name of tests structures

Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
@Naman-B-Parlecha

Copy link
Copy Markdown
Contributor Author

@bwplotka @perebaj
So why dont relabel and add _nhcb_to_classic suffix to the unrolled series to avoid conflicts

On enabling convert_nhcb_to_classic flag we add info for the users that we will be adding these suffix to avoid any conflicts in unrolling so that they are aware about the relabelling

And if there still is conflicts when unrolling, we can just error out?

@bwplotka

bwplotka commented Oct 1, 2025

Copy link
Copy Markdown
Member

Looks good in general, we decided to discuss the conflict topic in a native summaries proposal, but for nhcb unrolling it will be relevant for another PR (the one that uses this function in RW).

I will review this PR closer in the incoming days (likely Monday) unless @perebaj will review sooner 👍🏽

@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 great! Some suggestions for higher reliability of this code and test, but otherwise great job 💪🏽

Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved

@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.

LGTM, just tiny nits, @krajorama @bboreham are you ok with adding float formatting to labels pkg? It's essentially related to le label, so I'd think it's not a bad spot (although type and unit label semantics are in /schema/package), WDYT?

Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/labels/float.go Resolved
Signed-off-by: Naman-B-Parlecha <[email protected]>

@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, thanks for starting to work on this.

I think there's some nuances about the model missed in the implementation. I've added comments.

Also I would advise you to set up a testbed with some target + Prometheus -> remote write -> other Prometheus and test things end-to-end.

You should get the same result whether you're using NHCB or not.

Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/labels/float.go Resolved
@Naman-B-Parlecha

Copy link
Copy Markdown
Contributor Author

Hey @krajorama,
Thanks for spotting this out, i missed out on understanding sparseness in NHCBs, I went over and read about it from this doc

And tried to implement the same, will setup a testbed in some time and add the results here

Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert_test.go Resolved
@Naman-B-Parlecha

Copy link
Copy Markdown
Contributor Author

Hey @krajorama here are the testbed results
did this setup as u mentioned

Screenshot 2025-10-16 at 7 21 31 PM Screenshot 2025-10-16 at 7 11 41 PM Screenshot 2025-10-16 at 7 11 59 PM Screenshot 2025-10-16 at 7 12 05 PM

@Naman-B-Parlecha

Naman-B-Parlecha commented Oct 25, 2025 •

Copy link
Copy Markdown
Contributor Author

Hey @bwplotka @krajorama, i have refactored the PR to support sparseness in NHCBs and have addressed all the changes suggested.
PTAL :)

@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.

Almost there, a few more details commented.
Sorry about the long wait, but we were very busy with Prometheus conference last week.

Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert_test.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert.go Resolved
Comment thread model/histogram/convert_test.go Resolved
@Naman-B-Parlecha

Copy link
Copy Markdown
Contributor Author

Hey @krajorama, I have addressed all the comments PTAL, have added .Validate() check just so that even if caller doesn't validate it before we could do it here as well

@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.

LGTM

I don't want to delay this PR anymore, but we should move the code to https://github.com/prometheus/prometheus/tree/main/util/convertnhcb in a next PR.

Also technically you can do the conversion without allocating the intermediate positiveBuckets array.

@krajorama
krajorama merged commit 37418b5 into prometheus:main Oct 30, 2025
@Naman-B-Parlecha
Naman-B-Parlecha deleted the NamanParlecha/NHCBtoCH branch October 30, 2025 08:14
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.

5 participants