Documentation
¶
Index ¶
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, merges, 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, } )
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.
Functions ¶
func NamedCounter ¶
NamedCounter increments the {name}.{counter} counter by 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.