Documentation
¶
Overview ¶
Package scheduler runs the checks this node is responsible for (FA-SCH-*).
Index ¶
- Constants
- func ActiveMonitors(monitors []store.Monitor, tenants []store.Tenant) []store.Monitor
- func ActiveTenantIDs(tenants []store.Tenant) map[string]bool
- func Capabilities(r *checker.Registry) func(monitorType string) string
- func NextRun(now time.Time, interval, phase time.Duration) time.Time
- func Phase(monitorID string, interval time.Duration) time.Duration
- func Reconcile(ctx context.Context, state store.State, changes <-chan struct{}, ...)
- type Assigner
- type AssignmentSyncer
- type CheckObserver
- type HeartbeatWriter
- type Options
- type Outcome
- type Scheduler
- type Sink
- type Sinks
- type Stats
- type Syncer
- type TenantGate
Constants ¶
const DefaultMaxConcurrent = 256
DefaultMaxConcurrent is the default limit of simultaneous checks (FA-SCH-07).
Variables ¶
This section is empty.
Functions ¶
func ActiveMonitors ¶
ActiveMonitors returns the monitors whose tenant is listed in tenants and not suspended, in their original order. The system tenant always counts as active.
func ActiveTenantIDs ¶
ActiveTenantIDs returns the set of tenants that are listed and not suspended.
func Capabilities ¶
Capabilities returns the capability function of an Assigner for the checkers of r: the capability a checker requires (checker.CapabilityRequirer), or "" if it requires none or the type is unknown.
func NextRun ¶
NextRun returns the first time strictly after now that lies on the grid phase + k*interval (Unix epoch based).
func Reconcile ¶
func Reconcile(ctx context.Context, state store.State, changes <-chan struct{}, interval time.Duration, log *slog.Logger, targets ...Syncer)
Reconcile keeps the targets (the scheduler and everything that tracks monitors) in line with state.db: it loads all monitors when changes signals and at least every interval, so a configuration change is active within seconds (FA-SCH-06). A target that runs checks is wrapped in an AssignmentSyncer, so it gets the monitors of its node only (ADR 0017).
Types ¶
type Assigner ¶
type Assigner struct {
// Capability returns the capability a monitor type requires, "" if none.
Capability func(monitorType string) string
}
Assigner decides which nodes run a monitor (ADR 0017, FA-SCH-01/02). It is pure: the result depends only on the monitor, the registry and the capability mapping, never on registry order.
type AssignmentSyncer ¶
type AssignmentSyncer struct {
Target Syncer
NodeID string
Assigner Assigner
Registry func() ([]store.Node, error)
Log *slog.Logger
}
AssignmentSyncer hands Target only the monitors that node NodeID runs (ADR 0017). Registry reads the node registry on every Sync; if that fails, Target keeps the previous monitors.
func (AssignmentSyncer) Sync ¶
func (s AssignmentSyncer) Sync(monitors []store.Monitor)
Sync implements Syncer.
type CheckObserver ¶
type CheckObserver interface {
CheckStarted(typ string)
CheckFinished(typ, result string, d time.Duration)
}
CheckObserver is told when a check starts and when it finishes. It is optional; metrics implement it. Calls come from the check goroutines and must not block for long. The result is the lower-case status (up, down, degraded).
type HeartbeatWriter ¶
type HeartbeatWriter struct {
// contains filtered or unexported fields
}
HeartbeatWriter turns outcomes into heartbeats of this node's stream and stores them in batches. seq continues after a restart and is never reused within an incarnation (FA-REP-01).
func NewHeartbeatWriter ¶
func NewHeartbeatWriter(ctx context.Context, metrics store.Metrics, nodeID string, log *slog.Logger) (*HeartbeatWriter, error)
NewHeartbeatWriter continues the stream (nodeID, metrics.Incarnation()).
func (*HeartbeatWriter) Record ¶
func (w *HeartbeatWriter) Record(ctx context.Context, o Outcome)
Record implements Sink. It blocks only if the queue is full, which applies backpressure to the checks instead of losing heartbeats.
func (*HeartbeatWriter) Run ¶
func (w *HeartbeatWriter) Run(ctx context.Context)
Run writes queued heartbeats until ctx ends, then flushes what is left.
func (*HeartbeatWriter) SetOnStored ¶
func (w *HeartbeatWriter) SetOnStored(fn func([]store.Heartbeat))
SetOnStored registers fn to receive every batch after it was stored. fn must not block, because the writer runs on; ADR 0021. The slice is only valid during the call, so fn must copy what it keeps. Several functions may be registered; they are called in registration order. Register before Run starts.
type Options ¶
type Options struct {
Registry *checker.Registry
Env *checker.Env
Sink Sink
Logger *slog.Logger
MaxConcurrent int
// Observer receives check start and finish events; nil disables them.
Observer CheckObserver
// Unit is the length of one interval second; tests shrink it.
Unit time.Duration
// Resolve returns the configuration with its secrets decrypted (ADR 0015);
// nil uses the stored configuration as it is.
Resolve func(ctx context.Context, m store.Monitor) (json.RawMessage, error)
// Now is the wall clock for the schedule and the start time of a check
// (heartbeat timestamps); nil means time.Now. Durations stay monotonic (ADR 0020).
Now func() time.Time
}
Options configure a Scheduler.
type Outcome ¶
type Outcome struct {
Monitor store.Monitor
// Scheduled is the planned start; Started may be later if the
// concurrency limit delayed the check.
Scheduled time.Time
Started time.Time
Result checker.Result
}
Outcome is one finished check.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs one timer loop per monitor.
type Sink ¶
Sink receives outcomes. Record must not block for long; it is called from the check goroutines.
type Stats ¶
type Stats struct {
Started int64
// Skipped counts runs dropped because the previous run of the same
// monitor was still in progress (FA-SCH-04).
Skipped int64
Running int64
}
Stats are counters for metrics and tests.
type TenantGate ¶
TenantGate hands Target only the monitors of tenants that may run: a suspended tenant rests its checks and alerts, and the monitors of a tenant that no longer exists are gone (ADR 0029). The system tenant is never suspended. Tenants returns the tenant list; if that fails, Target keeps the previous monitors.