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
- Variables
- func Classify(err error) string
- func Info() *nodev1.ProbeInfo
- func Main(ctx context.Context, o Options) error
- func MedianMillis(rtts []time.Duration) uint32
- func ProxyV1Header(local, remote net.Addr) string
- func Supported(t *nodev1.ProbeTarget) bool
- type Options
- type Prober
- type Runner
- type Settings
Constants ¶
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).
const ( ErrTimeout = "timeout" ErrRefused = "refused" ErrReset = "reset" ErrTLS = "tls" ErrStatus = "status" ErrUnreachable = "unreachable" )
Error codes of ProbeResult.error.
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).
const DefaultConcurrency = 32
DefaultConcurrency is the number of targets probed at the same time.
Variables ¶
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 Main ¶
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 ¶
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 ¶
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.
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.
type Settings ¶
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.