Repository navigation
Conversation
A native histogram accumulates into a mergeable structure supplied by the
application and reports one serialized payload per interval, rather than
a counter per pre-declared bucket. Because the encoding is the
application's choice, tally owns only the seam:
NativeHistogramData the accumulator interface an application
implements (Update / Count / Clear /
MarshalBinary).
NativeHistogram the metric interface callers use.
Two details are load-bearing:
RecordDuration converts to SECONDS, matching the units of
DurationBuckets.AsValues(). Any other unit is a wire concern belonging to
a specific reporter and must be applied on the way out; doing it here
would silently misalign percentiles against tally's own bucketed
histograms, and nothing downstream would catch it.
drain() is a delta. Each payload covers only the interval since the last
report, and a marshal error leaves the accumulator intact so the samples
are retried next cycle instead of being dropped.
That retry behavior is also what makes an unconfigured scope inert rather
than broken. defaultNativeHistogramData counts observations but always
fails to marshal with ErrNativeHistogramBackendNotConfigured, so a scope
with no NativeHistogramFactory skips every cycle: values are counted,
nothing is emitted, and nothing panics.
tally itself never gains a dependency on any histogram implementation.
Owner
Author
|
Superseded by uber-go#279 — org membership came through, so the stack now lives on the upstream repo. Review there. |
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.
Stack 2 of 4. Based on #1. The diff shown here is this commit only.
Adds the
NativeHistogrammetric type. Two files, no wiring —Scopedoes not expose this yet, that is #3.The seam
Tally must never depend on a histogram implementation. The only extension point is a factory the application supplies:
Tally calls
UpdateandMarshalBinaryand ships the bytes. It never inspects them, never learns the encoding, and takes on no new dependency. The seam is the deliverable; a real backend lives in the application.DefaultNativeHistogramMaxBuckets = 160, matching the OpenTelemetry exponential histogram default max size.Two behaviours worth reviewing closely
RecordDurationconverts to seconds. Not milliseconds. This matches the unitsDurationBuckets.AsValues()already reports durations in, so a native histogram and a bucketed timer over the same data agree. Reporters needing another unit on the wire convert on the way out, once. Getting this wrong silently misaligns percentiles and nothing downstream catches it, so there is a test asserting equality againstbuckets.AsValues()directly — change the unit and it fails loudly.The drain is a delta. Each payload covers one reporting interval, not the distribution's whole history: marshal, then clear. On a marshal error the accumulator is left intact, so samples are retried next cycle rather than dropped.
That retry is also what makes an unconfigured scope harmless. The default
NativeHistogramDatanever marshals successfully — it returnsErrNativeHistogramBackendNotConfigured— so the report loop's skip-this-cycle path absorbs it every time. A scope with no factory configured is inert, not broken, and never emits a partial or bogus payload.Tests
13 tests covering the seconds conversion (table-driven, including negatives), delta semantics, sample retention across a marshal error, and the unconfigured default. Fakes only; no backend is imported.
go build ./... && go test ./... && gofmt -l .clean on this commit alone.