alert

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: Apache-2.0 Imports: 27 Imported by: 4

Documentation

Overview

Package alert contains logic to send alert notifications to Alertmanager clusters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressProvider added in v0.10.0

type AddressProvider interface {
	Resolve(context.Context, []string)
	Addresses() []string
}

type Alert

type Alert struct {
	// Label value pairs for purpose of aggregation, matching, and disposition
	// dispatching. This must minimally include an "alertname" label.
	Labels labels.Labels `json:"labels"`

	// Extra key/value information which does not define alert identity.
	Annotations labels.Labels `json:"annotations"`

	// The known time range for this alert. Start and end time are both optional.
	StartsAt     time.Time `json:"startsAt,omitempty"`
	EndsAt       time.Time `json:"endsAt,omitempty"`
	GeneratorURL string    `json:"generatorURL,omitempty"`
}

Alert is a generic representation of an alert in the Prometheus eco-system.

func (*Alert) Hash

func (a *Alert) Hash() uint64

Hash returns a hash over the alert. It is equivalent to the alert labels hash.

func (*Alert) Name

func (a *Alert) Name() string

Name returns the name of the alert. It is equivalent to the "alertname" label.

func (*Alert) Resolved

func (a *Alert) Resolved() bool

Resolved returns true iff the activity interval ended in the past.

func (*Alert) ResolvedAt

func (a *Alert) ResolvedAt(ts time.Time) bool

ResolvedAt returns true off the activity interval ended before the given timestamp.

func (*Alert) String

func (a *Alert) String() string

type AlertingConfig added in v0.10.0

type AlertingConfig struct {
	Alertmanagers []AlertmanagerConfig `yaml:"alertmanagers"`
}

func LoadAlertingConfig added in v0.10.0

func LoadAlertingConfig(confYaml []byte) (AlertingConfig, error)

LoadAlertmanagerConfigs loads a list of AlertmanagerConfig from YAML data.

type Alertmanager added in v0.10.0

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

Alertmanager represents an HTTP client that can send alerts to a cluster of Alertmanager endpoints.

func NewAlertmanager added in v0.10.0

func NewAlertmanager(logger log.Logger, cfg AlertmanagerConfig, provider AddressProvider) (*Alertmanager, error)

NewAlertmanager returns a new Alertmanager client.

func (*Alertmanager) Discover added in v0.10.0

func (a *Alertmanager) Discover(ctx context.Context)

Discover runs the service to discover target endpoints.

func (*Alertmanager) Do added in v0.10.0

func (a *Alertmanager) Do(ctx context.Context, u *url.URL, r io.Reader) error

Do sends a POST request to the given URL.

func (*Alertmanager) Endpoints added in v0.10.0

func (a *Alertmanager) Endpoints() []*url.URL

Endpoints returns the list of known Alertmanager endpoints.

func (*Alertmanager) Resolve added in v0.10.0

func (a *Alertmanager) Resolve(ctx context.Context)

Resolve refreshes and resolves the list of Alertmanager targets.

type AlertmanagerClient added in v0.10.0

type AlertmanagerClient interface {
	Endpoints() []*url.URL
	Do(context.Context, *url.URL, io.Reader) error
}

type AlertmanagerConfig added in v0.10.0

type AlertmanagerConfig struct {
	// HTTP client configuration.
	HTTPClientConfig http_util.ClientConfig `yaml:"http_config"`

	// List of addresses with DNS prefixes.
	StaticAddresses []string `yaml:"static_configs"`
	// List of file  configurations (our FileSD supports different DNS lookups).
	FileSDConfigs []FileSDConfig `yaml:"file_sd_configs"`

	// The URL scheme to use when talking to Alertmanagers.
	Scheme string `yaml:"scheme"`

	// Path prefix to add in front of the push endpoint path.
	PathPrefix string `yaml:"path_prefix"`

	// The timeout used when sending alerts (default: 10s).
	Timeout model.Duration `yaml:"timeout"`
}

AlertmanagerConfig represents a client to a cluster of Alertmanager endpoints. TODO(simonpasquier): add support for API version (v1 or v2).

func BuildAlertmanagerConfig added in v0.10.0

func BuildAlertmanagerConfig(logger log.Logger, address string, timeout time.Duration) (AlertmanagerConfig, error)

BuildAlertmanagerConfig initializes and returns an Alertmanager client configuration from a static address.

func DefaultAlertmanagerConfig added in v0.10.0

func DefaultAlertmanagerConfig() AlertmanagerConfig

func (*AlertmanagerConfig) UnmarshalYAML added in v0.10.0

func (c *AlertmanagerConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type FileSDConfig added in v0.10.0

type FileSDConfig struct {
	Files           []string       `yaml:"files"`
	RefreshInterval model.Duration `yaml:"refresh_interval"`
}

type Queue

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

Queue is a queue of alert notifications waiting to be sent. The queue is consumed in batches and entries are dropped at the front if it runs full.

func NewQueue

func NewQueue(logger log.Logger, reg prometheus.Registerer, capacity, maxBatchSize int, externalLset labels.Labels, excludeLabels []string) *Queue

NewQueue returns a new queue. The given label set is attached to all alerts pushed to the queue. The given exclude label set tells what label names to drop including external labels.

func (*Queue) Cap

func (q *Queue) Cap() int

Cap returns the fixed capacity of the queue.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the current length of the queue.

func (*Queue) Pop

func (q *Queue) Pop(termc <-chan struct{}) []*Alert

Pop takes a batch of alerts from the front of the queue. The batch size is limited according to the queues maxBatchSize limit. It blocks until elements are available or a termination signal is send on termc.

func (*Queue) Push

func (q *Queue) Push(alerts []*Alert)

Push adds a list of alerts to the queue.

type Sender

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

Sender sends notifications to a dynamic set of alertmanagers.

func NewSender

func NewSender(
	logger log.Logger,
	reg prometheus.Registerer,
	alertmanagers []AlertmanagerClient,
) *Sender

NewSender returns a new sender. On each call to Send the entire alert batch is sent to each Alertmanager returned by the getter function.

func (*Sender) Send

func (s *Sender) Send(ctx context.Context, alerts []*Alert)

Send an alert batch to all given Alertmanager clients. TODO(bwplotka): https://github.com/thanos-io/thanos/issues/660.

Jump to

Keyboard shortcuts

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