verify

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: 15 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 verify decides whether a load run passed. It compares what the driver submitted and what the simulated workers did (the simworker.Ledger) with what the server reports, through the seven run invariants of the load harness: every job terminal, every task's status the one the simulator decided, one live attempt per task at a time, the logs the simulator sent, the online worker count, the queue and usage-pool caps, and submission-atomic: every job the server holds is one the run submitted, and a submission that got no 2xx answer created all of its job or none of it. The logs invariant allows lines lost inside a fault window, and counts them.

Facts about the server the checks rely on:

  • The attempt ID in an assignment, and so in every ledger event, is the server's attempt row ID. The server's log chunks carry it as client.LogLine.AttemptID. GET /tasks/{id}/attempts does not expose it, only the attempt number, which the client returns as client.Attempt.ID.
  • Attempt statuses are running, succeeded, failed and canceled. An attempt the server reclaims from a crashed, restarted or silent worker is closed as failed, so a retry and a reclaim both follow a failed attempt, and a canceled task's open attempt is closed as canceled.
  • GET /tasks/{id}/logs returns only the task's latest attempt. A chunk is several lines joined with "\n", numbered from 1 per attempt (seq_num), and listed in broker order (nats_seq), which is not always seq_num order.
  • List pages are capped at 1000 items.

Index

Constants

View Source
const (
	NameTerminal         = "terminal"
	NameOutcomes         = "outcomes"
	NameSingleAttempt    = "single-attempt"
	NameLogs             = "logs"
	NameWorkersConverge  = "workers-converge"
	NameCaps             = "caps"
	NameSubmissionAtomic = "submission-atomic"

	// Package chaos reports these five, from the stopped server's store and
	// the real tasks' markers.
	NameStoreIntegrity     = "store-integrity"
	NameExecutionsRecorded = "executions-recorded"
	NameNoOrphans          = "no-orphans"
	NameSingleWriter       = "single-writer"
	NameReclaims           = "reclaims"

	// Package chaos also reports these, from the stopped server's store and
	// the server's log.
	NameRevoked      = "revoked"
	NameSkewWarning  = "skew-warning"
	NameAttemptOrder = "attempt-order"
	NameDiskFull     = "disk-full"
)

Invariant names, in the order Check returns them.

View Source
const (
	// MaxEvidence is the most evidence entries a Result carries. When there is
	// more, the last entry counts what was left out.
	MaxEvidence = 20
	// MaxKeptViolations is the most violations a Result keeps in full, for
	// a known violation scoped by a pattern to judge. Past it none are kept.
	MaxKeptViolations = 10000
	// DefaultSettle is the settle time when Input.Settle is zero.
	DefaultSettle = 5 * time.Second
	// DefaultLogSettle is the logs settle time when Input.LogSettle is zero.
	// It is longer than DefaultSettle because the log consumer has a backlog
	// of its own that WaitDrained, which waits on job statuses, does not see.
	DefaultLogSettle = 30 * time.Second
)
View Source
const CounterLogsLostInFault = "logs.lost_in_fault"

CounterLogsLostInFault is the logs result's counter of the lines the sampled tasks lost inside fault windows.

Variables

This section is empty.

Functions

func CancelTimes

func CancelTimes(records []driver.ActionRecord) map[string]time.Time

CancelTimes returns, for each job a cancel_jobs action targeted, when the first such action started, for Input.CanceledAt.

func Names

func Names() []string

Names returns every invariant name the harness can report, in the order scenario.CheckNames lists them (the chaos checks included).

func WaitDrained

func WaitDrained(ctx context.Context, v ServerView, farmID string, jobs []driver.SubmittedJob, timeout time.Duration) error

