dispatch

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 35 Imported by: 172

Documentation

Index

Constants

View Source
const (
	DispatcherStateUnknown = iota
	DispatcherStateWaitingToStart
	DispatcherStateRunning
	DispatcherStateStopped
)

Variables

View Source
var DefaultRouteOpts = RouteOpts{
	GroupWait:         30 * time.Second,
	GroupInterval:     5 * time.Minute,
	RepeatInterval:    4 * time.Hour,
	GroupBy:           map[model.LabelName]struct{}{},
	GroupByAll:        false,
	MuteTimeIntervals: []string{},
	Labels:            model.LabelSet{},
}

DefaultRouteOpts are the defaulting routing options which apply to the root route of a routing tree.

Functions

This section is empty.

Types

type AlertFilter added in v0.35.0

type AlertFilter func(a *alert.Alert, now time.Time) (alert.AlertStatus, bool)

AlertFilter decides whether an alert belongs in a Groups result and returns the status to report for it. Groups calls the filter once per alert per aggregation group and records the returned status in AlertGroup.AlertStatuses, so the same alert may legitimately be reported with a different status in different groups.

type AlertGroup

type AlertGroup struct {
	Alerts      alert.AlertSlice
	Labels      model.LabelSet
	RouteLabels model.LabelSet
	Receiver    string
	GroupKey    string
	// AlertStatuses holds the status returned by the AlertFilter for each
	// alert in Alerts, keyed by fingerprint.
	AlertStatuses map[model.Fingerprint]alert.AlertStatus
	// MutedByActiveTimeIntervals and MutedByMuteTimeIntervals hold the names
	// of the time intervals of the group's route that mute it at the time of
	// the Groups call, one per kind. They are computed at query time, like
	// silences and inhibitions, and are both empty if the group is not muted.
	MutedByActiveTimeIntervals []string
	MutedByMuteTimeIntervals   []string
}

AlertGroup represents how alerts exist within an aggrGroup.

func (*AlertGroup) MutedBy added in v0.35.0

func (ag *AlertGroup) MutedBy() []string

MutedBy returns the names of all the time intervals that mute the group, the active ones first. The group is muted if the result is not empty.

type AlertGroups added in v0.17.0

type AlertGroups []*AlertGroup

func (AlertGroups) Len added in v0.17.0

func (ag AlertGroups) Len() int

func (AlertGroups) Less added in v0.17.0

func (ag AlertGroups) Less(i, j int) bool

func (AlertGroups) Swap added in v0.17.0

func (ag AlertGroups) Swap(i, j int)

type Dispatcher

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

Dispatcher sorts incoming alerts into aggregation groups and assigns the correct notifiers to each.

func NewDispatcher

func NewDispatcher(
	alerts provider.Alerts,
	route *Route,
	stage notify.Stage,
	timeMuter notify.TimeMuter,
	timeout func(time.Duration) time.Duration,
	maintenanceInterval time.Duration,
	limits Limits,
	logger *slog.Logger,
	recorder eventrecorder.Recorder,
	metrics *DispatcherMetrics,
	tmpl *template.Template,
) *Dispatcher

NewDispatcher returns a new Dispatcher.

func (*Dispatcher) Groups

func (d *Dispatcher) Groups(ctx context.Context, routeFilter func(*Route) bool, alertFilter AlertFilter) (AlertGroups, map[model.Fingerprint][]string, error)

Groups returns a slice of AlertGroups from the dispatcher's internal state.

func (*Dispatcher) LoadingDone added in v0.30.0

func (d *Dispatcher) LoadingDone() <-chan struct{}

func (*Dispatcher) Run

func (d *Dispatcher) Run(dispatchStartTime time.Time)

Run starts dispatching alerts incoming via the updates channel.

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop the dispatcher.

func (*Dispatcher) WaitForLoading added in v0.30.0

func (d *Dispatcher) WaitForLoading()

type DispatcherMetrics added in v0.20.0

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

DispatcherMetrics represents metrics associated to a dispatcher.

func NewDispatcherMetrics added in v0.20.0

func NewDispatcherMetrics(_ bool, r prometheus.Registerer, ff featurecontrol.Flagger) *DispatcherMetrics

NewDispatcherMetrics returns a new registered DispatchMetrics.

type Limits added in v0.23.0

type Limits interface {
	// MaxNumberOfAggregationGroups returns max number of aggregation groups that dispatcher can have.
	// 0 or negative value = unlimited.
	// If dispatcher hits this limit, it will not create additional groups, but will log an error instead.
	MaxNumberOfAggregationGroups() int
}

Limits describes limits used by Dispatcher.

type Route

type Route struct {

	// The configuration parameters for matches of this route.
	RouteOpts RouteOpts

	// Matchers an alert has to fulfill to match
	// this route.
	Matchers labels.Matchers

	// If true, an alert matches further routes on the same level.
	Continue bool

	// Children routes of this route.
	Routes []*Route

	// Idx contains the index of this route in the config
	Idx int
	// contains filtered or unexported fields
}

A Route is a node that contains definitions of how to handle alerts.

func NewRoute

func NewRoute(cr *config.Route, parent *Route) *Route

NewRoute returns a new route.

func (*Route) ID added in v0.27.0

func (r *Route) ID() string

ID returns a unique identifier for the route.

func (*Route) Key added in v0.6.0

func (r *Route) Key() string

Key returns a key for the route. It does not uniquely identify the route in general.

func (*Route) Match

func (r *Route) Match(lset model.LabelSet) []*Route

Match does a depth-first left-to-right search through the route tree and returns the matching routing nodes.

func (*Route) Walk added in v0.21.0

func (r *Route) Walk(visit func(*Route))

Walk traverses the route tree in depth-first order.

type RouteOpts

type RouteOpts struct {
	// The identifier of the associated notification configuration.
	Receiver string

	// What labels to group alerts by for notifications.
	GroupBy map[model.LabelName]struct{}

	// Use all alert labels to group.
	GroupByAll bool

	// How long to wait to group matching alerts before sending
	// a notification.
	GroupWait      time.Duration
	GroupInterval  time.Duration
	RepeatInterval time.Duration

	// A list of time intervals for which the route is muted.
	MuteTimeIntervals []string

	// A list of time intervals for which the route is active.
	ActiveTimeIntervals []string

	// Merged labels from this route and all of its parent routes.
	Labels model.LabelSet
}

RouteOpts holds various routing options necessary for processing alerts that match a given route.

func (*RouteOpts) MarshalJSON

func (ro *RouteOpts) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of the routing options.

func (*RouteOpts) String

func (ro *RouteOpts) String() string

Jump to

Keyboard shortcuts

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