escalation

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 32 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 escalation holds the Escalation chains of C-32 as configuration: a name unique in the Organization, a description, an optional owning Team and the ordered steps within escalation.limits (steps.go), the Routes and Teams that name a chain, the Destinations it writes in and its warnings (warnings.go). Only Admins change chains; every change is recorded in the Audit log with a before/after diff, announced with the live hint escalation-chain, and the package exports muster_escalation_chain_info. Routes and Teams name chains through their own packages, which read escalation_chains with their own queries; a chain that one of them names is never deleted (chain_in_use).

Lock order. A transaction that locks rows of more than one of these locks them in this order: the Organization's row of the Teams (a save or the deletion of a Team), the Teams, the Routes, the Escalation chains, the Schedules. A save of a chain reads its new owning Team FOR SHARE before the chain's row — a Team's deletion locks the Team and then reads the chains it owns — and the Schedules its steps name FOR KEY SHARE after it, in id order — a Schedule's deletion locks the Schedule FOR UPDATE and then reads the steps that name it; KEY SHARE does not wait for a change of a Schedule that keeps its key, such as making another one main, which locks the new main Schedule and then updates the old one. A save of a Route or a Team locks its own row and then the chains it names FOR KEY SHARE, and a chain's deletion locks the chain FOR UPDATE and then reads the Routes and Teams that name it, taking no lock on them. No transaction of a chain locks a Route or a Team for a change.

Index

Constants

View Source
const (
	ActionCreated = "escalation_chain.created"
	ActionUpdated = "escalation_chain.updated"
	ActionDeleted = "escalation_chain.deleted"
	ResourceChain = "escalation_chain"
	Hint          = "escalation-chain"
)

The Audit log actions and resource type, and the live hint, of Escalation chains (C-32.FR-19).

View Source
const (
	MaxNameLength        = 200
	MaxDescriptionLength = 2000
)

The limits of a chain, in characters.

View Source
const (
	CodeRequired              = "required"
	CodeInvalidFormat         = "invalid_format"
	CodeTooLong               = "too_long"
	CodeOutOfRange            = "out_of_range"
	CodeDuplicate             = "duplicate"
	CodeUnknownID             = "unknown_id"
	CodeUnsupported           = "unsupported"
	CodeNotPageable           = "not_pageable"
	CodeGatewayRequired       = "gateway_required"
	CodeWebhookEventsRequired = "webhook_events_required"
)

The codes of FieldError, as the API names them.

View Source
const (
	ReasonViewer   = "viewer"
	ReasonDisabled = "disabled"
)

Why a person may not be Paged (NotPageableReason): a Viewer or a disabled User.

View Source
const (
	HolderRoute = "route"
	HolderTeam  = "team"
)

The kinds of what holds a chain, as in_use_by names them.

View Source
const (
	RunRunning     = "running"
	RunRanOut      = "ran_out"
	RunStopped     = "stopped"
	OutcomeMade    = "made"
	OutcomeSkipped = "skipped"
)

The states of a run, and the outcomes of its steps.

View Source
const (
	SourceRoute = "route"
	SourceTeam  = "team"
)

The kinds of the source of a run.

View Source
const (
	KindPageOnCall = "page_on_call"
	KindPagePeople = "page_people"
	KindPageTeam   = "page_team"
	KindCall       = "call"
	KindWait       = "wait"
	KindWebhook    = "webhook"
	KindRepeat     = "repeat"
)

The kinds of an Escalation step (C-32.FR-3).

View Source
const (
	ImportanceNormal    = "normal"
	ImportanceImportant = "important"
	CallOnCall          = "on_call"
	CallPeople          = "people"
)

The importance of a Page, and the targets of a call.

View Source
const (
	ConditionAny           = "any"
	ConditionCritical      = "critical"
	ConditionBelowCritical = "below_critical"
)

The Severity conditions of a step (C-26.FR-1).

View Source
const (
	MaxSteps       = 20
	MinWaitSeconds = 60
	MaxWaitSeconds = 86400
	MaxRepeatTimes = 10
)