WaitDrained polls the jobs the server holds, the accepted ones and the orphans (a submission with no 2xx answer whose ID the caller set from the farm's job list), until every one is terminal (completed, failed or canceled) and returns nil, or returns an error naming up to 20 of the jobs still open, with their statuses, once timeout has elapsed or ctx has ended. A submission with no ID is ignored. Up to 20 jobs are read one GET at a time; more are read from the farm's job list, 1000 a page.

Types

type Evidence

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

Evidence collects a check's violations, keeping the first MaxEvidence. The zero value is ready to use.

func (*Evidence) Add

func (e *Evidence) Add(s string)

Add adds one violation.

func (*Evidence) AddAll

func (e *Evidence) AddAll(ss []string)

AddAll adds each non-empty violation of ss.

func (*Evidence) AddUnmeasured

func (e *Evidence) AddUnmeasured(s string)

AddUnmeasured adds a line saying the check could not read what it judges.

func (*Evidence) Note

func (e *Evidence) Note(s string)

Note adds a line shown after the violations that fails nothing.

func (*Evidence) Result

func (e *Evidence) Result(name string) Result

Result is the verdict named name: OK when nothing was added, the last evidence entry counting what MaxEvidence left out.

type FaultWindow

type FaultWindow struct {
	Start, End time.Time
	// Groups are the worker groups the fault hit; empty means every group, as
	// for a server or power-cut fault.
	Groups []string
}

FaultWindow is when a network, server or power-cut fault was in effect: from when it fired to when it healed (or, for one that never healed, to the end of the run).

type Input

type Input struct {
	// Jobs are the run's submissions; rejected ones are ignored.
	Jobs []driver.SubmittedJob
	// Ledger is what the simulated workers did. Nil is an empty ledger.
	Ledger *simworker.Ledger
	// Scenario gives each job class's queue, usage pool and log line size,
	// and the farm's caps.
	Scenario *scenario.Scenario
	// PoolNames maps a scenario usage pool name to the server's, for
	// evidence: an attached run's pools are its own, namespaced ones. A
	// missing entry is the scenario's name.
	PoolNames map[string]string
	FarmID    string
	// LiveWorkers is how many workers of the farm are running when Check is
	// called: the simulated fleet's live count plus any real workers.
	LiveWorkers int
	// LogSample is the share of tasks whose logs are compared, 1.0 for all.
	LogSample float64
	// LogOverflowExpected says the scenario overflows the broker's store on
	// purpose, so losing a task's oldest whole chunks is allowed.
	LogOverflowExpected bool
	// AttemptSample is the share of tasks whose attempts are read, 1.0 for
	// all. Each sampled task costs one GET /tasks/{id}/attempts.
	AttemptSample float64
	// Seed picks the sampled tasks: the same seed picks the same tasks.
	Seed uint64
	// CanceledAt is when the first cancel action targeting each job started
	// ([CancelTimes]). A task of one of its jobs may be canceled whatever the
	// simulator did, and caps ends a canceled attempt of one of them no later
	// than that time, when the server may already have freed its slot.
	CanceledAt map[string]time.Time
	// ConvergeWithin is how long the online worker count may take to reach
	// LiveWorkers: the heartbeat timeout plus a margin. Zero checks once.
	ConvergeWithin time.Duration
	// Settle is how long, after the first pass, a task whose outcome
	// disagrees is re-read before the disagreement counts: the ledger records
	// a terminal event just after the server may already have applied it.
	// Zero means DefaultSettle. A disagreeing task is always re-read once.
	Settle time.Duration
	// LogSettle is the same for logs, whose chunks are ingested on a stream of
	// their own. Zero means DefaultLogSettle.
	LogSettle time.Duration
	// Simulated reports whether a worker ID is one of the simulated fleet's.
	// The ledger records only what simulated workers did, so the outcomes and
	// logs checks leave out a task a real sqi-worker ran, and caps does not
	// count its attempts. Nil means every worker is simulated.
	Simulated func(workerID string) bool
	// TaskSeen, when set, is called with every task the checks list, as the
	// server first lists it. Calls come from several goroutines at once.
	TaskSeen func(jobID string, t client.Task)

	// Orphans are the jobs the server created although their submission got
	// no 2xx answer (a timeout, a dropped connection, a 5xx), with ID set to
	// the server's job ID. terminal covers them beside the accepted jobs, and
	// caps counts their attempts.
	Orphans []driver.SubmittedJob
	// FaultWindows are when the run's faults were in effect. A sampled task
	// whose latest attempt overlaps a window that hit its worker may have
	// lost log lines (see the logs invariant).
	FaultWindows []FaultWindow
	// GroupOf names a simulated worker's group. Nil: no worker is in a
	// window's group list, so only a window on every group applies.
	GroupOf func(workerID string) string
}

Input is everything the checks compare.

type LeasedAttempt

type LeasedAttempt struct {
	ID, TaskID, WorkerID string
	// Leased is when the lease reached the worker.
	Leased time.Time
	// End is the attempt's terminal, canceled or crashed event; nil while the
	// worker has not ended it. A worker records one per attempt.
	End *simworker.Event
}

LeasedAttempt is an attempt a simulated worker leased, as the invariant checks read it from the ledger.

func LeasedAttempts

func LeasedAttempts(l *simworker.Ledger) []LeasedAttempt

LeasedAttempts returns every attempt l has a leased event for, in lease order.

func (LeasedAttempt) Outcome

func (a LeasedAttempt) Outcome() string

Outcome is the outcome of the attempt's terminal event, "" when it ended otherwise or has not ended.

type Result

type Result struct {
	Name     string
	OK       bool
	Evidence []string
	Counters map[string]int64 `json:"counters,omitempty"`
	// Known is the tracker of the known violation that excused a failure
	// (several joined with ", "): OK is then true and Evidence says what was
	// found.
	Known string `json:"known,omitempty"`
	// Unmeasured marks a failure that is no finding: the check could not read
	// what it judges, or did not run. A known violation never excuses it.
	Unmeasured bool `json:"unmeasured,omitempty"`
	// Violations is every violation the check found, which Evidence shows
	// only the first MaxEvidence of, and none of its notes; nil for a result
	// not built from [Evidence]. ViolationsCut is set, and Violations nil,
	// when there were more than MaxKeptViolations.
	Violations    []string `json:"-"`
	ViolationsCut bool     `json:"-"`
}

Result is one invariant's verdict. Evidence names the job, task, attempt, queue or pool of each violation with the observed and expected values; it is empty when OK. Counters are what the check measured besides its verdict, such as CounterLogsLostInFault.

func Check

func Check(ctx context.Context, v ServerView, in Input) []Result

Check evaluates the run invariants and returns their results in a fixed order: terminal, outcomes, single-attempt, logs, workers-converge, caps, submission-atomic. Call it once WaitDrained has returned nil and the fleet's churn has stopped, with the fleet still running.

Its server calls: the accepted jobs' and orphans' statuses (one GET each up to 20 jobs, otherwise the farm's job list, 1000 a page), every accepted job's task list (1000 a page), one attempt list for each task sampled at AttemptSample, one log read for each task sampled at LogSample (more for a task over 1000 chunks), the farm's worker list once per poll, and, for submission-atomic, the farm's job list and every orphan's task list.

func Unmeasured

func Unmeasured(msg string, names ...string) []Result

Unmeasured returns a Result for each name, failed and unmeasured with msg as its evidence: the checks could not run.

type ServerView

type ServerView interface {
	GetJob(ctx context.Context, id string) (client.Job, error)
	ListJobs(ctx context.Context, farmID string, limit, offset int) (client.Page[client.Job], error)
	ListTasks(ctx context.Context, jobID string, limit, offset int) (client.Page[client.Task], error)
	ListAttempts(ctx context.Context, taskID string) ([]client.Attempt, error)
	TaskLogs(ctx context.Context, taskID string, after int64, limit int) ([]client.LogLine, int64, error)
	ListWorkers(ctx context.Context, farmID string, limit, offset int) (client.Page[client.Worker], error)
}

ServerView is the part of the server's REST API the checks read. *client.Client satisfies it. The checks do not retry a failed read, so pass a client from client.Client.RetryingReads: a passing fault is then retried, and only one that outlasts the client's retry budget is reported.

Jump to

Keyboard shortcuts

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