selfcheck

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 13 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 selfcheck probes the reference targets of a node to tell whether the node itself has lost its connectivity (ADR 0022, FA-CON-04). A round counts as failed only when every target fails; a single reachable target proves that egress works.

Index

Constants

View Source
const (
	DefaultInterval = 30 * time.Second
	DefaultTimeout  = 5 * time.Second
)

Defaults for Options fields that are left at their zero value (ADR 0022).

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Targets  []Target
	Dialer   *checker.Dialer
	Interval time.Duration // default DefaultInterval
	Timeout  time.Duration // per target, default DefaultTimeout
	Now      func() time.Time
	Logger   *slog.Logger
}

Options configures a Prober. Dialer is required: it is the SSRF-aware dialer of the checkers, so self-checks obey the same address policy.

type Prober

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

Prober runs the reference targets periodically. Status may be called concurrently with Run.

func New

func New(opts Options) (*Prober, error)

New validates opts and returns a Prober. It does not start any probing.

func (*Prober) Run

func (p *Prober) Run(ctx context.Context)

Run probes immediately and then every Interval until ctx is done. It returns at once when no targets are configured.

func (*Prober) Status

func (p *Prober) Status() Status

Status returns the state of the latest completed round.

type Remote

type Remote struct {
	Status Status
	// ReceivedAt is the local time at which the answer arrived.
	ReceivedAt time.Time
	// Age is how old the round was when the peer answered, on the peer's clock.
	Age time.Duration
}

Remote is the self-check state of a peer as the leader last received it through GetStatus (ADR 0022). Ages are kept apart from the clocks: the peer reports its own wall clock, so its round age does not depend on the skew.

func (Remote) AgeAt

func (r Remote) AgeAt(now time.Time) time.Duration

AgeAt returns the age of the round at now (local clock): the age at the answer plus the time since then.

type Status

type Status struct {
	// Configured is true when at least one target is configured.
	Configured bool
	// Failed is true when all targets failed in the latest round.
	Failed bool
	// AtMs is the Unix time in milliseconds of the latest completed round; 0
	// before the first round.
	AtMs int64
}

Status is the result of the latest completed round.

type Target

type Target struct {
	// Label is the log-safe form: host:port for TCP, scheme://host[:port] for
	// HTTP. It never contains a path or query.
	Label string
	// Addr is host:port of a TCP target; empty for HTTP targets.
	Addr string
	// URL is the http(s) URL that is sent a HEAD request; empty for TCP targets.
	URL string
}

Target is one parsed reference target.

func ParseTargets

func ParseTargets(entries []string) ([]Target, error)

ParseTargets parses SELF_CHECK_TARGETS entries. Each entry is either host:port (TCP connect) or an http(s) URL (HTTP HEAD). Blank entries are skipped. All invalid entries are reported together; each error names its entry.

Jump to

Keyboard shortcuts

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