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
- Variables
- func GuardRegistry(base *checker.Registry, o GuardOptions) (*checker.Registry, error)
- 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 GuardOptions
- type MonitorSync
- type Policy
- type PrepareOptions
- type UploadMetricsStore
- type VoterList
Constants ¶
const ( BlockedTarget = "target" BlockedMethod = "method" BlockedType = "type" )
Reasons of a local policy block (ADR 0044, section 4); they are metric label values.
const TargetPolicyCapability = "target-policy"
TargetPolicyCapability is announced when PROBE_ALLOW_TARGETS restricts the targets; the cluster only displays it (ADR 0044, section 5).
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 ¶
func GuardRegistry ¶ added in v0.0.5
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.
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 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 ¶
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 (*Policy) Check ¶
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
CheckAddrPort implements checker.AddrPortPolicy for TCP and UDP connections.
func (*Policy) SetRemote ¶
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 ¶
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.