The limits of a chain, escalation.limits (P-84, confirmed with the story of the Escalation chains): at most MaxSteps steps, each wait a whole number of minutes from MinWaitSeconds to MaxWaitSeconds, and a repeat at most MaxRepeatTimes times. Migration 0046 pins the same values in the CHECKs of escalation_steps.

View Source
const (
	WarningEveryoneUnsupported = "everyone_unsupported"
	WarningGatewayDeleted      = "gateway_deleted"
	WarningDestinationDeleted  = "destination_deleted"
	WarningTeamDeleted         = "team_deleted"
	WarningPagesNobody         = "pages_nobody"
)

The kinds of a chain's warning (C-32.FR-17): a page_team step whose Team mention or word for everyone the Connection of one of the chain's Destinations cannot mention, a call step whose gateway is no Notification gateway any more, a webhook step whose Destination was deleted, a page_team step whose Team was deleted, and a chain none of whose steps Pages anyone — no page_on_call, page_people, page_team or call step — which is the only warning of the chain as a whole, without a step.

View Source
const MaxStepsPerFiring = 1000

MaxStepsPerFiring bounds the steps one firing makes. Repeats nested without a wait between them make many passes in one go; past this many steps the firing ends and the run goes on at the next one, due at once, so that one transaction never holds the Alert Group for long.

View Source
const MaxStepsPerRun = MaxSteps * (1 + MaxSteps*MaxRepeatTimes)

MaxStepsPerRun bounds the steps of a run, which repeats nested inside one another multiply: the steps a chain of escalation.limits makes when each repeat goes back its times once, MaxSteps*(1+MaxSteps*MaxRepeatTimes). A run that reaches it runs out there, as after its last step, so that its Alert Group becomes Unclaimed, and logs escalation_run_step_limit.

View Source
const TimerKind = "escalation_step"

TimerKind is the kind of the timer of a run.

Variables

View Source
var (
	// ErrNotFound is a chain that does not exist in the Organization.
	ErrNotFound = errors.New("no such escalation chain")
	// ErrNameTaken is a name another chain has, ignoring case.
	ErrNameTaken = errors.New("another escalation chain has this name")
	// ErrVersionMismatch is an If-Match that names another version of the chain.
	ErrVersionMismatch = errors.New("the escalation chain changed since it was read")
	// ErrInUse is the deletion of a chain that a Route or a Team names (chain_in_use); InUseError names them.
	ErrInUse = errors.New("routes or teams name the escalation chain")
)

Functions

This section is empty.

Types

type Actor

type Actor struct {
	Kind        string
	PublicID    string
	Name        string
	Login       string
	Deactivated bool
}

Actor is a User or a Service account who stopped a run.

type Calls

type Calls interface {
	Target(ctx context.Context, tx gateways.DBTX, gatewayID int64, gatewayPublicID string, users []int64) (
		gateways.CallTarget, error)
	Queue(ctx context.Context, tx gateways.DBTX, p gateways.PageCall) (int64, func(context.Context), error)
}

Calls queues the calls of Pages through Notification gateways, in the dispatcher's transaction: (*gateways.Calls).

type Chain

type Chain struct {
	ID           int64
	PublicID     string
	Name         string
	Description  string
	OwningTeam   *TeamRef
	Steps        []Step
	Referrers    Referrers
	Destinations []DestinationRef
	Warnings     []Warning
	CreatedAt    time.Time
	Version      int64
	// ManagedBy is the tool that keeps the chain as code, nil for none (C-33.FR-11).
	ManagedBy *string
}

Chain is an Escalation chain as the API reads it, with its steps in their order, the Routes and Teams that name it, the Destinations it writes in and its warnings.

type ChainRef

type ChainRef struct {
	PublicID   string
	Name       string
	OwningTeam *TeamRef
}

ChainRef names a chain with its owning Team.

type ChainRun

type ChainRun struct {
	PublicID  string
	Group     RunGroup
	State     string
	StartedAt time.Time
	EndedAt   *time.Time
	StoppedBy *StoppedBy
	Steps     []RunStepView
}

