alerting

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownType   = "unknown"
	ThresholdType = "threshold"
)

Rule types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	RuleID    string     `json:"ruleId"`
	Ingress   string     `json:"ingress"`
	Service   string     `json:"service"`
	Points    []Point    `json:"points"`
	Logs      []byte     `json:"logs"`
	Threshold *Threshold `json:"threshold"`
}

Alert contains alert information.

type Backend

type Backend interface {
	GetRules(ctx context.Context) ([]Rule, error)
	PreflightAlerts(ctx context.Context, alerts []Alert) ([]Alert, error)
	SendAlerts(ctx context.Context, alerts []Alert) error
}

Backend is capable of serving rules and sending alerts.

type Client

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

Client for the alerting service.

func NewClient

func NewClient(client *http.Client, baseURL, token string) (*Client, error)

NewClient creates an alerting service client.

func (*Client) GetRules

func (c *Client) GetRules(ctx context.Context) ([]Rule, error)

GetRules gets the agent configuration.

func (*Client) PreflightAlerts

func (c *Client) PreflightAlerts(ctx context.Context, data []Alert) ([]Alert, error)

PreflightAlerts sends alert descriptors to the server and returns which alerts to send.

func (*Client) SendAlerts

func (c *Client) SendAlerts(ctx context.Context, data []Alert) error

SendAlerts sends alerts to the server.

type DataPointsFinder

type DataPointsFinder interface {
	FindByIngressAndService(table, ingress, service string, from, to time.Time) (metrics.DataPoints, error)
	FindByService(table, service string, from, to time.Time) metrics.DataPoints
	FindByIngress(table, ingress string, from, to time.Time) metrics.DataPoints
}

DataPointsFinder is capable of finding data points for given criteria.

type LogProvider

type LogProvider interface {
	GetServiceLogs(ctx context.Context, namespace, name string, lines, maxLen int) ([]byte, error)
}

LogProvider implements an object that can provide logs for a service.

type Manager

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

Manager manages rule synchronization and scheduling.

func NewManager

func NewManager(backend Backend, procs map[string]Processor, refreshInterval, schedulerInterval time.Duration) *Manager

NewManager returns an alert manager. The alertRefreshInterval is the interval to fetch configuration, including alert rules. The alertSchedulerInterval is the interval at which the scheduler runs rule checks.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

Run runs the alert manager.

type Point

type Point struct {
	Timestamp int64   `json:"ts"`
	Value     float64 `json:"value"`
}

Point contains a point and its timestamp.

type Processor

type Processor interface {
	Process(ctx context.Context, rule *Rule) (*Alert, error)
}

Processor represents a rule processor.

type Rule

type Rule struct {
	ID      string `json:"id"`
	Ingress string `json:"ingress"`
	Service string `json:"service"`

	Threshold *Threshold `json:"threshold"`
}

Rule defines evaluation configuration for alerting on metrics.

func (*Rule) Type

func (r *Rule) Type() string

Type returns the rule type (for now, only threshold).

type Threshold

type Threshold struct {
	Metric     string             `json:"metric"`
	Condition  ThresholdCondition `json:"condition"`
	Occurrence int                `json:"occurrence"`
	TimeRange  time.Duration      `json:"timeRange"`
}

Threshold contains a threshold and its direction.

func (Threshold) Granularity

func (t Threshold) Granularity() time.Duration

Granularity returns the metrics point granularity.

func (Threshold) Table

func (t Threshold) Table() string

Table returns the metrics table containing the data points.

type ThresholdCondition

type ThresholdCondition struct {
	Above bool    `json:"above"`
	Value float64 `json:"value"`
}

ThresholdCondition contains a threshold condition.

type ThresholdProcessor

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

ThresholdProcessor processes threshold rules.

func NewThresholdProcessor

func NewThresholdProcessor(dataPoints DataPointsFinder, logs LogProvider) *ThresholdProcessor

NewThresholdProcessor returns a threshold processor.

func (*ThresholdProcessor) Process

func (p *ThresholdProcessor) Process(ctx context.Context, rule *Rule) (*Alert, error)

Process processes a threshold rule returning an alert or nil.

Jump to

Keyboard shortcuts

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