edge

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package edge is the agent: it polls the central, runs probes and reports results.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("the central refused the token")

ErrUnauthorized is returned when the central refuses the token.

Functions

func DoctorSteps added in v1.1.0

func DoctorSteps(cfg DoctorConfig) []doctor.Step

DoctorSteps checks, in order, everything an edge needs to work: the settings, the name of the central, the network path to it, its certificate, its health, the token and the clock.

func TLSConfig added in v1.1.0

func TLSConfig(caFile, certFile, keyFile string) (*tls.Config, error)

TLSConfig trusts the system roots and the CA file, if any, and presents the client certificate, if any. The certificate is read at each handshake, so a renewed one is used without a restart.

Types

type Agent

type Agent struct {
	Client         *Client
	Measure        Measurer
	Interval       time.Duration // between two polls
	ReportInterval time.Duration // between two reports
	Log            *slog.Logger
}

Agent polls the central for checks, runs them and reports the results.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context)

Run works until ctx is cancelled. A failed poll is logged and retried at the next tick. On the way out the measurements stop first, then what is still queued is sent once.

type Client added in v1.1.0

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

Client talks to the edge API of the central.

func NewClient added in v1.1.0

func NewClient(central, token string, opts ...ClientOption) (*Client, error)

NewClient checks the central URL and prepares a client. A token is never sent over plain HTTP unless the central is on this machine.

func (*Client) Assignments added in v1.1.0

func (c *Client) Assignments(ctx context.Context) (checks []api.Check, changed bool, err error)

Assignments fetches the checks to run. changed is false when the central answered that nothing differs from the previous call.

func (*Client) PostResults added in v1.1.0

func (c *Client) PostResults(ctx context.Context, results []api.Result) error

PostResults sends a batch of results.

type ClientOption added in v1.1.0

type ClientOption func(*Client)

ClientOption changes how a Client talks to the central.

func WithTLS added in v1.1.0

func WithTLS(cfg *tls.Config) ClientOption

WithTLS sets the TLS settings of the connection, for a private CA or a client certificate.

type DoctorConfig added in v1.1.0

type DoctorConfig struct {
	Central string
	Token   string
	// TLS holds the private CA and the client certificate; nil means the system
	// trust store and no client certificate.
	TLS *tls.Config
}

DoctorConfig is what the edge diagnostics need.

type Measurer added in v1.1.0

type Measurer func(ctx context.Context, c api.Check) api.Result

Measurer runs one check and describes the outcome.

func ProbeMeasurer added in v1.1.0

func ProbeMeasurer(p *probe.Prober) Measurer

ProbeMeasurer runs each check with the probe of its kind.

type Reporter added in v1.1.0

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

Reporter queues results and sends them to the central in batches. While the central is unreachable the results wait in memory, up to maxQueued; the oldest are dropped first.

func NewReporter added in v1.1.0

func NewReporter(post poster, interval time.Duration, log *slog.Logger) *Reporter

NewReporter sends what was queued every interval.

func (*Reporter) Add added in v1.1.0

func (r *Reporter) Add(res api.Result)

Add queues one result; it is safe to call from several goroutines.

func (*Reporter) Run added in v1.1.0

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

Run flushes on every tick, and a last time when ctx ends.

type Scheduler

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

Scheduler runs each assigned check on its own interval and hands the results to a sink, which is called from several goroutines.

func NewScheduler

func NewScheduler(ctx context.Context, measure Measurer, sink func(api.Result)) *Scheduler

NewScheduler starts with no checks; the context ends every one of them.

func (*Scheduler) Apply

func (s *Scheduler) Apply(checks []api.Check)

Apply makes the running checks match the assignment: new ones start, changed ones restart, missing ones stop.

func (*Scheduler) Stop added in v1.1.0

func (s *Scheduler) Stop()

Stop ends every check and waits until none is running.

type StatusError added in v1.1.0

type StatusError struct {
	Op     string
	Code   int
	Status string
}

StatusError is an answer of the central that is neither a success nor an authentication failure.

func (*StatusError) Error added in v1.1.0

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

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