loadmetrics

package
v0.0.0-...-7eb2361 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

func DecodeHistogram

func DecodeHistogram(encoded []byte) (*hdrhistogram.Histogram, error)

DecodeHistogram is the inverse of EncodeHistogram.

func EncodeHistogram

func EncodeHistogram(h *hdrhistogram.Histogram) ([]byte, error)

EncodeHistogram serializes a histogram in HdrHistogram's compressed V2 format, the encoding the LoadMetricEntry wire model carries.

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.

func (*Aggregator) Flush

func (a *Aggregator) Flush(now time.Time) Frame

Flush drains the current interval into a Frame and starts a fresh interval for subsequent Records. now becomes the next interval's start, so successive Flush calls describe contiguous, non-overlapping time ranges.

func (*Aggregator) Record

func (a *Aggregator) Record(k Key, latency time.Duration, bytes int64, isErr bool)

Record adds one observation to the bucket identified by k. It is goroutine-safe.

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 Frame

type Frame struct {
	IntervalStart time.Time
	Interval      time.Duration
	Entries       map[Key]Entry
}

Frame is one flushed interval's worth of aggregated entries.

func Combine

func Combine(frames []Frame) Frame

Combine folds any number of Frames - typically one interval's flush from each of many concurrent Aggregators - into a single Frame, without deriving anything. Unlike Merge it keeps a histogram per (step, status-class) entry, so the result can be combined again later (for example across machines) with no loss.

The combined frame covers the union of the inputs' time ranges. The inputs' histograms are only read; every entry of the result owns a freshly allocated one.

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

type Report struct {
	Total   Stats
	PerStep map[Key]Stats
}

Report is the fully-merged result of one or more Frames: overall Stats plus a per-(step,status-class) breakdown.

func Merge

func Merge(frames []Frame) Report

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.

Jump to

Keyboard shortcuts

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