fanout

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: GPL-3.0, LGPL-3.0 Imports: 14 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 fanout works on many targets at once, as clusterctl does: the executor that runs a request on every target, the status and the groups of their results, the bound on each host, and the exit code a fan-out that failed somewhere asks for.

The pools themselves, Each, Map and Batches, are those of internal/clikit/fanout, which knows no program; this package gives them clusterctl's name, its rule for the class of an error (exitcode.Class) and the error its commands exit with (Summarize).

The degree of parallelism is bounded and conservative by default: a connection through a tunnel or a jump host is far more fragile than a local one, and a wide fan-out is what makes sshd refuse connections under its MaxStartups limit.

Index

Constants

View Source
const DefaultMax = pool.DefaultMax

DefaultMax is used when nothing configures the fan-out.

View Source
const PerHost = 4

PerHost is how many sessions a command opens to one infrastructure host at once (ADR 0022). By default sshd starts to drop connections once ten are waiting to authenticate, and a role that multiplexes its connections carries at most ten sessions on one; four leaves room for the other administrators and for the jobs of the host itself.

Variables

View Source
var ErrNotTried = pool.ErrNotTried

ErrNotTried is the error of a batch that was not run because one before it failed.

Functions

func Each added in v0.4.0

func Each(ctx context.Context, n, limit int, work func(i int))

Each calls work with every index below n, at most limit at a time, as internal/clikit/fanout's Each does.

func FailureError added in v0.4.0

func FailureError(results []*transport.Result) error

FailureError turns the targets of a fan-out that failed into the error the command exits with, as Summarize makes it of the hosts that failed. The errors are kept underneath, not only their text, so that a caller can still tell a cancellation from a failure. It is nil when every target succeeded.

func Failures

func Failures(results []*transport.Result) []*transport.Result

Failures returns the results that did not succeed.

func IsSkipped added in v0.4.0

func IsSkipped(err error) bool

IsSkipped reports whether err says that an item was left out on purpose.

func Recovered added in v0.3.0

func Recovered(log io.Writer, target string, v any) error

Recovered turns a panic in the work for one target into that target's error, as internal/clikit/fanout's Recovered does for clusterctl, with the exit code of a target that failed.

func Skip added in v0.4.0

func Skip(reason string) error

Skip returns the error of work that leaves its item out on purpose, as internal/clikit/fanout's Skip does.

func Status added in v0.3.0

func Status(r *transport.Result) string

Status says in a word how a target ended: "ok", "exit N", "unreachable" when the transport could not reach it, or "interrupted" when it was cancelled.

func Summarize added in v0.4.0

func Summarize(noun string, n int, names []string, errs []error, interrupted bool) error

Summarize is the error a fan-out of n that did not succeed everywhere exits with: internal/clikit/fanout's Failure, "k of n <noun> failed: <node set>", with the code exitcode.Worst gives the items' errors, or TargetFailed when none of them says, since a command that exited non-zero is a target that failed. Its progress class is that of the code, not of whichever of the items' errors says a class first, or canceled when interrupted says that the interrupt ended the items. It is nil when none failed.

Types

type Batch added in v0.4.0

type Batch = pool.Batch

Batch is what came of one batch of Batches.

func Batches added in v0.4.0

func Batches(ctx context.Context, nodes *nodeset.NodeSet, o BatchOptions, run func(ctx context.Context, batch *nodeset.NodeSet) error) []Batch

Batches runs a node set in batches, as internal/clikit/fanout's Batches does.

type BatchOptions added in v0.4.0

type BatchOptions = pool.BatchOptions

BatchOptions say how Batches splits a node set and reports its work.

type Executor

type Executor struct {
	// Runner performs one request; a Recorder stands in for a dry run.
	Runner transport.Runner
	// Max is how many targets are worked on at once.
	Max int
	// Step names the step a display shows the targets under; empty is
	// "run".
	Step string
	// Flags are given to that step, such as progress.ShowLines for a
	// command whose output is the product.
	Flags progress.Flags
	// PanicLog receives the stack of a panic in a worker; nil is the
	// process's standard error.
	PanicLog io.Writer
	// Answers says that a result that failed is an answer all the same,
	// for a command that reports it, as provision status reports which
	// nodes ssh reaches: every target ends well, but for one the context
	// ended. The results are the same either way.
	Answers bool
}

