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 ¶
- Variables
- func ParseSeed(raw string) (string, error)
- type Buffer
- func (b *Buffer) AckedSeq() uint64
- func (b *Buffer) Cleanup(ctx context.Context) error
- func (b *Buffer) DroppedTotal() uint64
- func (b *Buffer) LostBelow() uint64
- func (b *Buffer) RecordAck(ctx context.Context, seq uint64) error
- func (b *Buffer) RunCleanup(ctx context.Context, interval time.Duration)
- func (b *Buffer) StartAfter(ctx context.Context, voterPos uint64) (uint64, error)
- func (b *Buffer) Status(ctx context.Context) (*pb.ProbeBufferStatus, error)
- type BufferOptions
- type BufferStore
- type Client
- type ClientOptions
- type MonitorSync
- type Policy
- type PrepareOptions
- type UploadMetricsStore
- type VoterList
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) Cleanup ¶
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 ¶
DroppedTotal returns the cumulative number of unacknowledged heartbeats dropped.
func (*Buffer) RunCleanup ¶
RunCleanup runs Cleanup periodically until ctx is canceled.
func (*Buffer) StartAfter ¶
StartAfter computes the starting sequence number for resuming upload to a voter reporting voterPos: max(voterPos, minSeq-1) when minSeq > 0, else voterPos.
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 ¶
NotifyNewHeartbeats wakes the upload loop after new heartbeats are stored. It is non-blocking and safe to pass to HeartbeatWriter.SetOnStored.
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 MonitorSync ¶
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.
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 ¶
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 ¶
func Prepare(ctx context.Context, opts PrepareOptions) (*clusterpki.NodeCert, *VoterList, error)
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 ¶
Candidates returns a copy of the current candidate addresses in rotation order.