probe

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 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 probe measures, for the console's scheduling, whether the scheduling addresses of edge nodes answer (ProbeService, proto v0.14.0). `edgeweir-node probe` runs it with a probe identity; a node the console lets probe its peers runs it with its node identity.

One attempt per method:

TCP    connect, then close; the RTT is the connect time.
HTTP   connect, GET /.edgeweir/health with Host health.edgeweir.invalid;
       success only on status 200.
HTTPS  connect, TLS with SNI health.edgeweir.invalid, then the same GET.

For HTTP and HTTPS the RTT is the time from sending the request to the status line: one round trip on the established connection, like TCP's connect time, so the values of all methods compare. With proxy_protocol a PROXY protocol v1 line built from the socket's own addresses comes first.

HTTPS never verifies the node's certificate (InsecureSkipVerify): nodes answer SNI health.edgeweir.invalid with a self-signed certificate each generates for itself, so there is nothing a probe could verify it against. The probe only measures reachability: it sends no secret, and nothing but the status line of the answer is used.

Index

Constants

View Source
const (
	HealthPath = "/.edgeweir/health"
	// HealthHost is the Host of health requests and the SNI of HTTPS
	// probes; nodes answer it with their self-signed health certificate.
	HealthHost = "health.edgeweir.invalid"
)

The health endpoint nodes answer before any site lookup (feature probe-health-v1).

View Source
const (
	ErrTimeout     = "timeout"
	ErrRefused     = "refused"
	ErrReset       = "reset"
	ErrTLS         = "tls"
	ErrStatus      = "status"
	ErrUnreachable = "unreachable"
)

Error codes of ProbeResult.error.

View Source
const (
	DefaultInterval = 10 * time.Second
	DefaultTimeout  = 3 * time.Second
	DefaultAttempts = 3
)

Round settings when the console leaves them out, and their bounds (proto: interval 5-60 s, timeout 500-10000 ms, attempts 1-10).

View Source
const DefaultConcurrency = 32

DefaultConcurrency is the number of targets probed at the same time.

Variables

View Source
var ErrNotEnrolled = errors.New("probe is not enrolled: the first run needs --server, --ca-sha256 and a probe token " +
	"(EDGEWEIR_TOKEN, --token-file or --token)")

ErrNotEnrolled is returned by Main when the state directory holds no probe identity and the enrollment settings are incomplete.

Functions

func Classify

func Classify(err error) string

Classify maps a connection error to an error code.

func Info

func Info() *nodev1.ProbeInfo

Info describes this process in GetProbeTargets and EnrollProbe.

func Main

func Main(ctx context.Context, o Options) error

Main enrolls the probe on its first start and then runs rounds until ctx is done. A token given once the probe is enrolled is ignored. It never starts OpenResty.

func MedianMillis

func MedianMillis(rtts []time.Duration) uint32

MedianMillis is the median of rtts in milliseconds, rounded, and at least 1 when there is any RTT (0 means "no successful attempt").

func ProxyV1Header

func ProxyV1Header(local, remote net.Addr) string

ProxyV1Header is the PROXY protocol v1 line for a connection from local to remote: "PROXY TCP4|TCP6 <src> <dst> <sport> <dport>\r\n", or "PROXY UNKNOWN\r\n" when the addresses are not TCP addresses of one family.

func Supported

func Supported(t *nodev1.ProbeTarget) bool

Supported reports whether a target can be probed: an IP literal, a port and a known method. Other targets are left out of a round.

Types

type Options

type Options struct {
	// Enrollment (first run only): console node-channel URL, one-time
	// probe token, CA pin and an optional TLS server name.
	ServerURL  string
	Token      string
	CASHA256   string
	ServerName string
	// StateDir holds the probe identity (probe.key 0600, probe.crt, ca.crt,
	// probe.json).
	StateDir string
	// Timeout bounds every RPC, the enrollment included (default 30s).
	Timeout time.Duration
	Log     *slog.Logger

	// Tests: the prober and the backoff bounds of enrollment retries and
	// failed rounds (defaults 1s and 30s / 60s).
	Prober     *Prober
	BackoffMin time.Duration
	BackoffMax time.Duration
	// Following the console's address (controlplane.Follower; zero values
	// take its defaults).
	FailoverAfter time.Duration
	RetryPrimary  time.Duration
	FollowBackoff []time.Duration
}

Options configure a standalone probe (`edgeweir-node probe`).

type Prober

type Prober struct {
	// Dial opens TCP connections (default: net.Dialer).
	Dial func(ctx context.Context, network, address string) (net.Conn, error)
	// Concurrency bounds the targets probed at the same time (default 32).
	Concurrency int
}

Prober probes targets.

func (*Prober) Probe

func (p *Prober) Probe(ctx context.Context, t *nodev1.ProbeTarget, timeout time.Duration, attempts int) *nodev1.ProbeResult

Probe makes attempts attempts one after another (fewer when ctx ends) and summarizes them: sent, lost, the median RTT of the successful ones and the error code of the last failure.

func (*Prober) ProbeAll

func (p *Prober) ProbeAll(ctx context.Context, targets []*nodev1.ProbeTarget, timeout time.Duration, attempts int) []*nodev1.ProbeResult

ProbeAll probes every target (at most Concurrency at a time) and returns the results in the order of targets.

type Runner

type Runner struct {
	// Client returns the ProbeService client (it changes when the
	// credentials are reloaded).
	Client func() nodev1connect.ProbeServiceClient
	// Info describes this process in GetProbeTargets.
	Info *nodev1.ProbeInfo
	// SkipNodeID: targets of this node are left out (a node never probes
	// itself).
	SkipNodeID string
	// Renew renews the client certificate when the console asks for it
	// (renew_certificate) or NeedsRenewal reports it due. Nil when the
	// certificate is renewed elsewhere (a node renews through NodeService).
	Renew        func(ctx context.Context, reason string)
	NeedsRenewal func() bool
	Prober       *Prober
	Log          *slog.Logger
	// Follow moves a standalone probe to the console's node channel address
	// (rounds carry its status and take the address); nil for a node,
	// which follows through its heartbeats.
	Follow *controlplane.Follower
	// RPCTimeout bounds each call (default 30s); BackoffMin and BackoffMax
	// bound the wait after a failed round (default 1s and 60s).
	RPCTimeout time.Duration
	BackoffMin time.Duration
	BackoffMax time.Duration
}

Runner runs probe rounds: GetProbeTargets, probe, ReportProbeResults, then the next round interval_seconds after the start of this one (at once when a round took longer). Errors back off exponentially.

func (*Runner) Round

func (r *Runner) Round(ctx context.Context) (time.Duration, error)

Round runs one round and returns the interval until the next one.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context)

Run runs rounds until ctx is done.

type Settings

type Settings struct {
	Interval time.Duration
	Timeout  time.Duration
	Attempts int
}

Settings are the timing of one round.

func SettingsFrom

func SettingsFrom(r *nodev1.GetProbeTargetsResponse) Settings

SettingsFrom takes the round settings from a GetProbeTargets response: zero values get the defaults, others are clamped to the proto's bounds.

Jump to

Keyboard shortcuts

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