stats: add a Nanoseconds histogram unit - #47737
Merged
mattklein123 merged 1 commit intoSep 30, 2026
Merged
Conversation
Add Nanoseconds to Stats::Histogram::Unit so histograms created by extensions and embedders can record nanosecond samples. Timespans flushing to such a histogram record the elapsed nanoseconds, the statsd sinks scale the samples to milliseconds when unit scaling is enabled, and the Lua filter accepts "nanoseconds" as a histogram unit. No Envoy histogram uses the new unit, so existing output is unchanged. Signed-off-by: Bruno Palermo <b@palermo.dev>
Contributor
Author
|
/retest |
bpalermo
marked this pull request as ready for review
September 26, 2026 15:20
bpalermo
requested review from
mathetake,
mattklein123 and
wbpcode
as code owners
September 26, 2026 15:20
Contributor
Author
|
@mathetake this is the follow-up to #47505 you reviewed last week: it adds a |
mattklein123
approved these changes
Sep 30, 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.
Commit Message
stats: add a Nanoseconds histogram unit
Additional Description
Stats::Histogram::Unitstops at microseconds. The motivating consumer isNighthawk, Envoy's load generator, which records request
latencies in nanoseconds and is adding export of those histograms through Envoy's own statsd and
DogStatsD sinks (envoyproxy/nighthawk#1617). Today it has to either quantize to microseconds at
recording time, losing sub-microsecond resolution on the loopback and same-host latencies it exists
to measure, or register the histogram without a unit, in which case the statsd sinks relabel the raw
nanosecond value as milliseconds and report a 3.9 ms latency as about 65 minutes. The same applies to
any embedder or extension measuring sub-microsecond durations.
This adds
Unit::Nanosecondsand wires it through the three places that switch on the unit:HistogramCompletableTimespanImplrecords the elapsed nanoseconds for such a histogram.scale_histogram_units_to_milliseconds(stat_sinks: scale statsd histogram samples to milliseconds by unit #47505) is enabled; with it disabled the sample passesthrough unchanged as for every other unit.
"nanoseconds"as a histogram unit.The unit is opt-in by construction: nothing in Envoy creates a nanosecond histogram, so no existing
metric, value or bucket boundary changes. Storage is unaffected: circllhist bins values to two
significant digits, so scaling samples by 1000 shifts exponents without adding populated bins.
Not included: the stats access logger's own proto unit enum, which is an API change and has no
sub-microsecond source values; and unit-aware default Prometheus/OTel buckets, which would be a
behavior change for existing output. The changelog notes that nanosecond histograms need explicit
histogram_bucket_settingsfor those exporters.Risk Level
Low. Additive enum value; no default behavior change.
Testing
New
ElapsedAndCompleteNanosecondstimespan test; nanosecond samples added to theSiSuffixandHistogramUnitScalingOffByDefaulttests of both statsd sinks; LuaHistogramUnitstest extended.Docs Changes
Lua filter docs list the new unit string.
Release Notes
Added a new feature fragment.
Platform Specific Features
N/A