runner

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 35 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package runner runs one load scenario end to end against an sqi-server and writes its record. It wires the harness together in a fixed order: start the target, ramp the simulated fleet, start the observer and the UI clients, submit jobs (with the scenario's actions and churn) for the scenario's duration, wait for the jobs to drain, check the invariants while the fleet is still up, stop the fleet and the clients, take the observer's last sample, close the target, and write run.json, summary.md and series.csv.

A chaos run (a scenario with faults, a rework budget, known violations or real tasks, on a target that can inject faults) also fires the scenario's faults beside the submissions, waits for every one to heal before the drain, waits for the jobs the server created for submissions it gave no 2xx answer, and checks the store, the real tasks' markers and the rework.

A run interrupted through its context still tears everything down and writes its record, marked incomplete.

Index

Constants

View Source
const (
	// DefaultOutDir is where run directories go when Options.OutDir is "".
	DefaultOutDir = "runs"
	// DefaultSample is the observer's sampling period when Options.Sample is 0.
	DefaultSample = 5 * time.Second
	// DefaultSoakProfileEvery is a soak's heap and goroutine profile period
	// when Options.ProfileEvery is 0. A load run takes them only at its start
	// and end.
	DefaultSoakProfileEvery = 15 * time.Minute
)

Variables

This section is empty.

Functions

func NewRunID

func NewRunID(now time.Time) string

NewRunID returns a run ID for a run starting at now: the UTC time as yyyymmdd-hhmmss and four random hex digits, like 20261104-170507-3fa2.

func Run

func Run(ctx context.Context, o Options) (*report.Record, error)

Run runs the scenario once and writes its record into the run directory.

It returns the record and nil for a run that went to its end, and for one interrupted through ctx (the record says Complete: false). It returns nil and an error when the run could not be set up (bad options, a target or fleet that would not start), after stopping whatever it had started. It returns the record and an error when something failed after setup: a driver error (the run is then incomplete), the target's teardown, or writing the record.

A panic in the goroutine calling Run stops the fleet and the target before it continues. A panic on another goroutine ends the process at once; the managed target's processes then die with it on Linux and Windows (parent death signal, job object) but not on macOS.

func SeedFor

func SeedFor(runID string) int64

SeedFor derives a run's default seed from its ID, so a run is reproducible from its ID alone. It is never zero.

func Sweep

func Sweep(ctx context.Context, base Options, path string, values []string) ([]report.SweepPoint, error)

Sweep runs base's scenario once for each of values, the value set at path (scenario.Set syntax) on top of base's own overrides, each on a fresh managed target, in the order given (ascending, for the knee). The sweep's ID is base.RunID; point i runs as <id>-p<i> and writes its run directory to OutDir/<id>/<i>-<value>. Every point shares base's seed, so the points differ only in the value. sweep.csv and sweep.md, with the knee, go to OutDir/<id> at the end, also after an interrupt.

Every value is applied and validated before the first run, so a bad value fails the sweep up front. A point that cannot be set up is recorded without a record (the knee calls it out) and the sweep goes on; an interrupt ends the sweep after the point it interrupted. A sweep cannot attach: each point needs a server of its own.

func SweepScenarios

func SweepScenarios(base *scenario.Scenario, path string, values []string) ([]*scenario.Scenario, error)

SweepScenarios returns the scenario of each sweep point: a copy of base with the value set at path, defaults applied and validated for a managed target. base is not changed.

func ValidRunID

func ValidRunID(id string) error

ValidRunID reports why id cannot name a run, or nil when it can: it must be 1 to 64 letters, digits and dashes, starting with a letter or digit, and not end in -s<digits>, which shards use.

Types

type Options

type Options struct {
	// Scenario is the resolved scenario, overrides applied and defaults
	// filled. Normalize validates it for the target.
	Scenario *scenario.Scenario
	// Mode is report.ModeLoad (the default), report.ModeSoak or
	// report.ModeSweepPoint.
	Mode string
	// RunID names the run, its directory and its farm; "" generates one with
	// NewRunID. The run directory is OutDir/RunID, or OutDir/RunID-s<i> for a
	// shard of several, unless Dir names it.
	RunID, OutDir string
	Dir           string
	// Seed seeds every random choice of the run; 0 derives it from RunID
	// (SeedFor). A shard adds its index, so shards differ.
	Seed int64
	// Sample is the observer's sampling period (DefaultSample when 0).
	// ProfileEvery is the period of heap and goroutine profiles: 0 means
	// DefaultSoakProfileEvery in a soak and start and end only otherwise; a
	// negative value means start and end only.
	Sample, ProfileEvery time.Duration
	// Shard runs one slice of the scenario (see report.ShardSpec.Apply).
	Shard report.ShardSpec
	// AllowSaturated keeps an invalid run (a saturated generator) from
	// counting against it: the record stays invalid and gains a warning
	// finding. The CLI uses it to choose its exit status.
	AllowSaturated bool
	// Managed starts the run's own sqi-server; Attach drives one somebody
	// else runs. Neither set means a managed target with defaults. Run fills
	// RunDir, RunID, Scenario and Logger itself, and builds the binaries
	// Managed does not name into OutDir/.bin.
	Managed *target.ManagedConfig
	Attach  *target.AttachConfig
	// Flags is the command line, for the record's environment.
	Flags  []string
	Logger *slog.Logger
	// Abort, when closed, cuts the teardown short: processes are killed
	// rather than waited for. The CLI closes it on a second interrupt.
	Abort <-chan struct{}
	// BeforeVerify, when set, may change the verifier's input just before
	// the invariants are checked. A test hook.
	BeforeVerify func(*verify.Input)
	// OnTarget, when set, is called with the target once it has started. A
	// test hook.
	OnTarget func(target.Target)
	// contains filtered or unexported fields
}

Options configures a run.

func (*Options) Directory

func (o *Options) Directory() string

Directory is the run directory the options name.

func (*Options) Normalize

func (o *Options) Normalize() error

Normalize fills in what the options leave to Run (a managed target when neither Managed nor Attach is set, the mode, run ID, output directory, seed, and the sample and profile periods), rejects options that do not go together, and validates the scenario for the target. Run and Sweep call it; a caller that wants the run ID, seed or directory before the run starts calls it first. It is idempotent, and does not validate a scenario again that it validated for the same target, so the scenario must not be changed in place once it has.

func (*Options) TargetKind

func (o *Options) TargetKind() scenario.TargetKind

TargetKind is the kind of target the options run on.

Jump to

Keyboard shortcuts

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