Documentation
¶
Overview ¶
Package levelalert evaluates conditions that have a warning and a critical level and routes them to notification channels (#2148, #2149).
An evaluator hands Apply every condition it found at warning or critical on this pass. Each is sent to the configured channels under a key carrying its level, every pass, so the channel's repeat window decides how often a standing condition is repeated and a move from warning to critical is a new key the warning's window cannot hold back. A condition that was alerting on the previous pass and is not in this one has cleared: a resolved notification is sent once, under its own key, and its record is removed. The records live in alert_conditions so a restart, or the next pass running on another replica, still knows what was alerting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine applies a family's findings.
func New ¶
New returns an engine, or nil when store is nil. A nil sender records conditions and sends nothing.
func (*Engine) Apply ¶
func (e *Engine) Apply(ctx context.Context, family string, channels []string, findings []Finding, unknown ...string) (Result, error)
Apply sends each finding at its level to channels, sends a resolved notification for each condition of family that was alerting and is not among findings, and records the result. It is ApplyPass with Findings and Unknown alone.
func (*Engine) ApplyPass ¶ added in v1.170.1
func (e *Engine) ApplyPass(ctx context.Context, family string, channels []string, p Pass) (Result, error)
ApplyPass sends each finding at its level to channels and ends each condition of family that was alerting and is not among the findings, once, in words that say why: "Resolved" only when the condition was checked under the settings it began under and is gone (#2876). A condition no longer checked, or gone after the settings changed, once read "Resolved" although nobody fixed anything.
A send's key carries the condition, its level and when that level began, so the channel's repeat window holds back repeats of one episode while a condition that clears and returns, or changes level, is posted at once.
type Finding ¶
type Finding struct {
// Key names the condition and what it is about, unique within its
// family: webhook:spool_age:replica-a. It never carries the level.
Key string
Level Level
// Title is the notification's one line: what, where, how bad.
Title string
// Body is markdown: the value, the threshold, and what to look at.
Body string
// Link is the admin page the condition is seen on.
Link string
}
Finding is one condition at warning or critical.
type Level ¶
type Level string
Level is how bad a condition is.
The levels a condition is reported at.
type Pass ¶ added in v1.170.1
type Pass struct {
// Findings are the conditions at warning or critical.
Findings []Finding
// Unknown names key prefixes whose conditions this pass could not judge
// (a store that could not be read): what was recorded under them is left
// as it stands, neither ended nor sent again, until a pass can judge them.
Unknown []string
// Stopped says why a recorded condition is no longer checked at all (its
// source was deleted, its schema was not checked), or "" when this pass
// checked it (#2876). Nil checks every condition.
Stopped func(key string) string
// SettingsSavedAt is when the family's settings were last saved. A
// condition that began before it and is gone now may have gone because a
// threshold was raised or a rule turned off, not because it improved,
// and its notice says so (#2876).
SettingsSavedAt time.Time
}
Pass is what one evaluation of a family judged.
type PostgresStore ¶
type PostgresStore struct {
// contains filtered or unexported fields
}
PostgresStore is the alert_conditions table.
func NewPostgresStore ¶
func NewPostgresStore(db *sql.DB) *PostgresStore
NewPostgresStore returns the store over db.
func (*PostgresStore) Delete ¶
func (s *PostgresStore) Delete(ctx context.Context, key string) error
Delete removes a condition that cleared.
type Sender ¶
type Sender interface {
Send(ctx context.Context, names []string, key string, p notification.Payload) int
}
Sender queues an alert for notification channels. notifyalert.Sender satisfies it.
type Store ¶
type Store interface {
List(ctx context.Context, family string) ([]Record, error)
Upsert(ctx context.Context, family string, f Finding, now time.Time) error
Delete(ctx context.Context, key string) error
}
Store keeps the conditions each family found on its last pass.
type Thresholds ¶
type Thresholds struct {
Warning float64 `json:"warning"`
Critical float64 `json:"critical"`
Below bool `json:"-"`
}
Thresholds are the two values a reading is judged against. A zero threshold is off. Below marks a reading that is worse the lower it is (free space, days left); otherwise higher is worse.
func (Thresholds) Of ¶
func (t Thresholds) Of(v float64) Level
Of returns the level v is at, or "" when it is under both thresholds.