Documentation
¶
Overview ¶
Package monitor implements yarilo-monitor: a sidecar health checker that probes backend pods via IMAP/POP3/LMTP login and reports state changes to the director (BACKEND-FLUSH on failure, BACKEND-UP on recovery).
Backend list is sourced dynamically from the director ring:
- HOST handshake lines seed the initial set on connect
- RING-CHANGE pushes add/remove backends as pods scale in/out
Credentials are looked up per-tag; all backends in the same tag share the same monitoring account (user/password).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackendEvent ¶
type BackendEvent struct {
IP string
Port int // populated from HOST handshake lines; 0 for RING-CHANGE events
Tag string
Event string // "up" | "down" | "flush"
}
BackendEvent describes a change in the director ring received by the monitor.
type BackendMonitor ¶
type BackendMonitor struct {
// contains filtered or unexported fields
}
BackendMonitor polls one backend pod in a loop and reports state changes to the director via dc. One goroutine per backend IP.
func (*BackendMonitor) Run ¶
func (b *BackendMonitor) Run(ctx context.Context)
Run polls until ctx is cancelled or the drain timeout expires after a FLUSH.
type Config ¶
type Config struct {
DirectorAddr string `koanf:"director_addr"`
Interval int `koanf:"interval"` // seconds between polls; default 10
Timeout int `koanf:"timeout"` // seconds per probe attempt; default 3
RetryCount int `koanf:"retry_count"` // consecutive failures before rapid poll; default 3
RapidRounds int `koanf:"rapid_rounds"` // rapid poll iterations; default 10
RapidFailsNeeded int `koanf:"rapid_fails_needed"` // rapid poll failures to declare down; default 7
DrainTimeout int `koanf:"drain_timeout"` // seconds from FLUSH to BACKEND-DOWN; default 60
// Protocol probes — applied to every backend in the ring.
PollIMAP bool `koanf:"poll_imap"`
IMAPPort int `koanf:"imap_port"` // default 993
PollPOP3 bool `koanf:"poll_pop3"`
POP3Port int `koanf:"pop3_port"` // default 110
PollLMTP bool `koanf:"poll_lmtp"`
LMTPPort int `koanf:"lmtp_port"` // default 24
// Tags maps tag name → monitoring credentials.
// The tag is the same label used on backends, users, and storage.
// The empty string key "" covers untagged backends.
Tags map[string]TagConfig `koanf:"tags"`
}
Config holds yarilo-monitor settings loaded from YAML.
Example:
director_addr: "127.0.0.1:9102"
interval: 10
timeout: 3
retry_count: 3
rapid_rounds: 10
rapid_fails_needed: 7
poll_imap: true
imap_port: 993
poll_pop3: false
pop3_port: 110
poll_lmtp: false
lmtp_port: 24
# Per-tag monitoring credentials.
# Tag is the join key between backends, users, storage, and monitor accounts.
tags:
"": # default / untagged backends
user: monitor@example.com
password: secret
ssd:
user: monitor-ssd@example.com
password: ssd-secret
type DirectorClient ¶
type DirectorClient struct {
// contains filtered or unexported fields
}
DirectorClient maintains a persistent TCP connection to the director. It reads ring-change events (which drive the backend pool) and writes health reports (BACKEND-UP / BACKEND-FLUSH) on the same connection.
Reconnects automatically with exponential backoff.
func NewDirectorClient ¶
func NewDirectorClient(addr string) *DirectorClient
NewDirectorClient creates a client for the given director address.
func (*DirectorClient) Events ¶
func (d *DirectorClient) Events() <-chan BackendEvent
Events returns a channel that receives ring changes from the director. The channel is never closed; it blocks when nothing is happening.
func (*DirectorClient) ReportDown ¶ added in v1.3.1
func (d *DirectorClient) ReportDown(ip string)
ReportDown sends BACKEND-DOWN\t{ip} to remove the backend from the ring entirely. Called after the drain timeout expires following a FLUSH.
func (*DirectorClient) ReportFlush ¶
func (d *DirectorClient) ReportFlush(ip string)
ReportFlush sends BACKEND-FLUSH\t{ip} to mark the backend as temporarily unavailable.
func (*DirectorClient) ReportUp ¶
func (d *DirectorClient) ReportUp(ip string, port int, tag string)
ReportUp sends BACKEND-UP\t{ip}\t{port}\t{tag} to the director.
func (*DirectorClient) Run ¶
func (d *DirectorClient) Run(ctx context.Context)
Run connects to the director and processes events until ctx is cancelled. Reconnects with exponential backoff on failure.