internalalerts

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package internalalerts holds the closed registry of Internal alerts (C-06.FR-14, ADR-0014) and raises and resolves them. An Internal alert is an Alert of the built-in "Muster" Integration: each raise and each resolve is a synthetic Stored Snapshot of that Integration, marked internal, written in the caller's transaction and processed by the Snapshot worker in order with the Integration's other Snapshots. A configuration entity appears in the labels by its immutable id, with its current name in a separate label, and the fingerprint is computed from alertname and the id labels only, so that renaming the entity updates the open Internal alert instead of starting a new one.

Index

Constants

View Source
const (
	StatusFiring   = "firing"
	StatusResolved = "resolved"
)

The statuses of a synthetic Snapshot and of its Alert, as in an Alertmanager webhook.

View Source
const (
	SeverityCritical = "critical"
	SeverityWarning  = "warning"
)

The severities of Internal alerts.

View Source
const (
	EntityIntegration = "integration"
	EntityRoute       = "route"
	EntityDestination = "destination"
)

The entity labels of Internal alerts: the immutable id of a configuration entity, with its name in a label of its own.

View Source
const DefaultRunbookBase = "https://muster-io.github.io/muster"

DefaultRunbookBase is MUSTER_RUNBOOK_BASE_URL when it is not set: the published documentation site.

View Source
const (
	DeletionGroupKey = groupKeyPrefix + `:{event="integration_deleted"}`
)

The groupKeys of synthetic Stored Snapshots: one per Internal alert, and the marker of a deleted Integration.

View Source
const SnapshotChannel = "muster_snapshots"

SnapshotChannel is the LISTEN/NOTIFY channel that wakes the processing workers when a Stored Snapshot was stored; the payload is a Notification.

Variables

View Source
var DestinationBroken = register(&Definition{
	Name:      "MusterDestinationBroken",
	Severity:  SeverityCritical,
	Entity:    EntityDestination,
	NameLabel: "destination_name",
	Condition: "A Destination is Broken: the messenger answered with a Fatal error, or with Transient errors until the " +
		"budget ran out, so its deliveries wait. It resolves when a probe, a Destination check or a Destination test " +
		"succeeds.",
	Summary: "Destination {name} is Broken",
	Description: "Muster cannot deliver to Destination {name}: the messenger refuses or does not answer, and new " +
		"Alert Groups wait. The Destination page shows the reason. Muster probes it every " +
		"delivery.broken_probe_interval and sends the current state once it recovers.",
	Capability: "C-11",
})

DestinationBroken is raised while a Destination is Broken (C-11.FR-9).

View Source
var ErrNoBuiltin = errors.New("the built-in Muster integration is missing")

ErrNoBuiltin is an Organization without the built-in Integration, which the start-up ensure step creates.

View Source
var HeartbeatLost = register(&Definition{
	Name:         "MusterHeartbeatLost",
	Severity:     SeverityCritical,
	Entity:       EntityIntegration,
	NameLabel:    "integration_name",
	StaticLabels: true,
	Condition: "An Integration is Heartbeat lost: no Heartbeat signal arrived within its Heartbeat timeout, so the " +
		"path from its Alertmanager to Muster may be interrupted and Stale resolution is paused. It resolves with the " +
		"next signal, when the Heartbeat is turned off or when the Integration is deleted.",
	Summary: "No Heartbeat from the Alertmanager of Integration {name}",
	Description: "Muster has received no Heartbeat signal for Integration {name} within its Heartbeat timeout: " +
		"Alertmanager, its Heartbeat route or its network path to Muster may have stopped working, and new alerts may " +
		"not arrive. Nothing is resolved as Stale until the signal returns.",
	Capability: "C-07",
})

HeartbeatLost is raised while an Integration is Heartbeat lost (C-07.FR-4).

View Source
var OIDCSecretExpiring = register(&Definition{
	Name:     "MusterOIDCSecretExpiring",
	Severity: SeverityWarning,
	Condition: "The OIDC client secret expires within oidc.secret_expiry_lead, by the expiry date an Admin entered in " +
		"the OIDC settings. It resolves when the date moves further out or is removed.",
	Summary: "The OIDC client secret expires soon",
	Description: "The client secret Muster uses to sign people in through the identity provider expires soon, by the " +
		"date entered in the OIDC settings. Create a new secret at the identity provider, enter it and its expiry date " +
		"in the OIDC settings; until then sign-in through OIDC keeps working.",
	Capability: "C-19",
})

OIDCSecretExpiring is raised while the OIDC client secret expires within oidc.secret_expiry_lead (C-19.FR-5).