ChainRun is a run of a chain as "How it went" lists it (EscalationRun): its Alert Group, its state, when it started and ended, what stopped it, and the steps it made and skipped.

type Config

type Config struct {
	OrgID    int64
	Store    Store
	Audit    *audit.Writer
	Business clock.Clock
}

Config is what a Service needs: the Organization, the Store, the Audit log writer and the business clock, which dates the rows.

type DBTX

type DBTX = dbgen.DBTX

DBTX is the pool or transaction the queries run in.

type DestinationRef

type DestinationRef struct {
	ID           int64
	PublicID     string
	Name         string
	Type         string
	Health       string
	BrokenSince  *time.Time
	BrokenReason *string
	// contains filtered or unexported fields
}

DestinationRef is a Destination a chain writes in, with its health and what its Connection can mention.

type DestinationTarget

type DestinationTarget struct {
	PublicID string
	Name     string
	Type     string
	Mode     string
	Deleted  bool
}

DestinationTarget is the Destination of a webhook step, with its type and mode, marked deleted once deleted.

type Dispatcher

type Dispatcher interface {
	ChainStep(ctx context.Context, tx groups.DBTX, groupID int64,
		step func(ctx context.Context, g *groups.Group) (groups.ChainProgress, error)) (func(context.Context), error)
}

Dispatcher is the dispatcher of Alert Groups through which a step changes its Alert Group: (*groups.Service).ChainStep.

type FieldError

type FieldError struct {
	Pointer string
	Code    string
	Detail  string
	Reason  string
}

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; Reason says why a person may not be Paged with not_pageable.

func (*FieldError) Error

func (e *FieldError) Error() string

type GatewayRef

type GatewayRef struct {
	PublicID string
	Name     string
	Live     bool
}

GatewayRef is the Notification gateway of a call step, Live while it is one: not deleted, its info declaring the role gateway.

type GroupChain

type GroupChain struct {
	RunID      string
	Chain      *ChainRef
	ChainName  string
	Sources    []SourceRef
	State      string
	Step       *StepPosition
	NextStepAt *time.Time
	StartedAt  time.Time
}

GroupChain is a run of the current start of an Alert Group's chains as its read shows it (AlertGroupChain): its chain, nil once deleted, with the name it had when the run started, its sources, its state, its current step while it runs and when the next is due.

type Holder

type Holder struct {
	Type     string
	PublicID string
	Name     string
}

Holder is a Route or a Team that names a chain, which keeps it from being deleted.

type InUseError

type InUseError struct {
	Holders []Holder
}

InUseError is ErrInUse with the Routes and Teams that name the chain.

func (*InUseError) Error

func (e *InUseError) Error() string

func (*InUseError) Unwrap

func (e *InUseError) Unwrap() error

type Input

type Input struct {
	Name         string
	Description  *string
	OwningTeamID *string
	Steps        []StepInput
	// ManagedBy is the mark of the tool that keeps the chain as code (C-33.FR-11).
	ManagedBy managedby.Input
}

Input is what createEscalationChain and updateEscalationChain write. A nil Description keeps the stored one on an update and is empty on a creation; a nil OwningTeamID keeps the stored owner on an update and is none on a creation, and an empty string clears it. Steps replace the stored ones as a whole.

type ListFilter

type ListFilter struct {
	Query    string
	Team     string
	MemberID int64
	After    *Position
	Limit    int
}

ListFilter selects a page of chains by name: matching Query when it is set, owned by Team (a public_id) or by the Teams of the User MemberID when one is set, after the position After.

type NamedRef

type NamedRef struct {
	PublicID string
	Name     string
}

NamedRef is an object by public_id and name.

type OnCalls

type OnCalls interface {
	OnCallAtIn(ctx context.Context, db mentions.DBTX, scheduleID string, t time.Time) (schedules.Segment, error)
}

OnCalls finds the person On-call in a Schedule at a time, nil in a gap, read through the step's transaction: (*schedules.Service).OnCallAtIn (S-131).

type Page

type Page struct {
	Chains []Chain
	Next   *Position
}

Page is a page of chains; Next, the position to continue after, is nil on the last page.

type Pages

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

Pages makes the Pages of the steps (StepPages).

func NewPages

func NewPages(cfg PagesConfig) *Pages

NewPages returns the Pages of cfg.

func (*Pages) FireRule

func (p *Pages) FireRule(ctx context.Context, d RuleDispatcher, tx groups.DBTX, id int64, deadline time.Time) (
	func(context.Context), error)

FireRule is the handler of the timer of a rule run, notification_rule_action, claimed with its deadline (C-31.FR-3): it reads the rule run by the timer's notification_rule_run_id, takes its Alert Group through it and locks it through the dispatcher (ChainStep), then lets the rule run make its actions due (notificationrules.Advance), which does nothing for a rule run that no longer runs or whose timer moved, and stops one whose Alert Group is no longer firing. A Mention it made is a Page of the step recorded as paged, "again" when the rule run Mentioned the person before, and each call it made a Page of the step by a call, or a skip of the person when its gateway or their contact there is gone (ruleCall). It returns what to run once tx committed.

func (*Pages) MakeStep

func (p *Pages) MakeStep(ctx context.Context, tx groups.DBTX, g *groups.Group, run RunRef, step StepRef,
	people []int64) (StepMade, error)

MakeStep makes the step of the run on g, locked in the dispatcher's transaction tx, with the people it may Page (StepPages): the Page of a page_on_call, page_people or page_team step, or the reason to skip a page_team step that no Destination of its chain can carry.

func (*Pages) StopRules

func (p *Pages) StopRules(ctx context.Context, tx groups.DBTX, groupID int64, at time.Time) error

StopRules stops the rule runs of the Alert Group groupID that still run (StepPages): its chains stopped or started over.

type PagesConfig

type PagesConfig struct {
	OnCalls  OnCalls
	Rules    RuleRuns
	Targets  groups.PageTargets
	Calls    Calls
	Business clock.Clock
}

PagesConfig is what the Pages need: the On-call of Schedules, the runs of the Notification rules, where a Page can go — delivery's PageTargets, for a page_team step —, the queue of calls through Notification gateways, without which nobody is called, and the business clock.

type Pool

type Pool interface {
	DBTX
	db.Beginner
}

Pool is the main pool: the queries, and the transactions of a change.

type Position

type Position struct {
	Name string `json:"n"`
	ID   int64  `json:"i"`
}

Position is the place of a chain in the list by name: its lowered name and its id.

type Queries

type Queries interface {
	GetOrganizationWorkingHours(ctx context.Context, orgID int64) (dbgen.GetOrganizationWorkingHoursRow, error)
	GetTeamWorkingHours(ctx context.Context, arg dbgen.GetTeamWorkingHoursParams) (dbgen.GetTeamWorkingHoursRow, error)
	ListChains(ctx context.Context, arg dbgen.ListChainsParams) ([]dbgen.ListChainsRow, error)
	GetChain(ctx context.Context, arg dbgen.GetChainParams) (dbgen.GetChainRow, error)
	LockChain(ctx context.Context, arg dbgen.LockChainParams) (int64, error)
	LockChainForDeletion(ctx context.Context, arg dbgen.LockChainForDeletionParams) (int64, error)
	LockOwningTeam(ctx context.Context, arg dbgen.LockOwningTeamParams) (dbgen.LockOwningTeamRow, error)
	InsertChain(ctx context.Context, arg dbgen.InsertChainParams) (int64, error)
	UpdateChain(ctx context.Context, arg dbgen.UpdateChainParams) error
	DeleteChain(ctx context.Context, arg dbgen.DeleteChainParams) error
	ListSteps(ctx context.Context, arg dbgen.ListStepsParams) ([]dbgen.ListStepsRow, error)
	ListStepUsers(ctx context.Context, arg dbgen.ListStepUsersParams) ([]dbgen.ListStepUsersRow, error)
	DeleteSteps(ctx context.Context, arg dbgen.DeleteStepsParams) error
	InsertStep(ctx context.Context, arg dbgen.InsertStepParams) (int64, error)
	InsertStepUsers(ctx context.Context, arg dbgen.InsertStepUsersParams) error
	ResolveSchedules(ctx context.Context, arg dbgen.ResolveSchedulesParams) ([]dbgen.ResolveSchedulesRow, error)
	ResolveUsers(ctx context.Context, arg dbgen.ResolveUsersParams) ([]dbgen.ResolveUsersRow, error)
	ResolveTeams(ctx context.Context, arg dbgen.ResolveTeamsParams) ([]dbgen.ResolveTeamsRow, error)
	ListGateways(ctx context.Context, orgID int64) ([]dbgen.ListGatewaysRow, error)
	ResolveDestinations(ctx context.Context, arg dbgen.ResolveDestinationsParams) ([]dbgen.ResolveDestinationsRow,
		error)
	ListRouteReferrers(ctx context.Context, arg dbgen.ListRouteReferrersParams) ([]dbgen.ListRouteReferrersRow, error)
	ListTeamReferrers(ctx context.Context, arg dbgen.ListTeamReferrersParams) ([]dbgen.ListTeamReferrersRow, error)
	ListChainDestinations(ctx context.Context, arg dbgen.ListChainDestinationsParams) (
		[]dbgen.ListChainDestinationsRow, error)
	ListUserTeams(ctx context.Context, arg dbgen.ListUserTeamsParams) ([]int64, error)
	GetTeamID(ctx context.Context, arg dbgen.GetTeamIDParams) (int64, error)
	ListChainInfo(ctx context.Context, orgID int64) ([]dbgen.ListChainInfoRow, error)
	audit.Store
	Notify(ctx context.Context, h db.Hint) error
}

Queries are the queries of the package, with the insert of the Audit log and the live hint.

type Referrers

type Referrers struct {
	Routes []RouteReferrer
	Teams  []TeamReferrer
}

Referrers are the Routes and the Teams that are not deleted and name a chain, by name.

type Requester

type Requester struct {
	Actor     audit.Actor
	Transport audit.Transport
	Address   netip.Addr
}

Requester is who asks for a change and how: the actor and the Transport of the Audit log entry, and the client address.

type RouteReferrer

type RouteReferrer struct {
	PublicID  string
	Name      string
	Condition string
}

RouteReferrer is a Route that names a chain with its Severity condition.

type RuleDispatcher

type RuleDispatcher interface {
	ChainStep(ctx context.Context, tx groups.DBTX, groupID int64,
		step func(ctx context.Context, g *groups.Group) (groups.ChainProgress, error)) (func(context.Context), error)
}

RuleDispatcher is the dispatcher through which the action of a rule run changes its Alert Group: (*groups.Service).ChainStep.

type RuleRuns

type RuleRuns interface {
	Start(ctx context.Context, tx notificationrules.DBTX, s notificationrules.Start) (notificationrules.Started, error)
	StopForGroup(ctx context.Context, tx notificationrules.DBTX, groupID int64, at time.Time) error
	Group(ctx context.Context, tx notificationrules.DBTX, id int64) (int64, bool, error)
	Advance(ctx context.Context, tx notificationrules.DBTX, id int64, deadline time.Time, firing bool) (
		*notificationrules.Due, error)
}

RuleRuns are the runs of the Notification rules: (*notificationrules.Runs).

type RunGroup

type RunGroup struct {
	PublicID string
	Number   int64
	Title    string
	Severity string
}

RunGroup is the Alert Group of a run.

type RunPage

type RunPage struct {
	Runs []ChainRun
	Next *RunPosition
}

RunPage is a page of the runs of a chain; Next is nil on the last page.

type RunPageView

type RunPageView struct {
	Kind     string
	Users    []UserRef
	Team     *TeamRef
	Everyone string
	Gateway  *GatewayRef
	Outcome  string
	Reason   string
}

RunPageView is a Page a step of a run made (EscalationRunPage): its kind, the people it names, or the Team or the word for everyone in the chat of a page_team step, the Notification gateway of a call, and its outcome with the reason it was not delivered.

type RunPosition

type RunPosition struct {
	At time.Time `json:"a"`
	ID int64     `json:"i"`
}

RunPosition is the place of a run in the list of a chain's runs, newest first.

type RunRef

type RunRef struct {
	ID            int64
	PublicID      string
	ChainID       int64
	ChainPublicID string
	ChainName     string
	OwningTeamID  int64
	Sources       []RunSource
}

RunRef names a run and its chain for StepPages, with the owning Team the chain had when the run started and its sources.

type RunSource

type RunSource struct {
	Kind   string
	TeamID int64
}

RunSource is a source of a run: the Route, or a Team by id.

type RunStepView

type RunStepView struct {
	Number  int
	Kind    string
	At      time.Time
	Outcome string
	Reason  string
	Pages   []RunPageView
	// contains filtered or unexported fields
}

RunStepView is a step a run made or skipped, with the reason of a skip and the Pages of a made step; seq is its place among the steps the run made, repeated ones included (escalation_run_steps.seq).

type Runs

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

Runs holds the runs of the Organization's Escalation chains and implements groups.ChainRuns. Its zero value runs nothing; RunsConfig fills it.

func (*Runs) ChainRuns

func (r *Runs) ChainRuns(ctx context.Context, publicID string, after *RunPosition, limit int) (RunPage, error)

ChainRuns lists a page of the recent runs of the chain publicID, newest first, after the position after (C-32.FR-18, "How it went"), each step with its Pages, without the steps — and so the Pages — of a run whose Alert Group's details are removed (C-09.FR-16); an unknown chain is ErrNotFound. It reads the runs, then their steps, then their Pages, one query each per page of runs.

func (*Runs) FireStep

func (r *Runs) FireStep(ctx context.Context, tx DBTX, runID int64, deadline time.Time) (func(context.Context), error)

FireStep is the handler of the timer of a run, claimed with its deadline (C-32.FR-5, FR-14, FR-15): it reads the run by the timer's escalation_run_id, locks its Alert Group through the dispatcher (ChainStep) and then the run, and does nothing when the run no longer runs or its timer was moved or removed since it was claimed, so that a second replica firing the same step changes nothing; a run whose Alert Group is no longer firing, as a replica of an earlier version leaves it, which stops no run, is stopped then. Otherwise it makes the steps from the current one on: a step that Pages or sends is skipped, recording escalation_step_skipped, outside the Working hours of its chain when it is limited to them, for a Severity level its condition does not meet, in a gap of the Schedule it Pages, or for a person it names who became a Viewer or was disabled since; it is made otherwise, by StepPages (pages.go). A step "Send to an outgoing webhook" is also skipped when its Destination was deleted or takes no events any more, and is made by recording escalation_webhook (webhook.go). Skips and Pages go on at once; a wait sets the timer at the end of the wait, from the deadline the step was due, on the business clock, and a wait that is already over by then goes on, except before a step that would Page again only whom this late firing already Paged, which waits from now as long as it would have after them (walk.page); a repeat goes back to its step until it did so its times. After the last step the run has run out, which ChainsRanOut checks for the whole start. It returns what to run once tx committed.

func (*Runs) GroupChains

func (r *Runs) GroupChains(ctx context.Context, publicIDs []string) (map[string][]GroupChain, error)

GroupChains reads, for each of the Alert Groups publicIDs, the runs of the current start of its chains, in the order they started (C-32.FR-18, C-09.FR-1): none before its chains first started.

func (*Runs) RanOut

func (r *Runs) RanOut(ctx context.Context, tx groups.DBTX, g *groups.Group) (bool, error)

RanOut reports whether every run of the current start of g ran out: at least one, none running and none stopped (groups.ChainRuns, C-32.FR-7).

func (*Runs) Start

func (r *Runs) Start(ctx context.Context, tx groups.DBTX, g *groups.Group, st groups.ChainStart) (int, error)

Start starts the chains that apply to g in its current start (groups.ChainRuns): those its Route names and, where the Route delivers to the Teams and runs their chains, those its Teams name, each whose Severity condition its level meets, one run per chain however many name it (C-32.FR-4, P-70). At a start or a start-over (All) every such chain starts, after any run still running from an earlier start is stopped as started_over; otherwise only those whose condition a rise from Before newly meets and those a Team that joined names, and a chain that already runs in this start takes the sources that now name it. Each run takes the chain's steps as they are (P-73) and its timer at its first step, due at once.

func (*Runs) Started

func (r *Runs) Started(ctx context.Context, tx groups.DBTX, g *groups.Group) (bool, error)

Started reports whether chains started in the current start of g (groups.ChainRuns).

func (*Runs) Stop

func (r *Runs) Stop(ctx context.Context, tx groups.DBTX, g *groups.Group, st groups.ChainStop) error

Stop stops every run of g that still runs, with the Command and the lifecycle event that stopped it, and deletes their timers (groups.ChainRuns); runs that ran out stay as they are (C-32.FR-5).

type RunsConfig

type RunsConfig struct {
	DB      DBTX
	Groups  Dispatcher
	OnCalls OnCalls
	Pages   StepPages
	Log     *logging.Logger
}

RunsConfig is what the runs need: the main pool for the reads, the dispatcher, the On-call of Schedules, the Pages of the steps (NewPages) and the log; without Pages a step Pages nobody.

type ScheduleRef

type ScheduleRef struct {
	PublicID string
	Name     string
	Team     TeamRef
}

ScheduleRef is the Schedule a step names, with its Team.

type Service

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

Service holds the Escalation chains of the Organization.

func New

func New(cfg Config) *Service

New returns the Service of the Organization in cfg.

func (*Service) Create

func (s *Service) Create(ctx context.Context, r Requester, in Input) (Chain, error)

Create creates a chain with its steps. A name another chain has is ErrNameTaken.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, r Requester, publicID string, version *int64) error

Delete deletes the chain publicID with its steps; a non-nil version must be its current one. A chain that a Route or a Team that is not deleted names is refused with InUseError, read under the lock FOR UPDATE that the saves naming it wait for (C-32.FR-2).

func (*Service) Get

func (s *Service) Get(ctx context.Context, publicID string) (Chain, error)

Get reads the chain publicID; an unknown one is ErrNotFound.

func (*Service) InfoChanged

func (s *Service) InfoChanged()

InfoChanged asks RunInfo to refresh muster_escalation_chain_info: a hint said a chain changed, maybe on another replica. It never blocks.

func (*Service) List

func (s *Service) List(ctx context.Context, f ListFilter) (Page, error)

List lists a page of the chains by name.

func (*Service) RefreshInfo

func (s *Service) RefreshInfo(ctx context.Context) error

RefreshInfo makes muster_escalation_chain_info list exactly the chains the database has, whichever replica changed them (C-32.FR-19).

func (*Service) RunInfo

func (s *Service) RunInfo(ctx context.Context, ticks <-chan time.Time)

RunInfo keeps muster_escalation_chain_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) Runs

func (s *Service) Runs(cfg RunsConfig) *Runs

Runs returns the runs of the chains of s.

func (*Service) Update

func (s *Service) Update(ctx context.Context, r Requester, publicID string, version *int64, in Input) (Chain, error)

Update replaces the name and the steps of the chain publicID, and its description and owner when given; a non-nil version must be its current one (If-Match). An update that changes nothing writes nothing. The people, the gateway and the Destination that the stored steps name pass as they are; what the update adds is checked (steps.go).

func (*Service) WorkingHoursOf

func (s *Service) WorkingHoursOf(ctx context.Context, c Chain) (teams.WorkingHours, error)

WorkingHoursOf are the Working hours a step of the chain limited to Working hours uses (C-25.FR-9, C-32.FR-3): those of its owning Team — its own, else the Organization's, as teams.Effective says — and the Organization's for a chain without one.

type SourceRef

type SourceRef struct {
	Kind string
	Team *TeamRef
}

SourceRef is a source of a run as the API names it: the Route, or a Team.

type Step

type Step struct {
	Number           int
	Kind             string
	Importance       string
	Schedule         *ScheduleRef
	Users            []UserRef
	Team             *TeamRef
	Everyone         string
	CallTarget       string
	Gateway          *GatewayRef
	WaitSeconds      int
	Destination      *DestinationTarget
	RepeatFrom       int
	RepeatTimes      int
	WorkingHoursOnly bool
	Condition        string
}

Step is a step of a chain as a read gives it, with its number from 1 and the objects it names: Team is the Team a page_team step names itself, nil when it Pages the chain's owning Team or everyone.

func (Step) Pages

func (st Step) Pages() bool

Pages reports whether the step Pages or sends, and so takes the limit to Working hours and a Severity condition.

type StepInput

type StepInput struct {
	Kind             string
	Importance       *string
	ScheduleID       *string
	UserIDs          *[]string
	TeamID           *string
	Everyone         *string
	CallTarget       *string
	GatewayID        *string
	WaitSeconds      *int
	DestinationID    *string
	RepeatFrom       *int
	RepeatTimes      *int
	WorkingHoursOnly *bool
	Condition        *string
}

StepInput is a step of a request body; a nil field was not given.

type StepMade

type StepMade struct {
	Pages []groups.StepPage
	Skips []groups.StepSkip
	Skip  string
}

StepMade is what StepPages made of a step: its Pages, by Mention and by a call, and the skips of the people it could not call (C-32.FR-14, C-31.FR-3); or the reason to skip it, which those skips stand for when it has any.

type StepPages

type StepPages interface {
	MakeStep(ctx context.Context, tx groups.DBTX, g *groups.Group, run RunRef, step StepRef, people []int64) (
		StepMade, error)
	StopRules(ctx context.Context, tx groups.DBTX, groupID int64, at time.Time) error
}

StepPages makes what a step that Pages does — a Page of the On-call, of chosen people or of a whole Team, a call — once the run decided to make it, with the people it may Page (pages.go, calls.go), and stops the runs of the Notification rules of the runs that stop or start over (C-31.FR-3). A webhook step does not reach it: the run records its escalation_webhook itself (webhook.go).

type StepPosition

type StepPosition struct {
	Number int
	Kind   string
}

StepPosition is the step a run is at: its number and kind.

type StepRef

type StepRef struct {
	Seq        int
	Number     int
	Kind       string
	Importance string
	ScheduleID int64
	Schedule   string
	TeamID     int64
	Everyone   string
	GatewayID  int64
	CallTarget string
}

StepRef is the step of a run that StepPages makes, as the chain had it when the run started, its Schedule by id and by public_id, and Seq, the seq of the run step it is recorded as, which orders the steps of the run, repeated ones included (escalation_run_steps.seq), for the Assignees (C-32.FR-12).

type StoppedBy

type StoppedBy struct {
	Command string
	Actor   *Actor
}

StoppedBy is what stopped a run: the Command, and the person who ran it, nil for Muster (a Resolve by its Alerts).

type Store

type Store interface {
	Queries
	InTx(ctx context.Context, f func(Queries) error) error
}

Store runs the queries alone or in one transaction.

func NewStore

func NewStore(p Pool) Store

NewStore is the Store over the main pool.

type TeamRef

type TeamRef struct {
	ID       int64
	PublicID string
	Name     string
	Slug     string
	Deleted  bool
}

TeamRef names a Team, marked deleted once deleted.

type TeamReferrer

type TeamReferrer struct {
	Team      TeamRef
	Condition string
}

TeamReferrer is a Team that names a chain with its Severity condition.

type UserRef

type UserRef struct {
	PublicID string
	Name     string
	Login    string
	Role     string
	Status   string
}

UserRef is a person a step names, with their Role and status.

type Warning

type Warning struct {
	Kind        string
	Step        int
	Destination *NamedRef
	Reason      string
}

Warning is what a step of a chain cannot do: its kind, the step's number — 0 for pages_nobody, which concerns the chain as a whole — the Destination it concerns — the one that cannot mention, or the deleted one — and, for everyone_unsupported, the reason of mentions.Can (MentionUnavailableReason).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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