Documentation
¶
Index ¶
- Variables
- func NamedCounter(scope tally.Scope, name string, counter string, value int64, tags ...Tag)
- func NamedGauge(scope tally.Scope, name string, gauge string, value float64, tags ...Tag)
- func NamedHistogram(scope tally.Scope, name string, histogram string, buckets tally.Buckets, ...) tally.Histogram
- func WithContextTags(ctx context.Context, tags ...Tag) context.Context
- type Op
- type Tag
Constants ¶
This section is empty.
Variables ¶
var ( // FastLatencyBuckets suits fast in-process operations (~microseconds to // seconds): scoring, cache lookups, and other CPU-bound work. FastLatencyBuckets = tally.DurationBuckets{ 100 * time.Microsecond, 250 * time.Microsecond, 500 * time.Microsecond, 1 * time.Millisecond, 2500 * time.Microsecond, 5 * time.Millisecond, 10 * time.Millisecond, 25 * time.Millisecond, 50 * time.Millisecond, 100 * time.Millisecond, 250 * time.Millisecond, 500 * time.Millisecond, 1 * time.Second, 2500 * time.Millisecond, 5 * time.Second, } // StorageLatencyBuckets suits storage and message-queue round-trips // (~1ms to a minute): database reads/writes, publish/consume, and RPC // handlers whose latency is dominated by such calls. StorageLatencyBuckets = tally.DurationBuckets{ 1 * time.Millisecond, 2500 * time.Microsecond, 5 * time.Millisecond, 10 * time.Millisecond, 25 * time.Millisecond, 50 * time.Millisecond, 100 * time.Millisecond, 250 * time.Millisecond, 500 * time.Millisecond, 1 * time.Second, 2500 * time.Millisecond, 5 * time.Second, 10 * time.Second, 30 * time.Second, 1 * time.Minute, } // LongLatencyBuckets suits long-running pipeline work and external calls // (~5ms to hours): builds, lands, git pushes, and external provider calls. LongLatencyBuckets = tally.DurationBuckets{ 5 * time.Millisecond, 10 * time.Millisecond, 25 * time.Millisecond, 50 * time.Millisecond, 100 * time.Millisecond, 250 * time.Millisecond, 500 * time.Millisecond, 1 * time.Second, 2500 * time.Millisecond, 5 * time.Second, 10 * time.Second, 30 * time.Second, 1 * time.Minute, 2 * time.Minute, 5 * time.Minute, 10 * time.Minute, 30 * time.Minute, 1 * time.Hour, 2 * time.Hour, 4 * time.Hour, } // ChangeAgeBuckets suits durations measured from a source-control change's // commit timestamp. They span minutes to a month because that is the honest // range of such a signal: a break caught in minutes and one that survived a // fortnight are both ordinary observations, and collapsing the tail would hide // exactly the cases worth seeing. ChangeAgeBuckets = tally.DurationBuckets{ 1 * time.Minute, 5 * time.Minute, 15 * time.Minute, 30 * time.Minute, 1 * time.Hour, 2 * time.Hour, 4 * time.Hour, 8 * time.Hour, 12 * time.Hour, 24 * time.Hour, 48 * time.Hour, 7 * 24 * time.Hour, 14 * 24 * time.Hour, 30 * 24 * time.Hour, } // LandLatencyBuckets suits end-to-end request lifecycles, from accepting a // land request to its terminal outcome. Resolution is densest between 5 and // 60 minutes, where typical lands fall, and the tail reaches a day so that // requests stuck overnight stay distinguishable instead of overflowing. LandLatencyBuckets = tally.DurationBuckets{ 1 * time.Minute, 2 * time.Minute, 3 * time.Minute, 5 * time.Minute, 7*time.Minute + 30*time.Second, 10 * time.Minute, 15 * time.Minute, 20 * time.Minute, 30 * time.Minute, 45 * time.Minute, 1 * time.Hour, 90 * time.Minute, 2 * time.Hour, 3 * time.Hour, 4 * time.Hour, 6 * time.Hour, 8 * time.Hour, 12 * time.Hour, 24 * time.Hour, } )
Common duration bucket sets for latency histograms. Operations differ widely in expected latency, so there is no single default — pick the set whose range matches the operation and pass it to Begin or NamedHistogram. Buckets far outside an operation's real latency waste series cardinality and lose resolution where the data actually lands.
var CountBuckets = tally.ValueBuckets{0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144}
CountBuckets suits small cardinalities recorded with RecordValue, such as how many items a unit of work carries or depends on. Zero has its own bucket because "none" is a meaningful answer, and the Fibonacci spacing keeps resolution where counts usually fall while still separating outliers.
Functions ¶
func NamedCounter ¶
NamedCounter increments the {name}.{counter} counter by value.
func NamedGauge ¶
NamedGauge sets the {name}.{gauge} gauge to value.
func NamedHistogram ¶
func NamedHistogram(scope tally.Scope, name string, histogram string, buckets tally.Buckets, tags ...Tag) tally.Histogram
NamedHistogram returns a tally.Histogram at {name}.{histogram} with the given bucket configuration. Store the returned histogram and call RecordDuration or RecordValue on each invocation.
Types ¶
type Op ¶
type Op struct {
// contains filtered or unexported fields
}
Op tracks the lifecycle of a named operation. It captures the start time on creation, emits a {name}.start counter, and records the duration and result on a {name}.finish histogram when Complete is called.
Usage:
func (c *Controller) Process(ctx context.Context, delivery consumer.Delivery) (retErr error) {
op := metrics.Begin(c.scope, "process", metrics.StorageLatencyBuckets)
defer func() { op.Complete(retErr) }()
// ... business logic ...
}
func Begin ¶
Begin starts a new operation. It emits a {name}.start counter, captures the start time, and retains the buckets used by Complete.
func (Op) Complete ¶
Complete records elapsed time on the {name}.finish histogram, tagged with result=success|error|cancel and any additional tags accumulated while the operation ran. The histogram records both duration and count. Cancellation is detected through the error chain.
func (Op) CompleteAs ¶
CompleteAs records elapsed time on the {name}.finish histogram like Complete, but with a caller-chosen result tag. It serves outcomes that the error alone does not classify, such as a lookup that found no record.