Documentation
¶
Index ¶
- func ActiveTimeIntervalNames(ctx context.Context) ([]string, bool)
- func FiringAlerts(ctx context.Context) ([]uint64, bool)
- func GetTemplateData(ctx context.Context, tmpl *template.Template, alerts []*alert.Alert) *template.Data
- func GroupKey(ctx context.Context) (string, bool)
- func GroupLabels(ctx context.Context) (label.LabelSet, bool)
- func MuteTimeIntervalNames(ctx context.Context) ([]string, bool)
- func Now(ctx context.Context) (time.Time, bool)
- func ReceiverName(ctx context.Context) (string, bool)
- func RepeatInterval(ctx context.Context) (time.Duration, bool)
- func ResolvedAlerts(ctx context.Context) ([]uint64, bool)
- func Tenant(ctx context.Context) (string, bool)
- func TmplHTML(tmpl *template.Template, data *template.Data, err *error) func(string) string
- func TmplText(tmpl *template.Template, data *template.Data, err *error) func(string) string
- func WithActiveTimeIntervals(ctx context.Context, at []string) context.Context
- func WithFiringAlerts(ctx context.Context, alerts []uint64) context.Context
- func WithGroupKey(ctx context.Context, s string) context.Context
- func WithGroupLabels(ctx context.Context, lset label.LabelSet) context.Context
- func WithMuteTimeIntervals(ctx context.Context, mt []string) context.Context
- func WithNow(ctx context.Context, t time.Time) context.Context
- func WithReceiverName(ctx context.Context, rcv string) context.Context
- func WithRepeatInterval(ctx context.Context, t time.Duration) context.Context
- func WithResolvedAlerts(ctx context.Context, alerts []uint64) context.Context
- func WithTenant(ctx context.Context, tenant string) context.Context
- type CustomerConfigFunc
- type DedupStage
- type EntryQuery
- type EventSubscribeStage
- type FanoutStage
- type Integration
- type Key
- type Log
- func (l *Log) GC() (int, error)
- func (l *Log) Log(ctx context.Context, r *profile.ReceiverKey, gkey string, ...) error
- func (l *Log) MarshalBinary() ([]byte, error)
- func (l *Log) Merge(b []byte) error
- func (l *Log) Name() string
- func (l *Log) Query(params ...EntryQuery) ([]*LogEntry, error)
- func (l *Log) Start(ctx context.Context) error
- func (l *Log) Stop(ctx context.Context) error
- type LogEntry
- type LogOptions
- type MaintenanceFunc
- type MultiStage
- type MuteStage
- type NLogCallback
- type NotificationLog
- type Notifier
- type PipelineBuilder
- type ResolvedSender
- type Retrier
- type RetryStage
- type RoutingStage
- type SetNotifiesStage
- type Stage
- type StageFunc
- type Subscriber
- type TimeActiveStage
- type TimeMuteStage
- type UserInfo
- type WaitStage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActiveTimeIntervalNames ¶
ActiveTimeIntervalNames extracts a slice of active time names from the context. If none exists, the second argument is false.
func FiringAlerts ¶
FiringAlerts extracts a slice of firing alerts from the context. Iff none exists, the second argument is false.
func GetTemplateData ¶
func GetTemplateData(ctx context.Context, tmpl *template.Template, alerts []*alert.Alert) *template.Data
GetTemplateData creates the template data from the context and the alerts.
func GroupKey ¶
GroupKey extracts a group key from the context. Iff none exists, the second argument is false.
func GroupLabels ¶
GroupLabels extracts grouping label set from the context. Iff none exists, the second argument is false.
func MuteTimeIntervalNames ¶
MuteTimeIntervalNames extracts a slice of mute time names from the context. If and only if none exists, the second argument is false.
func Now ¶
Now extracts a now timestamp from the context. Iff none exists, the second argument is false.
func ReceiverName ¶
ReceiverName extracts a receiver name from the context. Iff none exists, the second argument is false.
func RepeatInterval ¶
RepeatInterval extracts a repeat interval from the context. Iff none exists, the second argument is false.
func ResolvedAlerts ¶
ResolvedAlerts extracts a slice of firing alerts from the context. Iff none exists, the second argument is false.
func TmplHTML ¶
TmplHTML is using monadic error handling in order to make string templating less verbose. Use with care as the final error checking is easily missed.
func TmplText ¶
TmplText is using monadic error handling in order to make string templating less verbose. Use with care as the final error checking is easily missed.
func WithActiveTimeIntervals ¶
func WithFiringAlerts ¶
WithFiringAlerts populates a context with a slice of firing alerts.
func WithGroupKey ¶
WithGroupKey populates a context with a group key.
func WithGroupLabels ¶
WithGroupLabels populates a context with grouping labels.
func WithMuteTimeIntervals ¶
WithMuteTimeIntervals populates a context with a slice of mute time names.
func WithReceiverName ¶
WithReceiverName populates a context with a receiver name.
func WithRepeatInterval ¶
WithRepeatInterval populates a context with a repeat interval.
func WithResolvedAlerts ¶
WithResolvedAlerts populates a context with a slice of resolved alerts.
Types ¶
type CustomerConfigFunc ¶
CustomerConfigFunc is a function that can be overridden by out component. the function constrained the original configuration cannot be modified
type DedupStage ¶
type DedupStage struct {
// contains filtered or unexported fields
}
DedupStage filters alerts. Filtering happens based on a notification log.
func NewDedupStage ¶
func NewDedupStage(rs ResolvedSender, l NotificationLog, recv *profile.ReceiverKey) *DedupStage
NewDedupStage wraps a DedupStage that runs against the given notification log.
type EntryQuery ¶
func QGroupKey ¶
func QGroupKey(gk string) EntryQuery
func QReceiver ¶
func QReceiver(r *profile.ReceiverKey) EntryQuery
type EventSubscribeStage ¶
type EventSubscribeStage struct { Subs Subscriber // contains filtered or unexported fields }
EventSubscribeStage is a stage for if the alert is event type and not specify the recipient,then subscribe the user.
func NewEventSubscribeStage ¶
func NewEventSubscribeStage(alerts provider.Alerts, subs Subscriber) *EventSubscribeStage
func (EventSubscribeStage) Exec ¶
func (u EventSubscribeStage) Exec(ctx context.Context, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error)
Exec implements the Stage interface. If the alert has a label "to", it will be used as the recipient.means the alert will be sent to the user. Need to not handle subscribing.
type Integration ¶
type Integration struct {
// contains filtered or unexported fields
}
Integration wraps a notifier and its configuration to be uniquely identified by name and index from its origin in the configuration.
func NewIntegration ¶
func NewIntegration(notifier Notifier, name string, idx int) Integration
NewIntegration returns a new integration.
func (*Integration) Index ¶
func (i *Integration) Index() int
Index returns the index of the integration.
func (*Integration) Name ¶
func (i *Integration) Name() string
Name returns the name of the integration.
func (*Integration) SendResolved ¶
func (i *Integration) SendResolved() bool
SendResolved implements the ResolvedSender interface.
func (*Integration) String ¶
func (i *Integration) String() string
String implements the Stringer interface.
type Key ¶
type Key string
Key is a string that can be hashed.
func ExtractGroupKey ¶
ExtractGroupKey gets the group key from the context.
type Log ¶
type Log struct { LogOptions // contains filtered or unexported fields }
Log holds the notification log state for alerts that have been notified.
func NewLog ¶
func NewLog(cfg *conf.Configuration) (*Log, error)
NewLog creates a new notification log based on the provided options.
func (*Log) MarshalBinary ¶
MarshalBinary serializes all contents of the notification log.
func (*Log) Merge ¶
Merge merges notification log state received from the cluster with the local state.
type LogEntry ¶
type LogEntry struct { ID int `json:"id,omitempty"` ExpiresAt time.Time `json:"expires_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` // The key identifying the dispatching group. GroupKey string `json:"group_key,omitempty"` Receiver profile.ReceiverKey `json:"receiver,omitempty"` ReceiverType profile.ReceiverType `json:"receiver_type,omitempty"` Idx int `json:"idx,omitempty"` FiringAlerts []uint64 `json:"firing_alerts,omitempty"` ResolvedAlerts []uint64 `json:"resolved_alerts,omitempty"` }
func (*LogEntry) IsFiringSubset ¶
IsFiringSubset returns whether the given subset is a subset of the alerts that were firing at the time of the last notification.
func (*LogEntry) IsResolvedSubset ¶
IsResolvedSubset returns whether the given subset is a subset of the alerts that were resolved at the time of the last notification.
type LogOptions ¶
type LogOptions struct { // Retention is the duration for which notifications log are kept in the state. default 120h Retention time.Duration NLogCallback NLogCallback Spreader members.Spreader // MaintenanceInterval alert manager garbage collects the notification log state at the given interval. // default 15m MaintenanceInterval time.Duration // MaintenanceFunc represents the function to run as part of the periodic maintenance for the nflog. MaintenanceFunc MaintenanceFunc }
LogOptions configures a new Log implementation.
type MaintenanceFunc ¶
type MaintenanceFunc func() error
MaintenanceFunc represents the function to run as part of the periodic maintenance for the nflog.
type MuteStage ¶
type MuteStage struct {
// contains filtered or unexported fields
}
MuteStage filters alerts through a Muter.
func NewMuteStage ¶
NewMuteStage return a new MuteStage.
type NLogCallback ¶
type NLogCallback interface { LoadData() ([]*LogEntry, error) // CreateLog creates a new notification log entry. returns the id of the log entry. CreateLog(ctx context.Context, r *profile.ReceiverKey, gkey string, firingAlerts, resolvedAlerts []uint64, expiresAt time.Time) (int, error) EvictLog(ctx context.Context, ids []int) }
NLogCallback is the interface that must be implemented by the notification log callback.
type NotificationLog ¶
type NotificationLog interface { woocoo.Server Log(ctx context.Context, r *profile.ReceiverKey, gkey string, firingAlerts, resolvedAlerts []uint64, expiry time.Duration) error Query(params ...EntryQuery) ([]*LogEntry, error) }
NotificationLog is the interface for the notification log. It provides methods to persist and query notifications.
type Notifier ¶
type Notifier interface { ResolvedSender // Notify sends notifications for the given alerts. Returns a bool value whether retrying Notify(context.Context, ...*alert.Alert) (bool, error) }
Notifier notifies about alerts under constraints of the given context. It returns an error if unsuccessful and a flag whether the error is recoverable. This information is useful for a retry logic.
type PipelineBuilder ¶
type PipelineBuilder struct { }
func NewPipelineBuilder ¶
func NewPipelineBuilder() *PipelineBuilder
func (*PipelineBuilder) New ¶
func (pb *PipelineBuilder) New( receivers map[string][]Integration, wait func() time.Duration, inhibitor *inhibit.Inhibitor, silencer *silence.Silencer, times map[string][]timeinterval.TimeInterval, notificationLog NotificationLog, alerts provider.Alerts, subscriber Subscriber, ) RoutingStage
New returns a map of receivers to Stages.
type ResolvedSender ¶
type ResolvedSender interface {
SendResolved() bool
}
ResolvedSender returns true if resolved notifications should be sent.
type Retrier ¶
type Retrier struct { // Function to return additional information in the error message. CustomDetailsFunc func(code int, body io.Reader) string // Additional HTTP status codes that should be retried. RetryCodes []int }
Retrier knows when to retry an HTTP request to a receiver. 2xx status codes are successful, anything else is a failure and only 5xx status codes should be retried.
type RetryStage ¶
type RetryStage struct {
// contains filtered or unexported fields
}
RetryStage notifies via passed integration with exponential backoff until it succeeds. It aborts if the context is canceled or timed out.
func NewRetryStage ¶
func NewRetryStage(i Integration, groupName string) *RetryStage
NewRetryStage returns a new instance of a RetryStage.
type RoutingStage ¶
RoutingStage executes the inner stages based on the receiver specified in the context.
type SetNotifiesStage ¶
type SetNotifiesStage struct {
// contains filtered or unexported fields
}
SetNotifiesStage sets the notification information about passed alerts. The passed alerts should have already been sent to the receivers.
func NewSetNotifiesStage ¶
func NewSetNotifiesStage(l NotificationLog, recv *profile.ReceiverKey) *SetNotifiesStage
NewSetNotifiesStage returns a new instance of a SetNotifiesStage.
type Stage ¶
type Stage interface {
Exec(ctx context.Context, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error)
}
A Stage processes alerts under the constraints of the given context.
type StageFunc ¶
type StageFunc func(ctx context.Context, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error)
StageFunc wraps a function to represent a Stage.
type Subscriber ¶
type Subscriber interface { // SubUsers returns a list of subscribers by alert event name.if you don't have an event name,will return empty. SubUsers(context.Context, *alert.Alert) ([]UserInfo, error) }
Subscriber is an interface for subscription
type TimeActiveStage ¶
type TimeActiveStage timeStage
func NewTimeActiveStage ¶
func NewTimeActiveStage(ti map[string][]timeinterval.TimeInterval) *TimeActiveStage
type TimeMuteStage ¶
type TimeMuteStage timeStage
func NewTimeMuteStage ¶
func NewTimeMuteStage(ti map[string][]timeinterval.TimeInterval) *TimeMuteStage
type UserInfo ¶
UserInfo include base user notify info for event type alert which not specify the recipient.
type WaitStage ¶
type WaitStage struct {
// contains filtered or unexported fields
}
WaitStage waits for a certain amount of time before continuing or until the context is done.
func NewWaitStage ¶
NewWaitStage returns a new WaitStage.