Repository navigation
[metrics] Add native (sparse exponential) buckets to Distribution - #1514
Merged
Merged
Conversation
Add Prometheus-style native histogram buckets as a third bucket type for
distributions, configured through "native_buckets" in the dist proto:
latency_distribution { native_buckets {} }
Bucket boundaries are powers of 2^(2^-schema), and only the buckets that
have samples are stored. Bucket indexing and the bounds table are taken
from prometheus/client_golang.
Native buckets live inside metrics.Distribution, so Add, SubtractCounter,
Clone, String and ParseDistFromString keep working everywhere. Data()
returns a regular-bucket view of the native buckets for the surfacers
that don't handle them natively, along with the native buckets
themselves. The stackdriver surfacer skips native distributions.
This is the first part of native histogram support (#1480). Surfacers
don't export native histograms yet.
manugarg
commented
Oct 1, 2026
- Reject bucket keys that are outside the range that float64 values can map to. Keys come from outside through ParseDistFromString (probe payloads), and Data() builds a view that's as big as the range of the keys, so a single payload line could make it allocate GBs of memory. - Drop zero_threshold. It did nothing at its default of 0, and the regular buckets view was not right for other values. Zero bucket now counts exact zeros only. - Use one type, NativeBuckets, for the internal state and for DistributionData.Native. - Check native compatibility before lower bounds, so that mixing regular and native distributions gives the right error. - cloudwatch: call Data() once per distribution, not once per bucket. - stackdriver: warn about skipped native distributions only once. - Don't accept empty "pb:" and "nb:" tokens; we never write them.
manugarg
force-pushed
the
native-hist-metrics
branch
from
October 1, 2026 23:41
07291e5 to
628401e
Compare
manugarg
marked this pull request as ready for review
October 1, 2026 23:52
This was referenced Oct 2, 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.
First part of native histogram support (#1480). This adds Prometheus-style native buckets to
metrics.Distribution. No surfacer exports native histograms yet; that comes in follow-up PRs (OTel exponential histograms, then protobuf exposition in the Prometheus surfacer).native_buckets { schema }is a third option in theDistbuckets oneof. Bucket boundaries are powers of2^(2^-schema); schema defaults to 3 (about 9% wide buckets) and must be in -4..8.math.Frexpplus a bounds table), so values on a boundary land in the same bucket as they would there. The bounds table is copied intometrics/dist_native_bounds.gowith the Prometheus license header. Only buckets with samples are stored. Exact zeros are counted in a separate zero bucket.dist:sum:53.7|count:50|schema:3|zc:0|pb:-12=2,-9=1,0=3.zcis the zero count, andpb/nbare positive/negative buckets as<index>=<count>, left out when empty.ParseDistFromStringreads it back, so file surfacer output and external probe payloads work. Bucket indexes outside what the schema can produce are rejected.Data()— returns a regular-bucket view of the native buckets (-Inf, 0, then every bucket from the smallest to the largest filled one), so existing surfacers keep working unchanged. It also has a newNativefield with the sparse buckets for the surfacers that will export them natively.Data()once per distribution instead of once per bucket.native(schema=3)in place of the lower bounds.Things to know
native_bucketsis marked experimental in the proto: the option and its fields can change.leseries per bucket in the filled range, and that set grows as new buckets get samples. The plan is to emit only_sum,_countand+Infin text once protobuf exposition is in.zero_thresholdoption: the zero bucket holds exact zeros only. It can be added later if someone needs it.Data()view ignores this; it only matters for values exactly on a boundary.dist.pb.gowas regenerated for this proto alone (protoc 33.5, protoc-gen-go v1.36.12).Testing
Unit tests cover bucket boundaries for all schemas, add/subtract/reset, string round trip and malformed input, the
Data()view and the stackdriver skip. Also ran cloudprober locally with an HTTP probe usingnative_buckets {}and checked the Prometheus surfacer, file surfacer and status page output.