Repository navigation
Conversation
Scope.NativeHistogram(name, maxBuckets) returns the native histogram for
a name, holding at most maxBuckets buckets; 0 uses the scope's configured
default. It follows Histogram at every site: the lookup-then-create path,
the report loop, the cached path, subscope creation, clearMetrics, and
the snapshot.
Two new ScopeOptions:
NativeHistogramFactory supplies the accumulator behind each
native histogram on this scope and
its subscopes.
DefaultNativeHistogramMaxBuckets the budget used when NativeHistogram
is called with 0. Defaults to
DefaultNativeHistogramMaxBuckets.
A nil factory falls back to defaultNativeHistogramFactory, so
Scope.NativeHistogram is always safe to call. Without a real factory the
metric accumulates and is never reported, rather than panicking or
emitting an empty payload -- an application that has not chosen an
encoding has nothing meaningful to put on the wire.
Snapshot gains NativeHistograms(). Only the sample count is exposed: the
distribution lives in an application-supplied accumulator whose encoding
tally does not interpret, so there is nothing generic to show.
tally still has no dependency on any histogram implementation. The
factory is the entire seam.
Owner
Author
|
Superseded by uber-go#280 — 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 3 of 4. Based on #2. The diff shown here is this commit only.
Wires the type from #2 into
Scope. This is the commit that makes the feature reachable.Pass
maxBuckets < 1to take the scope's default.ScopeOptions
Two new fields:
NativeHistogramFactory func(maxBuckets int) NativeHistogramData— the only place a backend is ever supplied. Leave it nil and every native histogram on the scope is inert, per Add the NativeHistogram metric type #2.DefaultNativeHistogramMaxBuckets— defaults to 160 when unset or< 1.Both propagate to subscopes through
scope_registry.go, so a factory set once at the root reaches everything beneath it. There is a test for that specifically, since the registry's sharded subscope construction is easy to get wrong.Mirrors the existing Histogram plumbing
NativeHistogramfollowsHistogramstep for step: lookup underRLock, take the write lock, double-check, allocate the cached handle when aCachedStatsReporteris present, store. The newnhmmutex joins the existing lock chain inreport,cachedReport,clearMetricsandSnapshot.SnapshotgainsNativeHistograms() map[string]NativeHistogramSnapshot, exposing name, tags and sample count. Not the payload — the encoding is the application's, so tally has nothing meaningful to hand back.Deliberately not included
No cardinality gauge in
reportInternalMetrics. Adding one would put a permanently-zero series on every scope that never touches this feature, which is the same argument as the m3 counter in #1.Tests
7 scope-level tests: default and explicit bucket budgets, no-factory inertness, subscope inheritance, snapshot contents.
I mutation-tested the report wiring rather than trusting a green run — disabling the
nhmblock inreport()makesTestScopeNativeHistogramfail, so the test is actually exercising the path.go build ./... && go test ./... && gofmt -l .clean on this commit alone.