Documentation ¶
Index ¶
- Variables
- func NewEvaluationValues(m map[string]eval.NumberValueCapture) map[string]*float64
- type AlertInstanceManager
- type Evaluation
- type FakeHistorian
- type FakeInstanceStore
- func (f *FakeInstanceStore) DeleteAlertInstances(_ context.Context, _ ...models.AlertInstanceKey) error
- func (f *FakeInstanceStore) DeleteAlertInstancesByRule(ctx context.Context, key models.AlertRuleKey) error
- func (f *FakeInstanceStore) FetchOrgIds(_ context.Context) ([]int64, error)
- func (f *FakeInstanceStore) ListAlertInstances(_ context.Context, q *models.ListAlertInstancesQuery) error
- func (f *FakeInstanceStore) SaveAlertInstances(_ context.Context, q ...models.AlertInstance) error
- type FakeRuleReader
- type Historian
- type InstanceStateAndReason
- type InstanceStore
- type Manager
- func (st *Manager) Close()
- func (st *Manager) Get(orgID int64, alertRuleUID, stateId string) (*State, error)
- func (st *Manager) GetAll(orgID int64) []*State
- func (st *Manager) GetStatesForRuleUID(orgID int64, alertRuleUID string) []*State
- func (st *Manager) ProcessEvalResults(ctx context.Context, evaluatedAt time.Time, alertRule *ngModels.AlertRule, ...) []*State
- func (st *Manager) Put(states []*State)
- func (st *Manager) ResetAllStates()
- func (st *Manager) ResetStateByRuleUID(ctx context.Context, ruleKey ngModels.AlertRuleKey) []*State
- func (st *Manager) Warm(ctx context.Context)
- type RuleReader
- type State
- func (a *State) Equals(b *State) bool
- func (a *State) GetLabels(opts ...models.LabelOption) map[string]string
- func (a *State) GetLastEvaluationValuesForCondition() map[string]float64
- func (a *State) GetRuleKey() models.AlertRuleKey
- func (a *State) NeedsSending(resendDelay time.Duration) bool
- func (a *State) TrimResults(alertRule *models.AlertRule)
Constants ¶
This section is empty.
Variables ¶
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 (f *FakeInstanceStore) ListAlertInstances(_ context.Context, q *models.ListAlertInstancesQuery) error
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 ¶
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 ¶
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) GetStatesForRuleUID ¶
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) ResetAllStates ¶
func (st *Manager) ResetAllStates()
ResetAllStates is used to ensure a clean cache on startup.
func (*Manager) ResetStateByRuleUID ¶
ResetStateByRuleUID deletes all entries in the state manager that match the given rule UID.
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) GetLastEvaluationValuesForCondition ¶
func (*State) GetRuleKey ¶
func (a *State) GetRuleKey() models.AlertRuleKey