alerts

package
v2.32.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SeverityCrit describes an alert which requires immediate action.
	SeverityCrit alertSeverity = "crit"

	// SeverityWarn describes an alert which requires further observation.
	SeverityWarn alertSeverity = "warn"

	// SeverityInfo describes an alert which has informational purposes.
	SeverityInfo alertSeverity = "info"

	// SeverityUnknown describes an alert which does not have severity set.
	SeverityUnknown alertSeverity = ""
)

Variables

View Source
var AlertsFxTag = config.NameTag("AlertsFx")

AlertsFxTag - name tag for alerter in fx.

Functions

func Module

func Module() fx.Option

Module is a fx module that constructs annotated instance of alerts.Alerter.

func ParseSeverity

func ParseSeverity(rawSeverity string) alertSeverity

ParseSeverity returns alert severity parsed from string. Returns SeverityUnknown if parsing fails.

Types

type Alert

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

Alert is a wrapper around models.PostableAlert with handy transform methods.

func AlertsFromLogs

func AlertsFromLogs(ld plog.Logs) []*Alert

AlertsFromLogs gets slice of alerts from OTel Logs.

func NewAlert

func NewAlert(opts ...AlertOption) *Alert

NewAlert creates new instance of Alert with StartsAt set to now.

func NewAlertFromPostableAlert

func NewAlertFromPostableAlert(postabelAlert models.PostableAlert) *Alert

NewAlertFromPostableAlert creates new alert with given PostableAlert.

func (*Alert) AlertChannels

func (a *Alert) AlertChannels() []string

AlertChannels gets the alert channels from labels. Returns empty slice if label not found.

func (*Alert) AsLogs

func (a *Alert) AsLogs() plog.Logs

AsLogs returns alert as OTel Logs.

func (*Alert) Name

func (a *Alert) Name() string

Name gets the alert name from labels. Returns empty string if label not found.

func (*Alert) PostableAlert

func (a *Alert) PostableAlert() models.PostableAlert

PostableAlert returns the underlying PostableAlert struct.

func (*Alert) SetAlertChannels

func (a *Alert) SetAlertChannels(alertChannels []string)

SetAlertChannels sets the alert channels in labels. Overwrites previous value if exists.

func (*Alert) SetAnnotation

func (a *Alert) SetAnnotation(key, value string)

SetAnnotation sets a single annotation. It overwrites the previous value if exists.

func (*Alert) SetGeneratorURL

func (a *Alert) SetGeneratorURL(value string)

SetGeneratorURL sets a generator URL. It overwrites the previous value if exists.

func (*Alert) SetLabel

func (a *Alert) SetLabel(key, value string)

SetLabel sets a single label. It overwrites the previous value if exists.

func (*Alert) SetName

func (a *Alert) SetName(name string)

SetName sets the alert name in labels. Overwrites previous value if exists.

func (*Alert) SetResolveTimeout

func (a *Alert) SetResolveTimeout(t time.Duration)

SetResolveTimeout sets a resolve timeout which says when given alert becomes resolved.

func (*Alert) SetSeverity

func (a *Alert) SetSeverity(severity alertSeverity)

SetSeverity sets the alert severity in labels. Overwrites previous value if exists.

func (*Alert) Severity

func (a *Alert) Severity() alertSeverity

Severity gets the alert severity from labels. Returns empty string if label not found.

type AlertOption

type AlertOption func(*Alert)

AlertOption is a type for constructor options.

func WithAlertChannels

func WithAlertChannels(alertChannels []string) AlertOption

WithAlertChannels is an option function for constructor.

func WithAnnotation

func WithAnnotation(key, value string) AlertOption

WithAnnotation is an option function for constructor.

func WithGeneratorURL

func WithGeneratorURL(value string) AlertOption

WithGeneratorURL is an option function for constructor.

func WithLabel

func WithLabel(key, value string) AlertOption

WithLabel is an option function for constructor.

func WithName

func WithName(name string) AlertOption

WithName is an option function for constructor.

func WithResolveTimeout

func WithResolveTimeout(t time.Duration) AlertOption

WithResolveTimeout is an option function for constructor.

func WithSeverity

func WithSeverity(severity alertSeverity) AlertOption

WithSeverity is an option function for constructor.

type Alerter

type Alerter interface {
	AddAlert(*Alert)
	AlertsChan() <-chan *Alert
	WithLabels(map[string]string) Alerter
}

Alerter is responsible for receiving alerts and propagating them to the channel returned by AlertsChan().

func NewSimpleAlerter

func NewSimpleAlerter(channelSize int) Alerter

NewSimpleAlerter returns new instance of SimpleAlerter with channel of given size.

func ProvideAlerter

func ProvideAlerter(unmarshaller config.Unmarshaller) (Alerter, error)

ProvideAlerter creates an alerter.

type AlerterConfig

type AlerterConfig struct {
	// ChannelSize size of the alerts channel in the alerter. Alerts should be
	// consumed from it quickly, so no big sizes are needed.
	ChannelSize int `json:"channel_size" validate:"gt=0" default:"100"`
}

AlerterConfig for alerter. swagger:model +kubebuilder:object:generate=true

func (*AlerterConfig) DeepCopy

func (in *AlerterConfig) DeepCopy() *AlerterConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AlerterConfig.

func (*AlerterConfig) DeepCopyInto

func (in *AlerterConfig) DeepCopyInto(out *AlerterConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type SimpleAlerter

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

SimpleAlerter implements Alerter interface. It just simple propagates alerts to the channel.

func (*SimpleAlerter) AddAlert

func (a *SimpleAlerter) AddAlert(alert *Alert)

AddAlert adds alert to the channel.

func (*SimpleAlerter) AlertsChan

func (a *SimpleAlerter) AlertsChan() <-chan *Alert

AlertsChan returns the alerts channel.

func (*SimpleAlerter) WithLabels

func (a *SimpleAlerter) WithLabels(labels map[string]string) Alerter

WithLabels returns the alerter wrapper with specified labels.

Jump to

Keyboard shortcuts

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