agg

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package agg is the shared aggregation core: a concurrency-safe, bounded key→latency table with log2-bucket histograms for approximate percentiles.

Index

Constants

View Source
const (

	// DefaultMaxKeys bounds distinct keys per table. Observations for new
	// keys beyond the cap are merged into OverflowKey instead of being
	// silently dropped.
	DefaultMaxKeys = 10000
	// OverflowKey is the merged bucket for observations past the key cap.
	OverflowKey = "(other)"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Key        string        `json:"key"`
	Count      int64         `json:"count"`
	ErrorCount int64         `json:"error_count"`
	Total      time.Duration `json:"total_ns"`
	Avg        time.Duration `json:"avg_ns"`
	Max        time.Duration `json:"max_ns"`
	P95        time.Duration `json:"p95_ns"`
}

Entry is one aggregated row of a Snapshot. Duration fields marshal to JSON as integer nanoseconds.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table aggregates durations by key. All methods are safe for concurrent use.

func NewTable

func NewTable(maxKeys int) *Table

NewTable returns a Table holding at most maxKeys distinct keys.

func (*Table) Observe

func (t *Table) Observe(key string, d time.Duration)

Observe records one duration for key. New keys are reserved atomically so concurrent observations cannot exceed the configured normal-key budget.

func (*Table) ObserveResult added in v0.2.0

func (t *Table) ObserveResult(key string, d time.Duration, failed bool)

ObserveResult records one duration and whether the operation failed.

func (*Table) Reset

func (t *Table) Reset()

Reset clears all entries and restores the key budget.

func (*Table) Snapshot

func (t *Table) Snapshot() []Entry

Snapshot returns all entries sorted by total time descending (ties broken by key for determinism).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL