Documentation
¶
Overview ¶
Package loadmetrics aggregates load-test execution results into interval frames using HDR histograms, keyed by (step, status-class).
The usage shape is: an Aggregator collects Records concurrently during an interval, Flush drains that interval into an immutable Frame, and Merge lossily-free combines any number of Frames - whether successive flushes from one Aggregator, or one flush each from many concurrent Aggregators - into a single Report with derived percentiles.
This package has no dependency on the rest of the server; its exported surface is a frozen contract consumed by the load-test ingest pipeline.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator accumulates Records into per-key HDR histograms for the current interval. It is safe for concurrent use.
func NewAggregator ¶
func NewAggregator(interval time.Duration) *Aggregator
NewAggregator creates an Aggregator. interval documents the caller's intended flush cadence; it is not baked into Frame.Interval, which instead reflects the actual elapsed time between flushes (see Flush) so reported RPS stays correct even if the caller flushes early, late, or irregularly.
type Entry ¶
type Entry struct {
Count int64
ErrorCount int64
Bytes int64
Hist *hdrhistogram.Histogram // 1us..10min, 3 significant figures
}
Entry is one (step, status-class) bucket's accumulated stats for a single interval.
type Key ¶
type Key struct {
Step string
StatusClass StatusClass
}
Key identifies one aggregation bucket: a load-test step at a particular outcome class.
type Report ¶
Report is the fully-merged result of one or more Frames: overall Stats plus a per-(step,status-class) breakdown.
func Merge ¶
Merge combines any number of Frames - from one Aggregator's successive flushes, or from many concurrent Aggregators - into a single Report. Merging is lossless: percentiles on the merged histograms are equivalent (within HDR's significant-figure precision) to what a single Aggregator fed all the same observations would have produced.
The wall time used for RPS is the union of the supplied frames' time ranges (earliest IntervalStart to latest IntervalStart+Interval), not the sum of their durations - this keeps RPS correct both for a single Aggregator's successive contiguous flushes and for many Aggregators flushing over the same overlapping window.
type Stats ¶
type Stats struct {
Count, ErrorCount, Bytes int64
P50, P90, P95, P99, Max time.Duration
RPS float64 // Count / covered wall time
}
Stats is a set of derived, percentile-level statistics for a bucket, or for the whole run in Report.Total.
type StatusClass ¶
type StatusClass string
StatusClass buckets a recorded outcome for aggregation. Values are the literal strings carried on the wire (see the LoadMetricEntry TypeSpec model) - do not change them without updating that mapping.
const ( StatusClass2xx StatusClass = "2xx" StatusClass3xx StatusClass = "3xx" StatusClass4xx StatusClass = "4xx" StatusClass5xx StatusClass = "5xx" StatusClassError StatusClass = "error" StatusClassTimeout StatusClass = "timeout" )
func ClassifyStatus ¶
func ClassifyStatus(code int, err error) StatusClass
ClassifyStatus buckets an HTTP-ish status code and/or transport error into a StatusClass. A non-nil err always wins over code (whatever code happens to be at that point, e.g. zero, is irrelevant once the request failed at the transport level). Timeouts - deadline-exceeded context errors, or any error the standard library recognizes via os.IsTimeout - classify as StatusClassTimeout rather than the more generic StatusClassError.