probe

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 34 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 implements the client-side probe runtime (ADR 0034, ADR 0035): joining a cluster, managing the voter candidate list, maintaining the local heartbeat buffer, streaming monitor assignments, and uploading heartbeats with keepalive, tick-timeout failover, and CA bundle verification.

Index

Constants

View Source
const (
	BlockedTarget = "target"
	BlockedMethod = "method"
	BlockedType   = "type"
)

Reasons of a local policy block (ADR 0044, section 4); they are metric label values.

View Source
const TargetPolicyCapability = "target-policy"

TargetPolicyCapability is announced when PROBE_ALLOW_TARGETS restricts the targets; the cluster only displays it (ADR 0044, section 5).

Variables

View Source
var ErrCertRejected = errors.New("probe certificate rejected by cluster; re-join required")

ErrCertRejected is returned when the cluster permanently rejects the probe's certificate (revoked or foreign CA) and the probe must exit and re-join.

Functions

func GuardRegistry added in v0.0.5

func GuardRegistry(base *checker.Registry, o GuardOptions) (*checker.Registry, error)

GuardRegistry returns a registry with every checker of base wrapped in the local policy. Types and methods are checked before a check runs, so a blocked check opens no connection; results are reduced before they reach the local buffer, so what is dropped is never stored or sent.

func ParseSeed

func ParseSeed(raw string) (string, error)

ParseSeed validates and normalizes a seed address. It accepts "host:port" or "https://host:port" (with an optional trailing "/"), and rejects "http://", paths, queries, fragments, and empty hosts or ports.

Types

type Buffer

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

Buffer tracks acknowledgment watermarks and enforces retention and size limits on the probe's local heartbeat buffer.

func NewBuffer

func NewBuffer(ctx context.Context, opts BufferOptions) (*Buffer, error)

NewBuffer initializes a Buffer, loading persisted watermarks from opts.Store.

func (*Buffer) AckedSeq

func (b *Buffer) AckedSeq() uint64

AckedSeq returns the highest acknowledged sequence number.

func (*Buffer) Cleanup

func (b *Buffer) Cleanup(ctx context.Context) error

Cleanup enforces retention and size limits in the order defined by ADR 0034 section 5: 1. Delete acked heartbeats whose AckRetain window has elapsed. 2. Delete unacked heartbeats older than MaxAge (updating lostBelow and droppedTotal). 3. Vacuum and delete oldest heartbeats while DBSizeBytes exceeds MaxBytes.

func (*Buffer) DroppedTotal

func (b *Buffer) DroppedTotal() uint64

DroppedTotal returns the cumulative number of unacknowledged heartbeats dropped.

func (*Buffer) LostBelow

func (b *Buffer) LostBelow() uint64

LostBelow returns the lowest sequence number not known to be lost.

func (*Buffer) RecordAck

func (b *Buffer) RecordAck(ctx context.Context, seq uint64) error

RecordAck records a monotonic acknowledgment watermark and persists it.

func (*Buffer) RunCleanup

func (b *Buffer) RunCleanup(ctx context.Context, interval time.Duration)

RunCleanup runs Cleanup periodically until ctx is canceled.

func (*Buffer) StartAfter

func (b *Buffer) StartAfter(ctx context.Context, voterPos uint64) (uint64, error)

StartAfter computes the starting sequence number for resuming upload to a voter reporting voterPos: max(voterPos, minSeq-1) when minSeq > 0, else voterPos.

func (*Buffer) Status

func (b *Buffer) Status(ctx context.Context) (*pb.ProbeBufferStatus, error)

Status returns the current probe buffer fill and drop statistics.

type BufferOptions

type BufferOptions struct {
	Store     BufferStore
	NodeID    string
	AckRetain time.Duration
	MaxAge    time.Duration
	MaxBytes  int64
	Now       func() time.Time
	Log       *slog.Logger
}

BufferOptions configures a probe heartbeat Buffer.

type BufferStore

type BufferStore interface {
	Incarnation() string
	Watermark(ctx context.Context, name string) (int64, error)
	SetWatermark(ctx context.Context, name string, value int64) error
	MinSeq(ctx context.Context, nodeID, incarnation string) (uint64, error)
	LastSeq(ctx context.Context, nodeID, incarnation string) (uint64, error)
	UnackedStats(ctx context.Context, nodeID, incarnation string, afterSeq uint64) (uint64, int64, error)
	DeleteStreamHeartbeatsUpTo(ctx context.Context, nodeID, incarnation string, maxSeq uint64, limit int) (int64, error)
	DeleteStreamHeartbeatsOlderThan(ctx context.Context, nodeID, incarnation string, afterSeq uint64, beforeMs int64, limit int) (int64, uint64, error)
	DeleteOldestStreamHeartbeats(ctx context.Context, nodeID, incarnation string, ackedSeq uint64, limit int) (int64, int64, uint64, error)
	DBSizeBytes(ctx context.Context) (int64, error)
	IncrementalVacuum(ctx context.Context, pages int) error
}

BufferStore defines the persistence operations required by Buffer. It is satisfied by *sqlite.MetricsStore.

type Client

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

Client manages the probe's outbound mTLS connection to a voter, subscribes to monitor assignments, handles failover, renews certificates and CA bundles, and uploads buffered and live heartbeats.

func NewClient

func NewClient(opts ClientOptions) (*Client, error)

