maintenance

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package maintenance holds one-off scheduled maintenance windows: their validation, state, and the lead-time announcement through alert channels.

Index

Constants

View Source
const (
	MaxDomainTitle      = 120
	MaxDomainMessage    = 2000
	MaxBypassEntries    = 32
	MaxRetryAfterSecond = 86400
)

Bounds on a domain's maintenance settings.

View Source
const (
	StateScheduled = "scheduled"
	StateActive    = "active"
	StateEnded     = "ended"
)

Window states relative to one instant.

View Source
const (
	MaxDuration    = 30 * 24 * time.Hour
	MaxLeadMinutes = 7 * 24 * 60
)

Bounds on user input.

View Source
const DefaultInterval = time.Minute

DefaultInterval is how often the announcer looks for windows entering their lead time.

Variables

This section is empty.

Functions

func AnnounceDue

func AnnounceDue(w store.MaintenanceWindow, now time.Time) bool

AnnounceDue reports whether the lead-time notice should go out now.

func DomainWindow

func DomainWindow(m store.DomainMaintenance, app string, now, until time.Time) store.MaintenanceWindow

DomainWindow is the scheduled window that carries a domain's end time, so the banner, status page and announcer see it without a second state.

func NormalizeBypass

func NormalizeBypass(entries []string) ([]string, error)

NormalizeBypass turns IP addresses and CIDRs into deduplicated, masked CIDRs. A catch-all range is refused: that is ending maintenance.

func NoticeText

func NoticeText(w store.MaintenanceWindow) string

NoticeText is the plain-text announcement for w.

func StateAt

func StateAt(w store.MaintenanceWindow, now time.Time) string

StateAt reports where w is relative to now; the end instant is exclusive.

Types

type AnnounceStore

type AnnounceStore interface {
	ListMaintenanceWindows(ctx context.Context, since time.Time) ([]store.MaintenanceWindow, error)
	MarkMaintenanceAnnounced(ctx context.Context, id string, at time.Time) error
}

AnnounceStore is the store surface the announcer needs.

type Announcer

type Announcer struct {
	Store    AnnounceStore
	Channels Channels
	Notifier Notifier
	Logger   *slog.Logger
	Now      func() time.Time
}

Announcer sends each window's lead-time notice once.

func (*Announcer) Run

func (a *Announcer) Run(ctx context.Context, interval time.Duration) error

Run ticks until ctx is done.

func (*Announcer) Tick

func (a *Announcer) Tick(ctx context.Context) error

Tick announces every window whose lead time has begun. A window stays unmarked when no channel accepted the notice, so the next tick retries.

type Channels

type Channels interface {
	ListNotificationChannels(ctx context.Context) ([]alerting.NotificationChannel, error)
}

Channels lists notification channels. *alerting.DB satisfies it.

type DomainExpirer

type DomainExpirer struct {
	Store  DomainExpiryStore
	Nudge  func()
	Logger *slog.Logger
	Now    func() time.Time
}

DomainExpirer ends a domain's maintenance once its linked window ends or is cancelled. The ingress already stops serving the page at that instant; this removes the row, audits it and asks for a prompt reconcile.

func (*DomainExpirer) Run

func (x *DomainExpirer) Run(ctx context.Context, interval time.Duration) error

Run ticks until ctx is done.

func (*DomainExpirer) Tick

func (x *DomainExpirer) Tick(ctx context.Context) error

Tick ends every expired domain maintenance.

type DomainExpiryStore

type DomainExpiryStore interface {
	ListExpiredDomainMaintenance(ctx context.Context, now time.Time) ([]store.DomainMaintenance, error)
	DeleteDomainMaintenance(ctx context.Context, domain string) error
	SaveAuditEntry(ctx context.Context, e store.AuditEntry) error
}

DomainExpiryStore is what ending timed domain maintenance needs.

type DomainInput

type DomainInput struct {
	Title             string
	Message           string
	RetryAfterSeconds int
	// Until, when set, ends maintenance automatically through a linked window.
	Until             *time.Time
	Bypass            []string
	BypassHealthCheck bool
}

DomainInput is a request to put one domain into maintenance.

func (DomainInput) Validate

func (in DomainInput) Validate(domain string, now time.Time) (store.DomainMaintenance, error)

Validate checks in and returns the settings to store, without a window id.

type Input

type Input struct {
	Title            string
	Message          string
	Scope            string
	Target           string
	StartsAt         time.Time
	EndsAt           time.Time
	Freeze           bool
	AnnounceLeadMins int
}

Input is a request to create a window.

func (Input) Validate

func (in Input) Validate(now time.Time) (store.MaintenanceWindow, error)

Validate checks the input against now and returns the window to store.

type Notifier

type Notifier interface {
	SendNotice(ctx context.Context, c alerting.NotificationChannel, text string) error
}

Notifier sends one plain-text notice. *alerting.DeployDispatcher satisfies it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL