Documentation
¶
Overview ¶
Package routing holds the Routes of C-08 and routes Alerts with them. A Route has a name, Matchers, the Minimum severity, a Group key and every policy field, each in its typed column; the Default route exists from the first start, has no Matchers and is always last. Routes are evaluated `ORDER BY is_default, position, id` and the first one whose Matchers all match takes a newly firing Alert (Router). Reordering replaces the positions under the list ETag, organizations.route_order_version, which creating, deleting and reordering bump; deletion is soft. Every change is recorded in the Audit log and announced with the live hint route; the package also exports muster_route_info, serves the two Route profiles, Paging and Informational, from the built-in defaults, previews a Group key over the Stored Snapshots of a period with the Router's evaluation order, and computes the Route suggestions on each read.
Index ¶
- Constants
- Variables
- func EnsureDefault(ctx context.Context, q Queries, orgID int64, now time.Time) error
- func MessageLabels(own []string, key []string, severityLabel, teamLabel string) []string
- func ReachCounts(reaches [][]Reached) map[int64]int
- func RestampAlerts(ctx context.Context, tx dbgen.DBTX, orgID int64, alertIDs []int64, ...) error
- type AckTimeout
- type ChainEntry
- type ChainRef
- type Config
- type DeliveryGroup
- type DeliveryPreview
- type DestinationCount
- type DestinationEntry
- type Entry
- type FieldError
- type Input
- type KeepTemplates
- type LabelSuggestion
- type List
- type Matcher
- type Membership
- type MembershipChange
- type OpenAlertGroupsError
- type OwnerFilter
- type Policy
- type Preview
- type PreviewDestination
- type PreviewExample
- type PreviewRequest
- type PreviewSide
- type PreviewTeam
- type Profile
- type Queries
- type Reached
- type ReachedDestination
- type ReachedEntry
- type Reaching
- type Reminders
- type Requester
- type Route
- type Router
- type Service
- func (s *Service) AcceptSuggestion(ctx context.Context, r Requester, id string, destinationIDs []string) (Route, error)
- func (s *Service) Create(ctx context.Context, r Requester, in Input) (Route, error)
- func (s *Service) Delete(ctx context.Context, r Requester, publicID string, version *int64) error
- func (s *Service) DestinationDeleted(ctx context.Context, tx dbgen.DBTX, destinationID int64) error
- func (s *Service) DismissSuggestion(ctx context.Context, userID int64, id string) error
- func (s *Service) Get(ctx context.Context, publicID string) (Route, error)
- func (s *Service) InfoChanged()
- func (s *Service) LabelSuggestions(ctx context.Context, publicID string) ([]LabelSuggestion, error)
- func (s *Service) List(ctx context.Context) (List, error)
- func (s *Service) ListOwned(ctx context.Context, f OwnerFilter) (List, error)
- func (s *Service) Preview(ctx context.Context, req PreviewRequest) (Preview, error)
- func (s *Service) RefreshInfo(ctx context.Context) error
- func (s *Service) Reorder(ctx context.Context, r Requester, version *int64, ids []string) (List, error)
- func (s *Service) RunInfo(ctx context.Context, ticks <-chan time.Time)
- func (s *Service) SetMembership(m Membership)
- func (s *Service) SetStormSummaries(h StormSummaries)
- func (s *Service) SetTemplates(h TemplateHooks)
- func (s *Service) Suggestions(ctx context.Context, userID *int64) ([]Suggestion, error)
- func (s *Service) Update(ctx context.Context, r Requester, publicID string, version *int64, in Input) (Route, error)
- type Severities
- type Severity
- type SeverityCondition
- type Snapshots
- type Store
- type Storm
- type StormSummaries
- type Suggestion
- type TeamEntries
- type TeamRef
- type TemplateError
- type TemplateHooks
- type Templates
Constants ¶
const ( // PreviewPeriod is routing.group_key_preview_period, the period a request without one previews (P-12). PreviewPeriod = 24 * time.Hour // PreviewExamples is routing.group_key_preview_examples: how many of the largest Alert Groups each side shows. PreviewExamples = 5 // PreviewMaxAlerts is routing.group_key_preview_max_alerts: the most Alerts a preview covers, the newest first. PreviewMaxAlerts = 10000 )
The values of the Group key preview (C-08.FR-5, defaults.md).
const ( ProfilePaging = "paging" ProfileInformational = "informational" )
The ids of the Route profiles (C-08.FR-7).
const ( EntryRoute = "route" EntryTeam = "team" )
The kinds of the entries that reach a Destination: the Alert Group's Route, or one of its Teams.
const ( LanguageEnglish = "en" LanguageRussian = "ru" )
The languages of a Route (route.language).
const ( MinimumNone = "none" MinimumWarning = "warning" MinimumCritical = "critical" )
The Minimum severities of a Route (route.minimum_severity, C-26.FR-8): none, or the lowest Severity level of its Alert Groups.
const ( KindMinimumSeverity = "route_minimum_severity" KindMessageLabels = "route_message_labels" KindMessageSettings = "route_message_settings" OpenGroupUpdatesChannel = "muster_open_group_updates" )
KindMinimumSeverity is the kind of the open_group_updates row that a changed Minimum severity writes (C-26.FR-9), KindMessageLabels that of a changed "Labels in the message" or name (C-29.FR-1, FR-2), KindMessageSettings that of a changed language, Snooze durations, root_message or line template (C-12.FR-2, FR-3, C-10.FR-6), and OpenGroupUpdatesChannel the LISTEN/NOTIFY channel that wakes the workers of internal/groups, which claim them.
const ( ActionCreated = "route.created" ActionUpdated = "route.updated" ActionDeleted = "route.deleted" ActionReordered = "route.reordered" ResourceRoute = "route" Hint = "route" )
The Audit log actions and resource type, and the live hint, of Routes (C-03.FR-14).
const ( CodeInvalidFormat = "invalid_format" CodeTooLong = "too_long" CodeOutOfRange = "out_of_range" CodeUnsupported = "unsupported" CodeDuplicate = "duplicate" CodeUnknownID = "unknown_id" CodeInvalidRegex = "invalid_regex" CodeRouteSetMismatch = "route_set_mismatch" CodeOneOfRequired = "one_of_required" CodeRequired = "required" )
The codes of FieldError.
const ( TemplateRootMessage = "root_message" TemplateLine = "line" TemplateAckTimeoutNotice = "ack_timeout_notice" )
The kinds of Route templates, as the API and the template error state name them.
const ( SuggestionHeartbeatLost = "heartbeat_lost" SuggestionInternalAlerts = "internal_alerts" )
The ids of the Route suggestions (C-08.FR-11), in the order they are listed.
const ( HeartbeatLostRouteName = "Muster: Heartbeat lost" InternalAlertsRouteName = "Muster internal alerts" )
The names of the Routes the suggestions create.
const DefaultName = "Default"
DefaultName is the name the Default route is created with.
const (
MaxLabelSuggestions = 50
)
MaxLabelSuggestions is the most labels listRouteLabelSuggestions offers for "Labels in the message" (C-29.FR-2); suggestionGroups and suggestionAlerts bound what it reads: the most recent Alert Groups of the Route within routing.group_key_preview_period and the newest of their memberships.
Variables ¶
var ( // ErrNotFound is a Route that does not exist in the Organization or is deleted. ErrNotFound = errors.New("no such route") // ErrNameTaken is a name another Route that is not deleted has. ErrNameTaken = errors.New("another route has this name") // ErrVersionMismatch is an If-Match that names another version of the Route, or of the Route list. ErrVersionMismatch = errors.New("the route or the route order changed since it was read") // ErrDefaultImmutable is a deletion of the Default route, or a reorder that lists it. ErrDefaultImmutable = errors.New("the default route cannot be deleted or moved") )
var ( // ErrSuggestionNotFound is an id of no Route suggestion. ErrSuggestionNotFound = errors.New("no such route suggestion") // ErrSuggestionObsolete is a Route suggestion that no longer applies. ErrSuggestionObsolete = errors.New("the route suggestion no longer applies") )
var Conditions = []SeverityCondition{ConditionAny, ConditionCritical, ConditionBelowCritical}
Conditions are the Severity conditions in the order the API lists them.
Functions ¶
func EnsureDefault ¶
EnsureDefault creates the Default route of the Organization once (C-08.FR-3), as a start-up ensure step: "Default", without Matchers, with the values of the Paging profile, which sets no Minimum severity. It changes nothing when the Default route exists; a Route that is not deleted and already has its name stops the start with ErrNameTaken.
func MessageLabels ¶
MessageLabels is the effective "Labels in the message" of a Route (route.message_labels, C-29.FR-2): its own list own when it has one, otherwise the list computed from its Group key key and the Organization's severity and Team labels — the labels of the Group key except alertname and the severity label, then the Team label and namespace, each once, in that order.
func ReachCounts ¶
ReachCounts counts, over the reaches of a set of Alert Groups, how many of them reach each Destination, by the Destination's internal id (C-26.FR-12).
func RestampAlerts ¶
func RestampAlerts(ctx context.Context, tx dbgen.DBTX, orgID int64, alertIDs []int64, routeID int64) error
RestampAlerts records routeID as the Route of the current firing of the Alerts, in the Snapshot's transaction tx: grouping puts Alerts whose Route was deleted while their Snapshot waited for it on the Default route.
Types ¶
type AckTimeout ¶
type AckTimeout struct {
Enabled bool `json:"enabled"`
FirstIntervalSeconds int64 `json:"first_interval_seconds"`
}
AckTimeout is route.ack_timeout.
type ChainEntry ¶
type ChainEntry struct {
ChainID string `json:"chain_id"`
Condition SeverityCondition `json:"severity_condition"`
}
ChainEntry is an Escalation chain of a Route with its Severity condition, by the chain's public_id (C-32.FR-2).
type ChainRef ¶
ChainRef is an Escalation chain of a Route as a read names it, with its owning Team, nil when none owns it.
type Config ¶
type Config struct {
OrgID int64
Store Store
Audit *audit.Writer
// Business is the business clock, which dates the rows and the period of a Group key preview; Real measures how
// long a preview took.
Business clock.Clock
Real clock.Clock
// Router is the Router of the Organization, whose evaluation order the Group key preview and the suggestions
// use; a new one when nil.
Router *Router
// Snapshots reads the Stored Snapshots for the Group key preview.
Snapshots Snapshots
Log *logging.Logger
}
Config is what a Service needs.
type DeliveryGroup ¶
type DeliveryGroup struct {
GroupKeyValues map[string]string
AlertCount int
SeverityLevel string
Teams []PreviewTeam
Destinations []ReachedDestination
}
DeliveryGroup is one Alert Group of the preview: its Group key values, its Alerts, its Severity level raised to the Minimum severity, its Teams in the order of their ids and the Destinations it reaches in the order of their ids.
type DeliveryPreview ¶
type DeliveryPreview struct {
AlertGroups []DeliveryGroup
DestinationCounts []DestinationCount
}
DeliveryPreview is the preview "Where alerts go" (C-26.FR-12): the PreviewExamples largest Alert Groups that the Alerts would form under the proposed Group key with their Teams and the Destinations each reaches, for every Destination that any such Alert Group reaches how many of all of them do, and whether Alerts of different Teams would share an Alert Group.
type DestinationCount ¶
type DestinationCount struct {
Destination PreviewDestination
AlertGroupCount int
}
DestinationCount is how many of all the Alert Groups of the preview reach a Destination.
type DestinationEntry ¶
type DestinationEntry struct {
DestinationID string `json:"destination_id"`
Condition SeverityCondition `json:"severity_condition"`
}
DestinationEntry is a Destination of a Route with its Severity condition, by the Destination's public_id (C-26.FR-1).
type Entry ¶
type Entry struct {
DestinationID int64 `json:"destination_id"`
Condition SeverityCondition `json:"severity_condition"`
}
Entry is a Destination of a Route or a Team with its Severity condition, by the Destination's internal id.
type FieldError ¶
type FieldError struct {
Pointer string
Code string
Detail string
// Line and Column are the 1-based position of a template error, 0 when unknown.
Line int
Column int
}
FieldError is a field of a request that is not valid, at a JSON pointer of the request body, with a stable code of the validation-failed problem.
func (*FieldError) Error ¶
func (e *FieldError) Error() string
type Input ¶
type Input struct {
Name string
Description *string
Matchers []Matcher
MinimumSeverity *string
Urgent bool
GroupKey []string
// DestinationEntries are the Route's Destinations with their Severity conditions, replacing the stored ones as a
// whole; nil, when the request left them out, takes DestinationIDs. DestinationIDs, the deprecated list of a 0.1
// client, is read only without DestinationEntries: it keeps the stored condition of each Destination it keeps and
// gives a new one any. Both nil keep the stored entries on an update and are none on a creation.
DestinationEntries *[]DestinationEntry
DestinationIDs []string
// ChainEntries are the Route's Escalation chains with their Severity conditions, replacing the stored ones as a
// whole; nil keeps them on an update and is none on a creation (C-32.FR-2).
ChainEntries *[]ChainEntry
// DeliverToTeams and RunTeamChains are the options of C-26.FR-2: nil keeps the stored one on an update and is
// false, or true for RunTeamChains, on a creation.
DeliverToTeams *bool
RunTeamChains *bool
Policy Policy
// Keep are the templates an update leaves as they are stored.
Keep KeepTemplates
// OwningTeamID is the public_id of the Team that owns the Route: nil keeps the stored one on an update and is none
// on a creation, and an empty string clears it.
OwningTeamID *string
// OwnMessageLabels says whether the Route has a list of "Labels in the message" of its own: nil keeps the stored
// choice on an update and is false on a creation. MessageLabels is that list, read only when the Route has one, nil
// when the request left it out — which keeps a stored list of its own — and a slice, empty included, when it gave one.
OwnMessageLabels *bool
MessageLabels []string
// ManagedBy is the mark of the tool that keeps the Route as code (C-33.FR-11), the Default route's included.
ManagedBy managedby.Input
}
Input is what createRoute and updateRoute write. A nil Description or MinimumSeverity keeps the stored value on an update, and is empty or none on a creation; Matchers replace the stored ones as a whole. Urgent is the deprecated urgent mark of a 0.1 client (C-26.FR-10): true without a MinimumSeverity is read as the Minimum severity critical; false, or beside a MinimumSeverity, changes nothing.
type KeepTemplates ¶
KeepTemplates says, for updateRoute, which templates the request left out: those keep the stored template, while a template given as null resets it to the built-in one (C-08.FR-1). A creation ignores it: a template left out is the built-in one.
type LabelSuggestion ¶
LabelSuggestion is a label the Route form suggests for "Labels in the message" (C-29.FR-2): a label of the Alerts of the Route's recent Alert Groups, its most frequent value as an example, and how many of those Alert Groups carry it.
type List ¶
List is every Route that is not deleted in evaluation order, the Default route last, with the version of the list that its ETag carries.
type Matcher ¶
type Matcher struct {
Label string `json:"label"`
Op string `json:"op"`
Value string `json:"value"`
}
Matcher is a Matcher of a Route as the API and the Audit log show it: a label, an operator and a value.
type Membership ¶
Membership is the hook that delivery runs, in the transaction tx of a Route's save, when the save changed the Route's Destination entries or its option "Also to the Teams from the label" (C-26.FR-6, C-11.FR-14), under the Route's membership lock, which the save holds exclusively.
type MembershipChange ¶
type MembershipChange struct {
RouteID int64
Before, After []Entry
ToTeamsBefore bool
ToTeamsAfter bool
}
MembershipChange is a save of the Route RouteID that changed its Destination entries or its option "Also to the Teams from the label" (C-26.FR-6, C-11.FR-14): the entries before and after the save, by internal Destination id in id order, and the option before and after.
func (MembershipChange) Added ¶
func (c MembershipChange) Added() []int64
Added are the Destinations the save put on the Route, in id order.
func (MembershipChange) Changed ¶
func (c MembershipChange) Changed() bool
Changed reports whether the save changed the entries or the option.
func (MembershipChange) Removed ¶
func (c MembershipChange) Removed() []int64
Removed are the Destinations the save took off the Route, in id order.
type OpenAlertGroupsError ¶
type OpenAlertGroupsError struct {
Count int64
}
OpenAlertGroupsError is the refusal to delete a Route that still has open Alert Groups (C-09.FR-19); Count says how many.
func (*OpenAlertGroupsError) Error ¶
func (e *OpenAlertGroupsError) Error() string
type OwnerFilter ¶
OwnerFilter selects the Routes a Team owns (C-25.FR-2): the Team by its public_id, or with UserID the Teams the User is in, "My Teams".
type Policy ¶
type Policy struct {
ReopenWindowSeconds int64 `json:"reopen_window_seconds"`
GracePeriodSeconds int64 `json:"grace_period_seconds"`
UrgentRiseRemovesAck bool `json:"urgent_rise_removes_ack"`
SnoozeDurationsSeconds []int64 `json:"snooze_durations_seconds"`
ThreadBatchingWindowSeconds int64 `json:"thread_batching_window_seconds"`
StormThreshold int64 `json:"storm_threshold"`
Language string `json:"language"`
Templates Templates `json:"templates"`
AckTimeout AckTimeout `json:"ack_timeout"`
Reminders Reminders `json:"reminders"`
AutoUnacknowledge bool `json:"auto_unacknowledge"`
}
Policy is the policy fields of a Route; each capability brings the behaviour of its fields (C-08.FR-1).
type Preview ¶
type Preview struct {
PeriodSeconds int64
Truncated bool
Current *PreviewSide
Proposed PreviewSide
// Delivery is the preview "Where alerts go", nil when the request gave neither entries nor deliver_to_teams and
// no saved Route.
Delivery *DeliveryPreview
}
Preview is a Group key preview: how the Alerts the Route would take in the period group with its current Group key, absent for a Route that is not saved, and with the proposed one. Truncated says that the preview stopped at routing.group_key_preview_max_alerts with Stored Snapshots of the period left unread.
type PreviewDestination ¶
type PreviewDestination struct {
ID int64
PublicID string
Name string
Type string
Health string
BrokenSince *time.Time
BrokenReason *string
}
PreviewDestination is a Destination that is not deleted, as the preview names it.
type PreviewExample ¶
PreviewExample is one group of a PreviewSide: its Group key values, a missing label being empty, and its Alerts.
type PreviewRequest ¶
type PreviewRequest struct {
RouteID string
Matchers []Matcher
ProposedGroupKey []string
PeriodSeconds *int64
MinimumSeverity *string
DestinationEntries *[]DestinationEntry
DeliverToTeams *bool
}
PreviewRequest asks for a Group key preview: of the saved Route RouteID with its own Matchers, or with Matchers when they are not nil, or of Matchers alone for a Route that is not saved yet; with the proposed Group key, over the period PeriodSeconds or, when it is nil, routing.group_key_preview_period. MinimumSeverity, DestinationEntries and DeliverToTeams are the unsaved settings of the Route for the delivery preview (C-26.FR-12): nil takes the saved Route's when RouteID is given, else none, no entries and false.
type PreviewSide ¶
type PreviewSide struct {
AlertGroupCount int
Examples []PreviewExample
}
PreviewSide is how the Alerts group by one Group key: the count of distinct key values, which is the count of Alert Groups when Reopen windows and Grace periods are left aside, and the largest groups.
type PreviewTeam ¶
PreviewTeam is a Team that is not deleted, as the preview names it.
type Profile ¶
type Profile struct {
ID string
Name string
MinimumSeverity string
GroupKey []string
Policy Policy
}
Profile is a Route profile: a starting set of Route settings that only pre-fills a new Route and is never stored. Neither profile sets a Minimum severity (C-26.FR-11).
type Queries ¶
type Queries interface {
ListRoutes(ctx context.Context, orgID int64) ([]dbgen.ListRoutesRow, error)
GetRoute(ctx context.Context, arg dbgen.GetRouteParams) (dbgen.GetRouteRow, error)
LockRoute(ctx context.Context, arg dbgen.LockRouteParams) (int64, error)
ListRouteMatchers(ctx context.Context, arg dbgen.ListRouteMatchersParams) ([]dbgen.ListRouteMatchersRow, error)
BumpRouteOrder(ctx context.Context, arg dbgen.BumpRouteOrderParams) (int64, error)
GetRouteOrderVersion(ctx context.Context, orgID int64) (int64, error)
InsertRoute(ctx context.Context, arg dbgen.InsertRouteParams) (int64, error)
EnsureDefaultRoute(ctx context.Context, arg dbgen.EnsureDefaultRouteParams) (string, error)
UpdateRoute(ctx context.Context, arg dbgen.UpdateRouteParams) error
DeleteRouteMatchers(ctx context.Context, arg dbgen.DeleteRouteMatchersParams) error
InsertRouteMatcher(ctx context.Context, arg dbgen.InsertRouteMatcherParams) error
DeleteRoute(ctx context.Context, arg dbgen.DeleteRouteParams) error
SetRoutePositions(ctx context.Context, arg dbgen.SetRoutePositionsParams) error
ListRouteInfo(ctx context.Context, orgID int64) ([]dbgen.ListRouteInfoRow, error)
ListHeartbeatIntegrations(ctx context.Context, orgID int64) ([]dbgen.ListHeartbeatIntegrationsRow, error)
ListAlertingIntegrations(ctx context.Context, orgID int64) ([]dbgen.ListAlertingIntegrationsRow, error)
ListAlertingDestinations(ctx context.Context, orgID int64) ([]dbgen.ListAlertingDestinationsRow, error)
ListAlertingSchedules(ctx context.Context, orgID int64) ([]dbgen.ListAlertingSchedulesRow, error)
ListAlertingGateways(ctx context.Context, orgID int64) ([]dbgen.ListAlertingGatewaysRow, error)
HasOpenAlertGroups(ctx context.Context, arg dbgen.HasOpenAlertGroupsParams) (bool, error)
InsertOpenGroupUpdate(ctx context.Context, arg dbgen.InsertOpenGroupUpdateParams) error
NotifyOpenGroupUpdates(ctx context.Context, channel string) error
ListRouteLabelSuggestions(ctx context.Context, arg dbgen.ListRouteLabelSuggestionsParams) (
[]dbgen.ListRouteLabelSuggestionsRow, error)
ListRouteSuggestionDismissals(ctx context.Context, arg dbgen.ListRouteSuggestionDismissalsParams) ([]string,
error)
DismissRouteSuggestion(ctx context.Context, arg dbgen.DismissRouteSuggestionParams) error
CountOpenAlertGroups(ctx context.Context, arg dbgen.CountOpenAlertGroupsParams) (int64, error)
ListOpenAlertGroupCounts(ctx context.Context, orgID int64) ([]dbgen.ListOpenAlertGroupCountsRow, error)
ResolveDestinations(ctx context.Context, arg dbgen.ResolveDestinationsParams) ([]dbgen.ResolveDestinationsRow,
error)
ListRouteDestinationIDs(ctx context.Context, arg dbgen.ListRouteDestinationIDsParams) (
[]dbgen.ListRouteDestinationIDsRow, error)
InsertRouteDestinations(ctx context.Context, arg dbgen.InsertRouteDestinationsParams) error
SetRouteDestinationConditions(ctx context.Context, arg dbgen.SetRouteDestinationConditionsParams) error
DeleteRouteDestinations(ctx context.Context, arg dbgen.DeleteRouteDestinationsParams) error
DropDeletedRouteDestinations(ctx context.Context, arg dbgen.DropDeletedRouteDestinationsParams) error
LockRouteMembership(ctx context.Context, arg dbgen.LockRouteMembershipParams) error
ListTeamsOfDestination(ctx context.Context, arg dbgen.ListTeamsOfDestinationParams) ([]int64, error)
LockTeamMembership(ctx context.Context, arg dbgen.LockTeamMembershipParams) error
DeleteDestinationTeams(ctx context.Context, arg dbgen.DeleteDestinationTeamsParams) error
BumpRoutesOfDestination(ctx context.Context, arg dbgen.BumpRoutesOfDestinationParams) (
[]dbgen.BumpRoutesOfDestinationRow, error)
LockOwningTeam(ctx context.Context, arg dbgen.LockOwningTeamParams) (dbgen.LockOwningTeamRow, error)
ListRouteChains(ctx context.Context, arg dbgen.ListRouteChainsParams) ([]dbgen.ListRouteChainsRow, error)
ResolveRouteChains(ctx context.Context, arg dbgen.ResolveRouteChainsParams) ([]dbgen.ResolveRouteChainsRow, error)
DeleteRouteChainsExcept(ctx context.Context, arg dbgen.DeleteRouteChainsExceptParams) error
UpsertRouteChains(ctx context.Context, arg dbgen.UpsertRouteChainsParams) error
ListUserTeams(ctx context.Context, arg dbgen.ListUserTeamsParams) ([]string, error)
ListPreviewTeams(ctx context.Context, arg dbgen.ListPreviewTeamsParams) ([]dbgen.ListPreviewTeamsRow, error)
ListPreviewTeamEntries(ctx context.Context, arg dbgen.ListPreviewTeamEntriesParams) (
[]dbgen.ListPreviewTeamEntriesRow, error)
ListPreviewDestinations(ctx context.Context, arg dbgen.ListPreviewDestinationsParams) (
[]dbgen.ListPreviewDestinationsRow, error)
audit.Store
Notify(ctx context.Context, h db.Hint) error
// DB is the pool or the transaction the queries run on, which the membership hook writes through.
DB() dbgen.DBTX
// contains filtered or unexported methods
}
Queries are the queries of the package, with the insert of the Audit log and the live hint.
type Reached ¶
type Reached struct {
DestinationID int64 `json:"destination_id"`
Entries []Reaching `json:"entries"`
}
Reached is a Destination an Alert Group reaches with the entries that reach it, the Route's first, then the Teams' by id.
func Reach ¶
func Reach(level string, route []Entry, deliverToTeams bool, teams []TeamEntries) []Reached
Reach is the rule of the Destinations an Alert Group reaches (C-26.FR-2, FR-3, FR-7): the entries of its Route whose condition its Severity level meets and, with deliverToTeams, the entries of each of its Teams whose condition it meets, keyed by Destination with the entries that reach each, in the order of the Destinations' ids. A Destination that several entries reach is reached once; one whose entries none meets is not reached. The owning Team of the Route is no input: it adds nothing. The rule reads no store, so that the dispatcher, delivery and the preview apply the same rule to what each reads.
type ReachedDestination ¶
type ReachedDestination struct {
Destination PreviewDestination
Entries []ReachedEntry
}
ReachedDestination is a Destination an Alert Group of the preview reaches with the entries that reach it.
type ReachedEntry ¶
type ReachedEntry struct {
Kind string
Team *PreviewTeam
Condition SeverityCondition
}
ReachedEntry is an entry that reaches a Destination: the Route's, with a nil Team, or a Team's.
type Reaching ¶
type Reaching struct {
Kind string `json:"kind"`
TeamID int64 `json:"team_id,omitempty"`
Condition SeverityCondition `json:"severity_condition"`
}
Reaching is an entry that reaches a Destination: the Route's, or a Team's with its id, with its condition.
type Reminders ¶
type Reminders struct {
Enabled bool `json:"enabled"`
FirstIntervalSeconds int64 `json:"first_interval_seconds"`
CapSeconds int64 `json:"cap_seconds"`
}
Reminders is route.reminders.
type Requester ¶
Requester is who asks for a change and how: the actor and the Transport of the Audit log entry, and the client address.
type Route ¶
type Route struct {
ID int64
PublicID string
Name string
Description string
Position int
IsDefault bool
// MinimumSeverity is route.minimum_severity; Urgent, the deprecated urgent mark, is true exactly when it is
// critical (C-26.FR-10).
MinimumSeverity string
Urgent bool
Matchers []Matcher
GroupKey []string
Policy Policy
DestinationIDs []string
// DestinationEntries are the Destinations with their Severity conditions (C-26.FR-1).
DestinationEntries []DestinationEntry
// ChainEntries are the Escalation chains of the Route with their Severity conditions by public_id, and Chains the
// same chains by name (C-32.FR-2).
ChainEntries []ChainEntry
Chains []ChainRef
DeliverToTeams bool
RunTeamChains bool
Storm *Storm
TemplateError *TemplateError
CreatedAt time.Time
Version int64
// OpenAlertGroupCount is the number of its open Alert Groups, which block its deletion (C-09.FR-19).
OpenAlertGroupCount int64
// OwningTeam is the Team that owns the Route (C-25.FR-2), nil when none does.
OwningTeam *TeamRef
// OwnMessageLabels says whether the Route has a list of "Labels in the message" of its own, and MessageLabels is
// the effective list (C-29.FR-2): its own, or the one computed from its Group key and labels while it has none.
OwnMessageLabels bool
MessageLabels []string
// ManagedBy is the tool that keeps the Route as code, nil for none (C-33.FR-11); nothing that routes reads it.
ManagedBy *string
// contains filtered or unexported fields
}
Route is a Route as the API reads it; Position is its zero-based place in evaluation order, DestinationEntries its Destinations that are not deleted with their Severity conditions, by public_id, DestinationIDs their public_ids, which the API still derives from them until 0.3.0, and Storm its active Storm, nil when there is none. DeliverToTeams is "Also to the Teams from the label" and RunTeamChains "Run the Teams' Escalation chains" (C-26.FR-2).
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router routes newly firing Alerts (C-08.FR-3, FR-6, FR-13): it is the Sink of Snapshot processing. Each Alert of a fired change is taken by the first Route in evaluation order whose Matchers match its labels, Static labels applied, and gets its Severity level; both are recorded on the Alert, which keeps them until it fires again, so an edit or a reorder applies to the next Alerts only. The order with its compiled Matchers is cached per replica: a route hint drops it, and every Snapshot compares the stamp of the Routes in its own transaction, so that a change made on any replica applies at once. A fired change — the first firing of an Alert, or a firing after a resolve — also starts firing in the sense of C-25.FR-5: the Router classifies it by its Teams and records them on the Alert with their rules, and the value of the Team label that names no Team, replacing what its previous firing recorded; the Teams are cached per replica as the order is, under the stamp of the Teams read with the Routes' stamp.
func (*Router) AlertChanges ¶
func (r *Router) AlertChanges(ctx context.Context, tx ingestdb.DBTX, changes []ingest.AlertChange) (ingest.Routed, error)
AlertChanges routes the Alerts of the fired changes in the Snapshot's transaction tx, and the listed Alerts that fire without a Route, such as one that fired before routing took it; other changes are not routed. It returns the Routes that took them, in evaluation order.
func (*Router) Invalidate ¶
func (r *Router) Invalidate()
Invalidate drops the cached evaluation order: a hint said that a Route changed.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service holds the Routes of the Organization.
func (*Service) AcceptSuggestion ¶
func (s *Service) AcceptSuggestion(ctx context.Context, r Requester, id string, destinationIDs []string) (Route, error)
AcceptSuggestion creates the Route of the suggestion id at the top of the evaluation order, with destinationIDs when they are given, and records route.created with the suggestion; the Route for Internal alerts needs destinationIDs and goes directly below the last Route other than the Default route that takes an Internal alert, when one does (D268). A suggestion that no longer applies, checked under the lock of the list, is ErrSuggestionObsolete.
func (*Service) Create ¶
Create creates a Route at the last position before the Default route; a name another Route has is ErrNameTaken. Its templates are dry-run against the built-in example first (C-12.FR-5).
func (*Service) Delete ¶
Delete deletes the Route publicID; a non-nil version must be its current one. It leaves every list and the evaluation order at once; the row stays for the history that points at it. The Default route is ErrDefaultImmutable.
func (*Service) DestinationDeleted ¶
DestinationDeleted is the hook of the Destinations (C-11.FR-14), in the transaction tx that deletes the Destination destinationID, before it leaves its Routes: each Route that is not deleted and has it gets a new version — the Destination leaves its destination_ids — and its hint, and its membership lock is taken, so that no Enqueue on it runs until tx ends. The Routes are locked in id order before their membership locks; a transaction that renders Alert Groups of several Routes at once and holds the membership lock of one of them may still deadlock with it, which PostgreSQL detects and ends. Then, after the Routes' membership locks and in id order, it takes the membership lock of each Team whose Destination entries name the Destination exclusively and removes it from those Teams, so that no Enqueue reads such an entry and delivers to the Destination while the deletion commits (C-26.FR-6).
func (*Service) DismissSuggestion ¶
DismissSuggestion hides the suggestion id from the User userID; a suggestion that no longer applies is ErrSuggestionObsolete. Dismissing it again changes nothing.
func (*Service) InfoChanged ¶
func (s *Service) InfoChanged()
InfoChanged asks RunInfo to refresh muster_route_info: a hint said a Route changed, maybe on another replica. It never blocks.
func (*Service) LabelSuggestions ¶
LabelSuggestions lists the labels of the Alerts of the Alert Groups of the Route publicID created within routing.group_key_preview_period of the business clock — at most the 200 most recent of them and 5,000 of their memberships — most frequent first, at most MaxLabelSuggestions; a deleted or unknown Route is ErrNotFound.
func (*Service) List ¶
List lists the Routes that are not deleted in evaluation order with the version of the list. The version is read first, so that the list is never older than its ETag.
func (*Service) ListOwned ¶
ListOwned lists the Routes that are not deleted and that the Team of f owns, or the Teams of its User, in evaluation order with the version of the whole list. A Team that cannot exist owns nothing.
func (*Service) Preview ¶
Preview previews a Group key over the Stored Snapshots of the period (C-08.FR-5). Each distinct Alert reported firing, with its labels from the newest Snapshot listing it and its Integration's current Static labels, counts when the Route takes it in the current evaluation order as routing evaluates it: a saved Route at its place, with its own Matchers or with the given ones, and Matchers alone as a new Route just before the Default route, where createRoute puts it. It reads at most PreviewMaxAlerts such Alerts, from the newest Snapshot back.
func (*Service) RefreshInfo ¶
RefreshInfo makes muster_route_info list exactly the Routes that are not deleted, the Default route included, as the database has them, whichever replica changed them (C-08.FR-12), and gives each its series of muster_template_errors_total; a deleted Route loses them.
func (*Service) Reorder ¶
func (s *Service) Reorder(ctx context.Context, r Requester, version *int64, ids []string) (List, error)
Reorder replaces the order of every Route except the Default route with ids, in one transaction; a non-nil version must be the current version of the list (the list ETag). A list that names the Default route is ErrDefaultImmutable; one whose Routes differ from the current set is a route_set_mismatch FieldError.
func (*Service) RunInfo ¶
RunInfo keeps muster_route_info current until ctx ends: it refreshes it at once, after InfoChanged and at every tick, which also repairs a refresh that failed.
func (*Service) SetMembership ¶
func (s *Service) SetMembership(m Membership)
SetMembership fills the hook of delivery for Destinations added to or removed from a Route, before any Route changes.
func (*Service) SetStormSummaries ¶
func (s *Service) SetStormSummaries(h StormSummaries)
SetStormSummaries fills the hook of delivery for a Route whose Storm summary shows a changed name or language, before any Route changes.
func (*Service) SetTemplates ¶
func (s *Service) SetTemplates(h TemplateHooks)
SetTemplates fills the template checks of messages, before any Route is created or updated.
func (*Service) Suggestions ¶
Suggestions lists the Route suggestions that apply now and that the User userID, if any, has not dismissed; they are computed on each read.
func (*Service) Update ¶
func (s *Service) Update(ctx context.Context, r Requester, publicID string, version *int64, in Input) (Route, error)
Update replaces the configured fields of the Route publicID; a non-nil version must be its current one (If-Match). The change applies at once to the next Alerts routed; an Alert already routed keeps its Route (C-08.FR-8). The Default route takes no Matchers. A template in.Keep names stays as stored; a new template is dry-run first, and saving one clears the Route's template error about it (C-12.FR-5, FR-6).
type Severities ¶
type Severities struct {
// contains filtered or unexported fields
}
Severities map the severity label of Alerts to Severity levels by the Organization's settings (organization.severity_label and organization.severity_mapping, C-08.FR-6).
func NewSeverities ¶
func NewSeverities(label string, mapping []organization.SeverityMapping) Severities
NewSeverities returns the Severity levels by the label and its mapping; the first mapping of a value wins.
func (Severities) Of ¶
func (s Severities) Of(labels map[string]string) Severity
Of is the Severity level of an Alert with the labels: the level its severity value maps to; warning, keeping the value as received, for a value without a mapping; info for an Alert without the label or with an empty value.
type Severity ¶
type Severity struct {
Level organization.SeverityLevel
// Raw is the value of the severity label shown as received; empty when the value is mapped or missing.
Raw string
}
Severity is the Severity level of an Alert and, when its value has no mapping, the value as received.
type SeverityCondition ¶
type SeverityCondition string
SeverityCondition is the Severity condition of a Destination of a Route or a Team (C-26.FR-1), checked against the Severity level of an Alert Group.
const ( ConditionAny SeverityCondition = "any" ConditionCritical SeverityCondition = "critical" ConditionBelowCritical SeverityCondition = "below_critical" )
The Severity conditions: any level, the default, only critical, or every level below critical.
func (SeverityCondition) Meets ¶
func (c SeverityCondition) Meets(level string) bool
Meets reports whether the Severity level of an Alert Group meets the condition; an empty condition is any.
type Snapshots ¶
type Snapshots interface {
Retention(ctx context.Context) (time.Duration, error)
Firing(ctx context.Context, since time.Time, visit func([]ingest.FiringAlert) bool) (ingest.FiringRead, error)
}
Snapshots reads the Stored Snapshots for the Group key preview (internal/ingest).
type Store ¶
type Store interface {
Queries
InTx(ctx context.Context, f func(Queries) error) error
On(tx dbgen.DBTX) Queries
}
Store runs the queries alone, in one transaction, or in a caller's transaction tx (On).
type Storm ¶
Storm is the active Storm of a Route (C-11.FR-6): when it started and the new Alert Groups it counted, those of its Storm summary.
type StormSummaries ¶
StormSummaries is the hook that delivery runs, in the transaction tx of a save of the Route routeID that changed its name or its language, which the Storm summary of its active Storm shows (C-11.FR-6, C-12.FR-10).
type Suggestion ¶
Suggestion is a Route suggestion that applies, with the Route accepting it creates at the top of the list, or for internal_alerts directly below the last Route other than the Default route that takes an Internal alert.
type TeamEntries ¶
TeamEntries are the Destination entries of one Team of an Alert Group, by the Team's internal id.
type TeamRef ¶
TeamRef names the Team that owns a Route: its internal id, public_id, name and slug, and whether it was deleted.
type TemplateError ¶
TemplateError is the template error state of a Route (C-12.FR-6): since when a template of it keeps failing and what failed.
type TemplateHooks ¶
type TemplateHooks struct {
Check func(ctx context.Context, routeID int64, kind, source, language string) error
Saved func(ctx context.Context, tx dbgen.DBTX, routeID int64, publicID string, kinds []string) error
}
TemplateHooks are the template checks of messages, wired in the runtime: Check dry-runs a template of the Route routeID, 0 for a new Route, and returns a *templates.Error for a template that fails; Saved clears the Route's template error, in the transaction tx that saved new templates of the kinds given.