state

package
v0.0.1-test Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ResendDelay = 30 * time.Second

Functions

func NewEvaluationValues

func NewEvaluationValues(m map[string]eval.NumberValueCapture) map[string]*float64

NewEvaluationValues returns the labels and values for each RefID in the capture.

Types

type AlertInstanceManager

type AlertInstanceManager interface {
	GetAll(orgID int64) []*State
	GetStatesForRuleUID(orgID int64, alertRuleUID string) []*State
}

AlertInstanceManager defines the interface for querying the current alert instances.

type Evaluation

type Evaluation struct {
	EvaluationTime  time.Time
	EvaluationState eval.State
	// Values contains the RefID and value of reduce and math expressions.
	// Classic conditions can have different values for the same RefID as they can include multiple conditions.
	// For these, we use the index of the condition in addition RefID as the key e.g. "A0, A1, A2, etc.".
	Values map[string]*float64
	// Condition is the refID specified as the condition in the alerting rule at the time of the evaluation.
	Condition string
}

type FakeHistorian

type FakeHistorian struct{}

func (*FakeHistorian) RecordState

func (f *FakeHistorian) RecordState(ctx context.Context, rule *models.AlertRule, labels data.Labels, evaluatedAt time.Time, currentData, previousData InstanceStateAndReason)

type FakeInstanceStore

type FakeInstanceStore struct {
	RecordedOps []interface{}
	// contains filtered or unexported fields
}

func (*FakeInstanceStore) DeleteAlertInstances

func (f *FakeInstanceStore) DeleteAlertInstances(_ context.Context, _ ...models.AlertInstanceKey) error

func (*FakeInstanceStore) DeleteAlertInstancesByRule

func (f *FakeInstanceStore) DeleteAlertInstancesByRule(ctx context.Context, key models.AlertRuleKey) error

func (*FakeInstanceStore) FetchOrgIds

func (f *FakeInstanceStore) FetchOrgIds(_ context.Context) ([]int64, error)

func (*FakeInstanceStore) ListAlertInstances

func (*FakeInstanceStore) SaveAlertInstances

func (f *FakeInstanceStore) SaveAlertInstances(_ context.Context, q ...models.AlertInstance) error

type FakeRuleReader

type FakeRuleReader struct{}

func (*FakeRuleReader) ListAlertRules

func (f *FakeRuleReader) ListAlertRules(_ context.Context, q *models.ListAlertRulesQuery) error

type Historian

type Historian interface {
	RecordState(ctx context.Context, rule *models.AlertRule, labels data.Labels, evaluatedAt time.Time, currentData, previousData InstanceStateAndReason)
}

Historian maintains an audit log of alert state history.

type InstanceStateAndReason

type InstanceStateAndReason struct {
	State  eval.State
	Reason string
}

This struct provides grouping of state with reason, and string formatting.

func (InstanceStateAndReason) String

func (i InstanceStateAndReason) String() string

type InstanceStore

type InstanceStore interface {
	FetchOrgIds(ctx context.Context) ([]int64, error)
	ListAlertInstances(ctx context.Context, cmd *models.ListAlertInstancesQuery) error
	SaveAlertInstances(ctx context.Context, cmd ...models.AlertInstance) error
	DeleteAlertInstances(ctx context.Context, keys ...models.AlertInstanceKey) error
	DeleteAlertInstancesByRule(ctx context.Context, key models.AlertRuleKey) error
}

InstanceStore represents the ability to fetch and write alert instances.

type Manager

type Manager struct {
	ResendDelay time.Duration
	// contains filtered or unexported fields
}

func NewManager

func NewManager(logger log.Logger, metrics *metrics.State, externalURL *url.URL,
	ruleStore RuleReader, instanceStore InstanceStore, imageService image.ImageService, clock clock.Clock, historian Historian) *Manager

func (*Manager) Close

func (st *Manager) Close()

func (*Manager) Get

func (st *Manager) Get(orgID int64, alertRuleUID, stateId string) (*State, error)

func (*Manager) GetAll

func (st *Manager) GetAll(orgID int64) []*State

func (*Manager) GetStatesForRuleUID

func (st *Manager) GetStatesForRuleUID(orgID int64, alertRuleUID string) []*State

func (*Manager) ProcessEvalResults

func (st *Manager) ProcessEvalResults(ctx context.Context, evaluatedAt time.Time, alertRule *ngModels.AlertRule, results eval.Results, extraLabels data.Labels) []*State

ProcessEvalResults updates the current states that belong to a rule with the evaluation results. if extraLabels is not empty, those labels will be added to every state. The extraLabels take precedence over rule labels and result labels

func (*Manager) Put

func (st *Manager) Put(states []*State)

func (*Manager) ResetAllStates

func (st *Manager) ResetAllStates()

ResetAllStates is used to ensure a clean cache on startup.

func (*Manager) ResetStateByRuleUID

func (st *Manager) ResetStateByRuleUID(ctx context.Context, ruleKey ngModels.AlertRuleKey) []*State

ResetStateByRuleUID deletes all entries in the state manager that match the given rule UID.

func (*Manager) Warm

func (st *Manager) Warm(ctx context.Context)

type RuleReader

type RuleReader interface {
	ListAlertRules(ctx context.Context, query *models.ListAlertRulesQuery) error
}

RuleReader represents the ability to fetch alert rules.

type State

type State struct {
	AlertRuleUID string
	OrgID        int64
	CacheId      string

	StartsAt   time.Time
	EndsAt     time.Time
	LastSentAt time.Time

	State                eval.State
	StateReason          string
	LastEvaluationString string
	LastEvaluationTime   time.Time
	EvaluationDuration   time.Duration
	Results              []Evaluation
	Resolved             bool
	Annotations          map[string]string
	Labels               data.Labels
	Image                *models.Image
	Error                error
}

func (*State) Equals

func (a *State) Equals(b *State) bool

func (*State) GetLabels

func (a *State) GetLabels(opts ...models.LabelOption) map[string]string

func (*State) GetLastEvaluationValuesForCondition

func (a *State) GetLastEvaluationValuesForCondition() map[string]float64

func (*State) GetRuleKey

func (a *State) GetRuleKey() models.AlertRuleKey

func (*State) NeedsSending

func (a *State) NeedsSending(resendDelay time.Duration) bool

func (*State) TrimResults

func (a *State) TrimResults(alertRule *models.AlertRule)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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