loadgen

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package loadgen holds the reusable, testable pieces of the livck-loadgen fake-fleet driver: the catalog-driven synthetic report generator and the sender-side latency/status recorder. The live orchestration (enroll storm, ramp, pulse sampling) lives in cmd/livck-loadgen so this package stays pure and unit-testable. ASCII only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstrumentClient

func InstrumentClient(base *http.Client, rec *Recorder) *http.Client

InstrumentClient returns a shallow copy of base whose Transport records every request into rec. The original client is not mutated.

Types

type Generator

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

Generator produces synthetic reports for one simulated agent. It is NOT safe for concurrent use: each simulated agent owns one generator on its own goroutine (matching a real agent's single collect loop).

func NewGenerator

func NewGenerator(seed uint64) *Generator

NewGenerator builds a generator seeded from seed so each simulated agent walks a distinct value path (distinct-looking hosts) while a run stays reproducible.

func (*Generator) KeyCount

func (g *Generator) KeyCount() int

KeyCount is the number of base catalog keys a clean report carries (before avg+max companions). Exposed for the loadgen's throughput accounting.

func (*Generator) PoisonReport

func (g *Generator) PoisonReport() map[string]float64

PoisonReport returns a deliberately malformed report to exercise pulse's validation ladder under load: unknown keys (dropped, counted) and out-of-range values (clamped). The envelope stays valid protobuf+zstd, so this probes the per-key validation cost, not the batch-reject path.

func (*Generator) Report

func (g *Generator) Report() map[string]float64

Report returns one report's metrics: a plausible value for every catalog key, plus a "<key>.max" companion for every avg+max key with peak >= mean - exactly the shape the real agent's aggregator emits, so pulse sees a faithful batch.

type Raw

type Raw struct {
	Total, OK, Retry429, Retry5xx, Drop4xx, Auth, Other, TransportErr int64
	SumNanos                                                          uint64
	Buckets                                                           []uint64
}

Raw is a lossless readout of the recorder's counters and histogram buckets at one instant, so two Raws can be diffed into a per-window Snapshot (percentiles included). It is the basis for measuring one ramp step in isolation instead of reporting cumulative totals.

type Recorder

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

Recorder accumulates ingest request outcomes lock-free (atomics only) so it can sit in the hot RoundTrip path of thousands of concurrent senders.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder builds an empty Recorder.

func (*Recorder) Raw

func (r *Recorder) Raw() Raw

Raw reads the current counters and histogram buckets.

func (*Recorder) Record

func (r *Recorder) Record(d time.Duration, statusCode int, transportErr bool)

Record folds one request outcome into the recorder. statusCode is ignored when transportErr is true (no response arrived).

func (*Recorder) Snapshot

func (r *Recorder) Snapshot() Snapshot

Snapshot reads the current counters and derives latency percentiles from the histogram. Percentiles are the upper edge of the containing bucket.

type Snapshot

type Snapshot struct {
	Total        int64
	OK           int64
	Retry429     int64
	Retry5xx     int64
	Drop4xx      int64
	Auth         int64
	Other        int64
	TransportErr int64
	MeanMs       float64
	P50Ms        float64
	P90Ms        float64
	P99Ms        float64
}

Snapshot is an immutable readout of the recorder at one instant.

func DeltaSnapshot

func DeltaSnapshot(from, to Raw) Snapshot

DeltaSnapshot returns the readout for the window (from, to]: counts are the difference and percentiles come from the difference of the histogram buckets, so one ramp step is measured without the earlier steps' history.

func (Snapshot) OKRate

func (s Snapshot) OKRate() float64

OKRate is the fraction of requests that returned 202 (0..1).

Jump to

Keyboard shortcuts

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