NewClient constructs a probe Client.

func (*Client) NotifyNewHeartbeats

func (c *Client) NotifyNewHeartbeats(_ []store.Heartbeat)

NotifyNewHeartbeats wakes the upload loop after new heartbeats are stored. It is non-blocking and safe to pass to HeartbeatWriter.SetOnStored.

func (*Client) Ready

func (c *Client) Ready() error

Ready reports whether the probe has an active voter session and received its initial assignment snapshot.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run maintains a probe session across voter failovers until ctx is cancelled or the cluster permanently rejects the probe certificate (ErrCertRejected).

type ClientOptions

type ClientOptions struct {
	NodeID               string
	Name                 string
	Region               string
	Labels               map[string]string
	Capabilities         []string
	Version              string
	Cert                 *clusterpki.NodeCert
	Voters               *VoterList
	Buffer               *Buffer
	Metrics              UploadMetricsStore
	Sync                 MonitorSync
	Policy               *Policy
	SessionTimeout       time.Duration
	ConnectTimeout       time.Duration
	BackoffMin           time.Duration
	BackoffMax           time.Duration
	MaxUploadWindow      int
	UploadBatchSize      int
	RenewalCheckInterval time.Duration
	Dial                 func(ctx context.Context, addr string) (*grpc.ClientConn, error)
	RandIntN             func(int64) int64
	Clock                func() time.Time
	Log                  *slog.Logger
}

ClientOptions configure a probe Client.

type GuardOptions added in v0.0.5

type GuardOptions struct {
	// Types are the allowed monitor types; nil allows every registered type.
	Types []string
	// Methods are the allowed HTTP methods; nil allows every method.
	Methods *probepolicy.Methods
	// Detail is probepolicy.DetailFull or probepolicy.DetailMinimal.
	Detail string
	// HideTargets replaces the message of results blocked by the address
	// policy, so neither address nor port of an internal target leaves a
	// private probe.
	HideTargets bool
	// OnBlocked is called with BlockedTarget, BlockedMethod or BlockedType
	// for every blocked check; nil disables it.
	OnBlocked func(reason string)
}

GuardOptions is the local check policy of a probe (ADR 0044).

type MonitorSync

type MonitorSync interface {
	Sync(monitors []store.Monitor)
}

MonitorSync receives the current set of monitors assigned to the probe.

type Policy

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

Policy enforces SSRF protection for probe checks (ADR 0035 section 4). Private probes use only their local policy (remote ProbeMonitor.ssrf_protection is ignored). Public probes enforce the union of local and remote policies so neither side can weaken protection.

func NewPolicy

func NewPolicy(localSSRF, privateProbe bool) *Policy

NewPolicy builds an address policy for a probe.

func (*Policy) Check

func (p *Policy) Check(ip netip.Addr) error

Check implements checker.AddressPolicy. Without a port it serves ICMP and DNS answers: the target policy then accepts an address on any port.

func (*Policy) CheckAddrPort added in v0.0.5

func (p *Policy) CheckAddrPort(ap netip.AddrPort) error

CheckAddrPort implements checker.AddrPortPolicy for TCP and UDP connections.

func (*Policy) SetRemote

func (p *Policy) SetRemote(enabled bool)

SetRemote updates whether any assigned monitor requires SSRF protection. Private probes ignore this flag.

func (*Policy) WithTargets added in v0.0.5

func (p *Policy) WithTargets(t *probepolicy.Targets) *Policy

WithTargets adds the local target policy (PROBE_ALLOW_TARGETS, ADR 0044). It only narrows the policy: a connection must pass both. Call it before the policy is used.

type PrepareOptions

type PrepareOptions struct {
	DataDir      string
	NodeID       string
	Name         string
	Seeds        []string
	Token        string
	Region       string
	Labels       map[string]string
	Capabilities []string
	Version      string
	Incarnation  string
	Log          *slog.Logger
	Clock        func() time.Time
}

PrepareOptions configure probe identity loading and initial cluster join.

type UploadMetricsStore

type UploadMetricsStore interface {
	HeartbeatsAfter(ctx context.Context, nodeID, incarnation string, afterSeq, untilSeq uint64, limit int) ([]store.Heartbeat, bool, error)
}

UploadMetricsStore reads buffered heartbeats for upload.

type VoterList

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

VoterList manages the deduplicated union of configured seeds and learned voter addresses, persisted to DATA_DIR/probe/voters.json.

func NewVoterList

func NewVoterList(dataDir string, seeds []string, shuffleRand func(n int) int) (*VoterList, error)

NewVoterList creates a VoterList by parsing seeds, loading any persisted voters.json from dataDir/probe/voters.json, merging the union (seeds first, then learned voters, deduplicated), and shuffling once at startup.

func Prepare

Prepare loads the probe's certificate and voter list, joining the cluster on the first start when no certificate exists yet (ADR 0034 section 2).

func (*VoterList) Candidates

func (v *VoterList) Candidates() []string

Candidates returns a copy of the current candidate addresses in rotation order.

func (*VoterList) Update

func (v *VoterList) Update(voters []*pb.NodeInfo) error

Update updates the learned voter set from voters. It only writes voters.json when the sorted set of learned voter addresses changes. New voters are appended to the candidate list while preserving the existing rotation order.

Jump to

Keyboard shortcuts

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