Skip to content

Add native histogram support#304

Open
howardjohn wants to merge 2 commits into
prometheus:masterfrom
howardjohn:histogram/native2
Open

Add native histogram support#304
howardjohn wants to merge 2 commits into
prometheus:masterfrom
howardjohn:histogram/native2

Conversation

@howardjohn
Copy link
Copy Markdown
Contributor

This PR adds support for native histograms using the new prometheus protobuf support recently merged.

The implementation is basically 1:1 lifted from the Golang implementation as much as possible, including tests.

Users can make any of the 3: classic only, native only, or classic + native histogram.

Add native-only histograms and histograms that expose both classic and native buckets. Encode native sparse bucket spans and deltas through the Prometheus protobuf encoder while keeping text and OpenMetrics protobuf behavior on the classic representation when available.

Signed-off-by: John Howard <john.howard@solo.io>
@howardjohn howardjohn force-pushed the histogram/native2 branch from dc631bf to d4882eb Compare May 28, 2026 20:55
@f41gh7
Copy link
Copy Markdown

f41gh7 commented May 29, 2026

Related issue #150

Copy link
Copy Markdown
Collaborator

@krisztianfekete krisztianfekete left a comment

Choose a reason for hiding this comment

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

This looks great, I am planning to do some actual testing as well soon, but added a couple of comments/questions in the meantime!

Comment thread src/metrics/histogram.rs
Comment thread src/metrics/histogram.rs Outdated
Comment thread src/metrics/histogram.rs Outdated
Comment thread src/metrics/histogram.rs Outdated
Comment thread src/encoding/text.rs
_native: NativeHistogram<'_>,
) -> Result<(), std::fmt::Error> {
if buckets.is_empty() {
return Err(std::fmt::Error);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we have a typed error here and surface that the text encoder doesn't support native histograms?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really. the EncodeMetric itself has std::fmt::Error as the error type which conveys no information. To do so we would have to modify the public trait which doesn't seem in scope for this.

Comment thread src/metrics/histogram.rs
Comment thread src/metrics/histogram.rs
Signed-off-by: John Howard <john.howard@solo.io>
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.

3 participants