View Source
var SnapshotTruncated = register(&Definition{
	Name:      "MusterSnapshotTruncated",
	Severity:  SeverityWarning,
	Entity:    EntityIntegration,
	NameLabel: "integration_name",
	Condition: "An Integration has a truncated groupKey: Alertmanager cut a Snapshot with max_alerts, so Muster keeps " +
		"the unlisted Alerts alive and cannot resolve them by absence. It resolves with the next untruncated " +
		"Snapshot of every truncated groupKey.",
	Summary: "Alertmanager truncates the Snapshots of Integration {name}",
	Description: "Alertmanager sent a Snapshot with truncatedAlerts above 0 for Integration {name}: the receiver " +
		"has max_alerts set. Muster keeps the Alerts it does not list alive and cannot tell when they resolve. Set " +
		"max_alerts: 0 on the Muster receiver.",
	Capability: "C-06",
})

SnapshotTruncated is raised while any groupKey of an Integration is truncated (C-06.FR-6).

View Source
var TemplateError = register(&Definition{
	Name:        "MusterTemplateError",
	Severity:    SeverityWarning,
	Entity:      EntityRoute,
	NameLabel:   "route_name",
	OrEntity:    EntityDestination,
	OrNameLabel: "destination_name",
	Extra:       []string{"template"},
	Condition: "A template of a Route failed while rendering a message, so its messages use the Fallback template; or a " +
		"request template of an outgoing webhook Destination failed, so that request was not sent. It resolves when " +
		"the template renders again or, for a Route, a new template is saved.",
	Summary: "A template of Route {name} keeps failing",
	Description: "A message template of Route {name} failed while rendering, so its messages show every label in the " +
		"Fallback template instead. The Route page shows the error with its line and column; fix the template in the " +
		"Route's Message settings.",
	OrSummary: "A request template of Destination {name} keeps failing",
	OrDescription: "A request template of the outgoing webhook Destination {name} failed while rendering, so that " +
		"request was not sent and its delivery is Not delivered. The Destination page shows the error with its line " +
		"and column; fix the request templates of the Destination.",
	Capability: "C-12",
})

TemplateError is raised while a template of a Route keeps failing (C-12.FR-6, ADR-0012), or a request template of an outgoing webhook (C-15.FR-7).

Functions

func Fingerprint

func Fingerprint(d *Definition, labels map[string]string) string

Fingerprint is the fingerprint of an Internal alert: computed from alertname and the entity's id label only, so that a rename of the entity keeps it. It is Alertmanager's: FNV-1a over the label names in order, each name and value followed by the byte 0xff, as 16 hexadecimal digits.

func GroupKey

func GroupKey(name string) string

GroupKey is the groupKey of the synthetic Stored Snapshots of the Internal alert named name.

func RunbookVersion

func RunbookVersion(v string) string

RunbookVersion is the segment of the documentation site for the binary of version v (C-19.FR-9, C-21.FR-11): the major.minor of a release X.Y.Z, with an optional leading v, or latest for any other version: the development version, snapshots, pre-releases and build metadata.

Types

type Definition

type Definition struct {
	// Name is the alertname, shared with the chart rule for the same condition.
	Name     string
	Severity string
	// Entity is the label of the entity's immutable id, and NameLabel the label of its current name; Extra are the
	// other labels it carries.
	Entity    string
	NameLabel string
	Extra     []string
	// OrEntity is the other entity it may be about instead, OrNameLabel the label of that entity's name, and OrSummary
	// and OrDescription its annotations then: MusterTemplateError is about a Route or about a Destination. An alert
	// about one carries no label of the other.
	OrEntity      string
	OrNameLabel   string
	OrSummary     string
	OrDescription string
	// StaticLabels adds the Static labels of the Integration it is about; the labels above win over a Static label
	// of the same name.
	StaticLabels bool
	// Condition says while what it fires; Summary and Description are its annotations, where {name} is the entity's
	// current name.
	Condition   string
	Summary     string
	Description string
	// Capability raises it.
	Capability string
}

Definition is one Internal alert of the registry.

func Definitions

func Definitions() ([]*Definition, error)

Definitions returns the registry sorted by name, after checking it: names are unique and start with Muster, the severity is known, an entity label has a name label, label names are valid and unique, and the texts are set.

func Lookup

func Lookup(name string) *Definition

Lookup is the Internal alert named name, or nil.

func (*Definition) AlertLabels

func (d *Definition) AlertLabels(e Entity, extra map[string]string) map[string]string

AlertLabels are the labels the Internal alert d carries about the entity e, with its extra labels: alertname, severity, the entity's id and name, the Extra labels and, for one that carries the Static labels of its Integration, those in extra; its own labels win over a Static label of the same name.

func (*Definition) Labels

func (d *Definition) Labels() []string

Labels are the label names it carries besides alertname and severity, in order.

func (*Definition) Runbook

func (d *Definition) Runbook() string

Runbook is the page of the documentation site for the Internal alert, under the runbook base URL.

