Documentation
¶
Overview ¶
Package metrics implements per-tool latency reservoirs, error counters, and aggregate summaries used by the reporter and compare subcommand.
Index ¶
Constants ¶
const DefaultReservoirSize = 1_000_000
DefaultReservoirSize is the default number of latency samples retained per tool. With a 1M ring buffer the p99 is accurate up to ~3M requests per run (within ±0.5%). Users can lower this with NewReservoir for memory-tight scenarios.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregateSummary ¶
type AggregateSummary struct {
Overall ToolSummary `json:"overall"`
PerTool map[string]ToolSummary `json:"per_tool"`
ToolKeys []string `json:"tool_keys"`
}
AggregateSummary is the full finalized report fed to formatters and compare.
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator holds a global reservoir plus per-tool stats.
func NewAggregator ¶
func NewAggregator(reservoirSize int) *Aggregator
NewAggregator creates a new aggregator with the specified per-reservoir capacity.
func (*Aggregator) Global ¶
func (a *Aggregator) Global() *ToolStats
Global returns the global overall stats.
func (*Aggregator) Record ¶
func (a *Aggregator) Record(tool string, dur time.Duration, err error)
Record a single observation against both the per-tool and global reservoir.
func (*Aggregator) SummarizeAll ¶
func (a *Aggregator) SummarizeAll() AggregateSummary
SummarizeAll produces a finalized view of all tools plus overall.
func (*Aggregator) Tool ¶
func (a *Aggregator) Tool(name string) *ToolStats
Tool returns the stats for a single tool, or nil if unknown.
func (*Aggregator) ToolNames ¶
func (a *Aggregator) ToolNames() []string
ToolNames returns a sorted slice of tool names tracked.
type Reservoir ¶
type Reservoir struct {
// contains filtered or unexported fields
}
Reservoir stores up to Size samples; when full, new samples replace old slots in round-robin order. This is a fixed-window approximation — the test suite documents expected behaviour.
func NewReservoir ¶
NewReservoir constructs a reservoir with the specified capacity. size must be positive; negative or zero inputs are treated as 1.
type Summary ¶
type Summary struct {
Count int `json:"count"`
Min time.Duration `json:"min"`
Max time.Duration `json:"max"`
Mean time.Duration `json:"mean"`
StdDev time.Duration `json:"stddev"`
P50 time.Duration `json:"p50"`
P90 time.Duration `json:"p90"`
P95 time.Duration `json:"p95"`
P99 time.Duration `json:"p99"`
// SampleCount is the number of samples retained (may be less than Count
// when the reservoir overflowed).
SampleCount int `json:"sample_count"`
}
Summary is the finalized statistics for one reservoir.
type ToolStats ¶
type ToolStats struct {
Name string
Reservoir *Reservoir
// contains filtered or unexported fields
}
ToolStats aggregates all metrics for a single tool name.
func NewToolStats ¶
NewToolStats creates a ToolStats with an empty reservoir of the specified size.
func (*ToolStats) ErrorBreakdown ¶
ErrorBreakdown returns a copy of per-category counts.
func (*ToolStats) ErrorCount ¶
ErrorCount returns total errors across all categories.
func (*ToolStats) RPCErrorCodes ¶
RPCErrorCodes returns a copy of the count-by-code map for jsonrpc errors.
func (*ToolStats) Summarize ¶
func (s *ToolStats) Summarize() ToolSummary
Summarize produces a finalized, serialization-ready snapshot.
type ToolSummary ¶
type ToolSummary struct {
Name string `json:"name"`
Latency Summary `json:"latency"`
OK int64 `json:"ok"`
Errors int64 `json:"errors"`
ErrorPct float64 `json:"error_pct"`
Breakdown map[mcperrors.Category]int64 `json:"breakdown"`
RPCCodes map[int]int64 `json:"rpc_codes"`
}
ToolSummary finalizes a ToolStats into a printable record.