chaos

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: 29 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 chaos drives a load run's faults: it fires each of the scenario's faults at its time against the managed target and the simulated fleet, heals it, and records when it did both.

Index

Constants

View Source
const OrphanGrace = 10 * time.Second

OrphanGrace is how long a process may outlive the worker that started it before no-orphans counts it: the worker's own shutdown and the operating system's cleanup take a moment.

Variables

This section is empty.

Functions

func Apply

func Apply(results []verify.Result, rw *report.Rework, exp scenario.Expect, goos string) []verify.Result

Apply returns results with a scenario's expectations applied, for the OS goos. It does not modify results.

  • A failed result that a known violation for goos names becomes OK, with Known set to the tracker (several entries for one check join theirs) and its evidence kept. A result marked Unmeasured is never excused: the check could not judge, so no defect fired.
  • An entry with a match pattern covers only the violations it matches (the result's Violations, or its Evidence when it has none). When every entry for a check has a pattern, the failure is excused only when each violation matches one; otherwise it stays failed and its evidence counts the unmatched violations and names the first. A scoped entry fires only when it matched a violation. None can excuse a result whose violations were too many to keep (ViolationsCut), which stays failed saying so.
  • A known violation on "rework" excuses the rework only up to its MaxAttempts. Rework over every such ceiling stays failed, and its evidence says the known ceiling was exceeded; an entry with no ceiling excuses nothing, and neither does any entry when the count is short (Undercount), since the true count may be over the ceiling.
  • A max_rework_attempts bound adds a "rework" result after results: OK when rw.Attempts is within the bound, failed when it is over, and failed and Unmeasured with "rework could not be measured" when rw is nil, or when rw says its count is short (Undercount) and is within the bound: a count over the bound is a failure whatever it left out.
  • A "must" violation for goos whose check held, was not run, could not be measured, or failed with no violation its pattern matches adds a failed "known:<check>" result, after the rest. A check is not run when there is no result by its name, as "rework" when no bound is set. A "may" violation that did not fire adds nothing. A "must" rework entry whose ceiling was exceeded counts as fired: the rework result carries that failure.
  • An entry whose OS list leaves out goos does nothing.

func CheckNames

func CheckNames(in StoreInput) []string

CheckNames lists the checks StoreChecks runs on in, in order.

func MarkerChecks

func MarkerChecks(execs []marker.Exec, skipped int, outputs map[string][]marker.OutputLine, incs []target.Incarnation) []verify.Result

MarkerChecks returns [no-orphans, single-writer], from what the real tasks' processes wrote. It is called with the simulated fleet and the real workers still up, after the drain.

no-orphans: no process was seen alive more than OrphanGrace after the incarnation that started it ended. An incarnation still running is not judged. skipped, the exec files the read could not parse, is noted in the evidence and fails nothing.

single-writer: per task key, no two execs wrote the key's output over overlapping spans of time, the span being from an exec's first line to its last.

Types

type Controller

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

Controller fires a scenario's faults and heals them.

func NewController

func NewController(faults []scenario.Fault, groups []scenario.WorkerGroup, t target.Faults, fleet Fleet, logger *slog.Logger) (*Controller, error)

NewController checks the faults against the target and the operating system. t may be nil only when there are no faults; fleet may be nil when there is no simulated fleet.

func (*Controller) HealAll

func (c *Controller) HealAll()

HealAll heals every lane, resumes every stalled process and undoes every database stall, filled volume and lowered file limit still in force. An undo that fails is logged and the rest still run. Run calls it on return; the runner calls it again on an interrupt before teardown. It is safe to call at any time, more than once, and while Run is running: no fault fires after it, and a fault still running cuts and stalls nothing more.

func (*Controller) Records

func (c *Controller) Records() []report.FaultRecord

Records returns the records of the faults fired so far, ordered by Index.

func (*Controller) Run

func (c *Controller) Run(ctx context.Context, start time.Time) error

Run fires each fault at start+At, concurrently, and returns when every fault has healed or ctx is done. Errors are recorded per fault and joined. When ctx ends, each fault in progress heals what it changed on a lane and resumes what it stalled; a process it took down stays down. Run calls HealAll before it returns.

func (*Controller) Windows

func (c *Controller) Windows() []verify.FaultWindow

Windows returns each fired fault that can lose data (a partition, blackhole or flap, a kill, term or stall of the server, or a power cut; not latency or a kill, term or stall of workers) as a verify.FaultWindow, in fault order. One that has not healed ends now.

type DiskWindow

type DiskWindow struct {
	Start time.Time
	// Healed is zero when the volume was never freed.
	Healed time.Time
	// Reason, when set, is what every attempt failing inside the window must
	// match; nil checks none.
	Reason *regexp.Regexp
	// MinFailed, when set, is the fewest attempts that must fail inside the
	// window: fewer means the fault did not do what the scenario injects it
	// for.
	MinFailed *int
	// MaxFailed, when set, bounds the attempts that fail inside the window.
	MaxFailed *int
}

DiskWindow is one workers-volume disk_full fault that fired.

type Fleet

type Fleet interface {
	CrashAll()
	RestartAll(ctx context.Context) error
}

Fleet is the simulated fleet a power cut takes down with the real processes. *simworker.Fleet implements it.

type RevokedWorker

type RevokedWorker struct {
	ID string
	At time.Time
}

RevokedWorker is a real worker whose credential a revoke fault removed, and when.

type StoreInput

type StoreInput struct {
	// Options open the stopped server's store. StoreChecks never migrates it
	// and never takes the single-server lock, whatever they say.
	Options backend.Options
	// FarmID is the run's farm; the status checks read only its jobs.
	FarmID string
	// Ledger is what the simulated workers did. Nil is an empty ledger.
	Ledger *simworker.Ledger
	// Markers are the real tasks' executions; only the main ones count. Nil
	// when the run had no real task.
	Markers []marker.Exec
	// SkippedMarkers is how many exec files the markers' read could not parse,
	// so a real task's execution count may be low. It is a note on
	// executions-recorded, never a failure.
	SkippedMarkers int
	// Faults are the faults the run fired, to which the rework is attributed.
	Faults []report.FaultRecord
	// MaxReclaims, when set, adds the reclaims check: the server took back no
	// more than this many attempts.
	MaxReclaims *int
	// Revoked are the real workers whose credentials a revoke fault removed;
	// when set, the revoked check runs.
	Revoked []RevokedWorker
	// SkewedGroups maps each worker group with a clock skew to the IDs of its
	// simulated workers; when set, the skew-warning check reads ServerLog.
	SkewedGroups map[string][]string
	// ServerLog is the path of the server's log.
	ServerLog string
	// RealIDs are the real workers' IDs, for disk-full.
	RealIDs []string
	// DiskFaults are the workers-volume disk_full faults that fired; when set,
	// the disk-full check runs. DiskErr is why RealIDs or a window could not be
	// built, which leaves the check unmeasured.
	DiskFaults []DiskWindow
	DiskErr    error
}

StoreInput is what the store checks read and compare.

type StoreReport

type StoreReport struct {
	// Results are [store-integrity, executions-recorded, attempt-order], then
	// revoked, skew-warning and disk-full when StoreInput asks for them, then
	// reclaims when StoreInput.MaxReclaims is set.
	Results []verify.Result
	// Rework is what the faults cost; nil when it could not be measured, and
	// ReworkErr then says why.
	Rework    *report.Rework
	ReworkErr error
	// Reclaims are the attempts the server took back; nil when they could not
	// be counted.
	Reclaims *report.Reclaims
}

StoreReport is what StoreChecks found.

func StoreChecks

func StoreChecks(ctx context.Context, in StoreInput) StoreReport

StoreChecks opens the stopped server's store, runs store-integrity, executions-recorded and attempt-order (and revoked, skew-warning, disk-full and reclaims when StoreInput asks for them), and measures the rework and the reclaims.

store-integrity: on SQLite, PRAGMA integrity_check is "ok" and PRAGMA foreign_key_check finds nothing; on both backends, no active usage claim breaks invariant I3, and over the farm's jobs a terminal step holds only terminal tasks, a terminal task has no running attempt, a completed job has only completed steps, and a failed or canceled job no step still open.

executions-recorded: every attempt a simulated worker leased is in the store, closed, and not succeeded when the worker reported it failed (one the worker reported succeeded may have been reclaimed, so it may be failed or canceled); and no real task ran more times than the store has attempts for it.

attempt-order: every attempt's created_at, started_at and ended_at are in that order, within a second.

revoked: no revoked worker's last heartbeat, and no attempt given to it, is more than five seconds after its credential was revoked. The worker's row may stay online meanwhile; only the timestamps are judged.

skew-warning: the server's log warns about at least one worker of every group whose clock was skewed.

disk-full: for each workers-volume disk_full fault, the attempts that failed on real workers between the fault's start and ten seconds after the disk was freed match the fault's reason and number no more than its bound, and every real worker has a succeeded attempt that started after the disk was freed.

A store the checks cannot open, or whose farm's jobs they cannot list, fails every check as unmeasured, with the error as evidence, and leaves the rework and the reclaims unmeasured.

The rework (see [farmView.rework]) is measured from the same store, farm and attempt reads.

Jump to

Keyboard shortcuts

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