feat(metrics): add support for classic, time, and native histograms.#236
Open
ethanolchik wants to merge 10 commits into
Open
feat(metrics): add support for classic, time, and native histograms.#236ethanolchik wants to merge 10 commits into
ethanolchik wants to merge 10 commits into
Conversation
ethanolchik
marked this pull request as draft
July 20, 2026 17:25
Add owned fixed-bucket storage, direct protobuf encoding, and support for the legacy HistogramBuilder API (only classic histograms in this commit).
ethanolchik
force-pushed
the
metrics/histograms
branch
from
July 21, 2026 15:32
f4b4b5b to
535ae20
Compare
ethanolchik
marked this pull request as ready for review
July 21, 2026 15:32
Choose to pre-sort histogram buckets over a sorted boolean variable. Also satisfies cargo clippy & cargo fmt
fisherdarling
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adds classic, time, and native histogram metric types to
foundations-metrics, including protobuf encoding, constructors, family support,TimeHistogramsnapshots, and timer behaviour.Changes
Classic histograms
Adds an owned
Histogrambacked by shared, mutex-protected storage.Histogram::newaccepts inclusive bucket bounds and appends the legacy terminalf64::MAXbucket.observeupdates the sample sum, sample count, and the first matching bucket.Time histograms
Adds the lock-free
TimeHistogramandHistogramTimerAPIs previously provided byprometools.start_timerrecords elapsed time when the timer is stopped or dropped.pause,resume,stop_and_record, andstop_and_discard.TimeHistogram::snapshotexposes the current sum, count, and non-cumulative buckets throughHistogramSnapshot.Histogram construction
Adds
HistogramBuilderas aMetricConstructorfor bothHistogramandTimeHistogram.This allows configured histograms to be created by
Familyand by generated metric constructors while preserving the existing#[ctor = HistogramBuilder { ... }]shape.Native histograms
Adds
NativeHistogram, backed byprometheus-client0.25's native histogram implementation.NativeHistogram::observerecords values into sparse exponential buckets.NativeHistogramBuilderconfigures bucket growth factor, zero-bucket threshold, and the best-effort maximum number of sparse buckets.MetricConstructor, allowing native histograms to be used in labelledFamilymetrics.prometheus-clientbecause its sparse bucket state is private.foundations-metrics-registrymodel, including sample count/sum, schema, zero bucket, positive and negative spans, and bucket deltas.Public API
Exports the following from
foundations-metrics:HistogramHistogramBuilderHistogramSnapshotHistogramTimerTimeHistogramNativeHistogramNativeHistogramBuilderThe registry crate also re-exports the protobuf
Buckettype needed by histogram encoders.