Documentation
¶
Overview ¶
Package maintenance computes when maintenance windows are active (FA-MNT-01). It is pure: no I/O, no clock reads; callers pass the instants they ask about.
A schedule is either "once", a fixed interval [StartsMs, EndsMs), or "recurring": a 5-field cron expression evaluated in a time zone. Every cron match starts a window that lasts DurationMinutes of elapsed time.
DST rules for recurring schedules:
- Cron fields are matched against the local wall-clock time in the zone.
- A local start time that does not exist (spring-forward gap) starts at the instant the clock jumps forward. In Europe/Berlin, "30 2 * * *" on 2026-03-29 starts at 01:00 UTC (03:00 CEST).
- A local start time that occurs twice (fall-back overlap) starts once, at its first occurrence. In Europe/Berlin, "30 2 * * *" on 2026-10-25 starts at 00:30 UTC (02:30 CEST); the second occurrence at 01:30 UTC starts nothing.
- Durations are elapsed real time. A window crossing a transition lasts DurationMinutes of real time, not of wall-clock time.
StartsMs and EndsMs bound recurring starts (0 = unbounded). They do not cut the end of an occurrence that started within the bounds.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller keeps the MAINTENANCE status of monitors in line with the maintenance windows (FA-MNT-02). Every node caches the compiled windows so that the aggregator can ask InMaintenance; only the leader proposes status changes.
func NewController ¶
func NewController(opts ControllerOptions) *Controller
NewController creates a Controller with defaults applied to opts.
func (*Controller) InMaintenance ¶
InMaintenance reports whether an active window applies to m at the instant at. It uses the windows cached by Refresh and is safe for concurrent use.
func (*Controller) Reconcile ¶
func (c *Controller) Reconcile(ctx context.Context) error
Reconcile proposes the status changes that bring every monitor (except the paused ones) in line with the cached windows at the current time: monitors inside a window enter MAINTENANCE, monitors whose last window has ended leave it. Only the leader may call it.
func (*Controller) Refresh ¶
func (c *Controller) Refresh(ctx context.Context) error
Refresh loads the maintenance windows of all tenants, keeps the active ones and compiles their schedules. Invalid schedules are skipped with a warning. On error the previous set stays in effect. An invalid window is reported once per revision, as it is refreshed every interval.
func (*Controller) Run ¶
func (c *Controller) Run(ctx context.Context)
Run refreshes the cached windows and, on the leader, reconciles the monitor states, immediately and then every Interval, until ctx ends.
type ControllerOptions ¶
type ControllerOptions struct {
State store.State
Cluster Applier
// IsLeader reports whether this node may propose commands; only the leader reconciles.
IsLeader func() bool
Logger *slog.Logger
// Now is the clock used for the reconciliation (default time.Now).
Now func() time.Time
// Interval is the period of Refresh and Reconcile (default 15 s).
Interval time.Duration
}
ControllerOptions configure a Controller. Zero values select the defaults, except for State, Cluster and IsLeader, which should be set.
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron is a parsed 5-field cron expression (minute hour day-of-month month day-of-week). Every field is stored as a bitset of its allowed values.
func ParseCron ¶
ParseCron parses a standard 5-field cron expression or one of the macros @yearly, @annually, @monthly, @weekly, @daily, @midnight and @hourly. Fields support *, numbers, names (JAN-DEC, SUN-SAT, case-insensitive), ranges a-b, lists a,b, and steps */n and a-b/n. Day-of-week accepts 0-7, where 0 and 7 both mean Sunday.
type Schedule ¶
type Schedule struct {
// contains filtered or unexported fields
}
Schedule is a validated, compiled maintenance schedule.
func Compile ¶
func Compile(s store.MaintenanceSchedule) (*Schedule, error)
Compile validates s and returns its compiled form.
For "once" the interval must satisfy StartsMs < EndsMs and Cron must be empty. For "recurring" the cron expression must parse, DurationMinutes must be in 1..10080, Timezone must load (empty means UTC), and, when both bounds are set, StartsMs < EndsMs.