type Deletion

type Deletion struct {
	IntegrationID string
	Name          string
}

Deletion is what the marker of a deleted Integration says: the Integration's public_id and its name at deletion.

func DeletionOf

func DeletionOf(body []byte) (Deletion, bool)

DeletionOf reads the marker of a deleted Integration from the body of a synthetic Stored Snapshot; ok is false for any other body.

type Entity

type Entity struct {
	ID   string
	Name string
}

Entity is the configuration entity an Internal alert is about: its immutable public_id and its current name.

type Notification

type Notification struct {
	OrgID         int64 `json:"org_id"`
	IntegrationID int64 `json:"integration_id"`
}

Notification is the payload of a notification on SnapshotChannel: the Integration whose pending Stored Snapshots grew.

type Raiser

type Raiser struct {
	// contains filtered or unexported fields
}

Raiser raises and resolves the Internal alerts of an Organization. Callers raise and resolve on transitions of the condition, not on every check.

func NewRaiser

func NewRaiser(orgID int64, runbookBase string) *Raiser

NewRaiser returns the Raiser of the Organization orgID; runbookBase is MUSTER_RUNBOOK_BASE_URL, the base of each runbook_url, DefaultRunbookBase when empty.

func (*Raiser) Firing

func (r *Raiser) Firing(ctx context.Context, q Store, d *Definition) (bool, error)

Firing reports whether the Internal alert d, of no entity, fires or will once its pending raise is processed, so that a check raises and resolves it only on transitions.

func (*Raiser) MarkDeleted

func (r *Raiser) MarkDeleted(ctx context.Context, q Store, now time.Time, integrationID int64, publicID,
	name string) error

MarkDeleted writes the marker of the deletion of the Integration integrationID (public_id publicID, named name) into its own queue: processing reaches it after the Stored Snapshots the Integration accepted before, and then resolves its Alerts and its Internal alerts (C-06.FR-16).

func (*Raiser) Raise

func (r *Raiser) Raise(ctx context.Context, q Store, now time.Time, d *Definition, e Entity,
	extra map[string]string) error

Raise raises the Internal alert d about the entity e at now, with its extra labels. For an Internal alert that carries the Static labels of its Integration, extra holds them too; its own labels win over a Static label of the same name.

func (*Raiser) RaiseFor

func (r *Raiser) RaiseFor(ctx context.Context, q Store, now time.Time, d *Definition, entity string, e Entity,
	extra map[string]string) error

RaiseFor raises the Internal alert d about the entity e of the kind entity, which is d's Entity or its OrEntity.

func (*Raiser) Renamed

func (r *Raiser) Renamed(ctx context.Context, q Store, now time.Time, entity, id, name string) error

Renamed raises again every Internal alert about the entity entity=id with the entity's new name, as the same firing: its startsAt is kept, so processing updates the name label in place (C-06.AC-11). It covers the Internal alerts that fire and those whose raise still waits for processing in the built-in Integration's queue, which would otherwise fire with the old name.

func (*Raiser) Resolve

func (r *Raiser) Resolve(ctx context.Context, q Store, now time.Time, d *Definition, entityID string) error

Resolve resolves the Internal alert d about the entity whose id is entityID, at now. A resolve of an Internal alert that does not fire changes nothing.

func (*Raiser) ResolveAbout

func (r *Raiser) ResolveAbout(ctx context.Context, q Store, now time.Time, entity, id string) error

ResolveAbout resolves, at now, every Internal alert about the entity entity=id that fires or whose raise waits for processing, as the deletion of the entity does (C-06.FR-16). An entity with none writes nothing.

func (*Raiser) ResolveFor

func (r *Raiser) ResolveFor(ctx context.Context, q Store, now time.Time, d *Definition, entity, entityID string) error

ResolveFor resolves the Internal alert d about the entity of the kind entity whose id is entityID, at now.

type Store

type Store interface {
	FindBuiltinIntegration(ctx context.Context, orgID int64) (int64, error)
	InsertInternalBody(ctx context.Context, arg dbgen.InsertInternalBodyParams) error
	InsertInternalSnapshot(ctx context.Context, arg dbgen.InsertInternalSnapshotParams) error
	NotifyInternalSnapshot(ctx context.Context, arg dbgen.NotifyInternalSnapshotParams) error
	ListOpenInternalAlerts(ctx context.Context, arg dbgen.ListOpenInternalAlertsParams) (
		[]dbgen.ListOpenInternalAlertsRow, error)
	ListPendingInternalRaises(ctx context.Context, orgID int64) ([][]byte, error)
}

Store writes synthetic Stored Snapshots and reads the open Internal alerts; it runs inside the caller's transaction.

func NewStore

func NewStore(d dbgen.DBTX) Store

NewStore is the Store over a pool, a connection or a transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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