Executor runs requests on many targets.

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, targets []transport.Target, req transport.Request) []*transport.Result

Run executes the same request on every target.

func (*Executor) RunEach

func (e *Executor) RunEach(ctx context.Context, targets []transport.Target, build func(transport.Target) transport.Request) []*transport.Result

RunEach executes a request built per target, which is how a command sends each node its own arguments.

Results come back in the order the targets were given, whatever order they finished in, so output is reproducible. A target that fails does not stop the others: the point of a fan-out is to learn about every node. It runs on Map, and is reported as Map reports its work. A panic in the runner or in build becomes the target's failure rather than the end of the process.

type Group

type Group struct {
	// Nodes are the targets that produced this output.
	Nodes *nodeset.NodeSet `json:"nodes" yaml:"nodes"`
	// Output is the standard output they shared, exactly as it came.
	Output string `json:"output" yaml:"output"`
	// ExitCode is the status they shared.
	ExitCode int `json:"exitCode" yaml:"exitCode"`
	// Status says how they ended, as Status reports it.
	Status string `json:"status" yaml:"status"`
}

Group is a set of targets that produced identical output.

func GroupByOutput

func GroupByOutput(results []*transport.Result) ([]Group, error)

GroupByOutput collects targets that answered the same thing, which turns the output of a thousand nodes into the handful of answers worth reading.

Targets are grouped only when both their output and the way they ended are the same: for grep -q or test -e the status is the whole answer, and a node that could not be reached said nothing, which is not the same as a node that answered with nothing. Output that differs only in blank lines at the end is not the same output either.

Groups come back largest first, and equally sized groups in node set order, so two runs of the same command print the same thing.

A group holds its targets as a node set, so a target whose name is not one host name cannot be put into one: it would be read as an expression, or lost. GroupByOutput then returns an error naming it rather than groups that drop or miscount it.

type Hosts added in v0.4.0

type Hosts struct {
	// Limit is how many may be under way on one host; below one is
	// PerHost.
	Limit int
	// contains filtered or unexported fields
}

Hosts bounds the work under way on each host: at most Limit at a time on any one of them, however many hosts a pool works on at once. The zero value bounds each host to PerHost, and a Hosts is safe for concurrent use; one Hosts shared by pools side by side bounds them together.

func (*Hosts) Acquire added in v0.4.0

func (h *Hosts) Acquire(ctx context.Context, hosts ...string) (release func(), err error)

Acquire takes a place on every host it is given, waiting while one of them is full, and returns the function that gives them back, which may be called more than once. The places are taken in the order of the hosts' names, whatever order they are given in, so two callers that need the same two hosts cannot each hold one and wait for the other; a host given twice, or an empty name, takes no second place. Once ctx has ended nothing is taken: what was is given back, and the context's error returned.

type Options added in v0.4.0

type Options[T any] = pool.Options[T]

Options say how Map works on its items and how it reports them, as internal/clikit/fanout has them.

type Outcome added in v0.4.0

type Outcome[R any] = pool.Outcome[R]

Outcome is what the work for one item came to.

func Map added in v0.4.0

func Map[T, R any](ctx context.Context, items []T, o Options[T], fn func(ctx context.Context, item T) (R, error)) []Outcome[R]

Map is internal/clikit/fanout's Map as clusterctl runs it: a panic is clusterctl's, and the error it becomes asks for the exit code of a target that failed, as Recovered's does; the class of an error that says none of its own is that of its exit code; and the step ends with Summarize's error, which asks for the exit code the worst of the items' errors does. An Options that sets the program, the class or the summary keeps it.

Directories

Path Synopsis
Package fanouttest counts the calls a fake is in the middle of, so that a test can tell how many of them a fan-out ran at once: the requests a transport.Runner is asked to run, those an http.RoundTripper sends to a service processor and the connections a host key scan dials.
Package fanouttest counts the calls a fake is in the middle of, so that a test can tell how many of them a fan-out ran at once: the requests a transport.Runner is asked to run, those an http.RoundTripper sends to a service processor and the connections a host key scan dials.

Jump to

Keyboard shortcuts

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