Documentation ¶
Overview ¶
Package state is a generated GoMock package.
Index ¶
- Variables
- func FormatStateAndReason(state eval.State, reason string) string
- func IsNormalStateWithNoReason(s *State) bool
- func NewEvaluationValues(m map[string]eval.NumberValueCapture) map[string]*float64
- type AlertInstanceManager
- type Evaluation
- type FakeHistorian
- type FakeInstanceStore
- func (f *FakeInstanceStore) DeleteAlertInstances(ctx context.Context, q ...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) ([]*models.AlertInstance, error)
- func (f *FakeInstanceStore) SaveAlertInstances(_ context.Context, q ...models.AlertInstance) error
- type FakeInstanceStoreOp
- type FakeRuleReader
- type Historian
- type ImageCapturer
- type InstanceStore
- type Manager
- func (st *Manager) DeleteStateByRuleUID(ctx context.Context, ruleKey ngModels.AlertRuleKey, reason string) []StateTransition
- func (st *Manager) Get(orgID int64, alertRuleUID, stateId string) *State
- 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, ...) []StateTransition
- func (st *Manager) Put(states []*State)
- func (st *Manager) ResetStateByRuleUID(ctx context.Context, rule *ngModels.AlertRule, reason string) []StateTransition
- func (st *Manager) Run(ctx context.Context) error
- func (st *Manager) Warm(ctx context.Context, rulesReader RuleReader)
- type ManagerCfg
- type MockImageCapturer
- type MockImageCapturerMockRecorder
- type NoopImageService
- type NotAvailableImageService
- type RuleReader
- type State
- func (a *State) Equals(b *State) bool
- func (a *State) GetAlertInstanceKey() (models.AlertInstanceKey, error)
- 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) Maintain(interval int64, evaluatedAt time.Time)
- func (a *State) NeedsSending(resendDelay time.Duration) bool
- func (a *State) Resolve(reason string, endsAt time.Time)
- func (a *State) SetAlerting(reason string, startsAt, endsAt time.Time)
- func (a *State) SetError(err error, startsAt, endsAt time.Time)
- func (a *State) SetNoData(reason string, startsAt, endsAt time.Time)
- func (a *State) SetNormal(reason string, startsAt, endsAt time.Time)
- func (a *State) SetPending(reason string, startsAt, endsAt time.Time)
- func (a *State) TrimResults(alertRule *models.AlertRule)
- type StateTransition
Constants ¶
This section is empty.
Variables ¶
var ( ResendDelay = 30 * time.Second MetricsScrapeInterval = 15 * time.Second // TODO: parameterize? // Setting to a reasonable default scrape interval for Prometheus. )
Functions ¶
func IsNormalStateWithNoReason ¶
IsNormalStateWithNoReason returns true if the state is Normal and reason is empty
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 {
StateTransitions []StateTransition
}
func (*FakeHistorian) Record ¶
func (f *FakeHistorian) Record(ctx context.Context, rule history_model.RuleMeta, states []StateTransition) <-chan error
type FakeInstanceStore ¶
type FakeInstanceStore struct { RecordedOps []interface{} // contains filtered or unexported fields }
func (*FakeInstanceStore) DeleteAlertInstances ¶
func (f *FakeInstanceStore) DeleteAlertInstances(ctx context.Context, q ...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) ([]*models.AlertInstance, error)
func (*FakeInstanceStore) SaveAlertInstances ¶
func (f *FakeInstanceStore) SaveAlertInstances(_ context.Context, q ...models.AlertInstance) error
type FakeInstanceStoreOp ¶
type FakeInstanceStoreOp struct { Name string Args []interface{} }
type FakeRuleReader ¶
type FakeRuleReader struct{}
func (*FakeRuleReader) ListAlertRules ¶
func (f *FakeRuleReader) ListAlertRules(_ context.Context, q *models.ListAlertRulesQuery) (models.RulesGroup, error)
type Historian ¶
type Historian interface { // RecordStates writes a number of state transitions for a given rule to state history. It returns a channel that // is closed when writing the state transitions has completed. If an error has occurred, the channel will contain a // non-nil error. Record(ctx context.Context, rule history_model.RuleMeta, states []StateTransition) <-chan error }
Historian maintains an audit log of alert state history.
type ImageCapturer ¶
type ImageCapturer interface {
NewImage(ctx context.Context, r *models.AlertRule) (*models.Image, error)
}
ImageCapturer captures images.
type InstanceStore ¶
type InstanceStore interface { FetchOrgIds(ctx context.Context) ([]int64, error) ListAlertInstances(ctx context.Context, cmd *models.ListAlertInstancesQuery) ([]*models.AlertInstance, 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(cfg ManagerCfg) *Manager
func (*Manager) DeleteStateByRuleUID ¶
func (st *Manager) DeleteStateByRuleUID(ctx context.Context, ruleKey ngModels.AlertRuleKey, reason string) []StateTransition
DeleteStateByRuleUID removes the rule instances from cache and instanceStore. A closed channel is returned to be able to gracefully handle the clear state step in scheduler in case we do not need to use the historian to save state history.
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) []StateTransition
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) ResetStateByRuleUID ¶
func (st *Manager) ResetStateByRuleUID(ctx context.Context, rule *ngModels.AlertRule, reason string) []StateTransition
ResetStateByRuleUID removes the rule instances from cache and instanceStore and saves state history. If the state history has to be saved, rule must not be nil.
type ManagerCfg ¶
type ManagerCfg struct { Metrics *metrics.State ExternalURL *url.URL InstanceStore InstanceStore Images ImageCapturer Clock clock.Clock Historian Historian // DoNotSaveNormalState controls whether eval.Normal state is persisted to the database and returned by get methods DoNotSaveNormalState bool }
type MockImageCapturer ¶
type MockImageCapturer struct {
// contains filtered or unexported fields
}
MockImageCapturer is a mock of ImageCapturer interface.
func NewMockImageCapturer ¶
func NewMockImageCapturer(ctrl *gomock.Controller) *MockImageCapturer
NewMockImageCapturer creates a new mock instance.
func (*MockImageCapturer) EXPECT ¶
func (m *MockImageCapturer) EXPECT() *MockImageCapturerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockImageCapturerMockRecorder ¶
type MockImageCapturerMockRecorder struct {
// contains filtered or unexported fields
}
MockImageCapturerMockRecorder is the mock recorder for MockImageCapturer.
func (*MockImageCapturerMockRecorder) NewImage ¶
func (mr *MockImageCapturerMockRecorder) NewImage(arg0, arg1 interface{}) *gomock.Call
NewImage indicates an expected call of NewImage.
type NotAvailableImageService ¶
type NotAvailableImageService struct{}
NotAvailableImageService is a service that returns ErrScreenshotsUnavailable.
type RuleReader ¶
type RuleReader interface {
ListAlertRules(ctx context.Context, query *models.ListAlertRulesQuery) (models.RulesGroup, error)
}
RuleReader represents the ability to fetch alert rules.
type State ¶
type State struct { OrgID int64 AlertRuleUID string // CacheID is a unique, opaque identifier for the state, and is used to find the state // in the state cache. It tends to be derived from the state's labels. CacheID string // State represents the current state. State eval.State // StateReason is a textual description to explain why the state has its current state. StateReason string // Results contains the result of the current and previous evaluations. Results []Evaluation // Error is set if the current evaluation returned an error. If error is non-nil results // can still contain the results of previous evaluations. Error error // Resolved is set to true if this state is the transitional state between Firing and Normal. // All subsequent states will be false until the next transition from Firing to Normal. Resolved bool // Image contains an optional image for the state. It tends to be included in notifications // as a visualization to show why the alert fired. Image *models.Image // Annotations contains the annotations from the alert rule. If an annotation is templated // then the template is first evaluated to derive the final annotation. Annotations map[string]string // Labels contain the labels from the query and any custom labels from the alert rule. // If a label is templated then the template is first evaluated to derive the final label. Labels data.Labels // Values contains the values of any instant vectors, reduce and math expressions, or classic // conditions. Values map[string]float64 StartsAt time.Time EndsAt time.Time LastSentAt time.Time LastEvaluationString string LastEvaluationTime time.Time EvaluationDuration time.Duration }
func (*State) GetAlertInstanceKey ¶
func (a *State) GetAlertInstanceKey() (models.AlertInstanceKey, error)
func (*State) GetLastEvaluationValuesForCondition ¶
func (*State) GetRuleKey ¶
func (a *State) GetRuleKey() models.AlertRuleKey
func (*State) Resolve ¶
Resolve sets the State to Normal. It updates the StateReason, the end time, and sets Resolved to true.
func (*State) SetAlerting ¶
SetAlerting sets the state to Alerting. It changes both the start and end time.
func (*State) SetNoData ¶
SetNoData sets the state to NoData. It changes both the start and end time.
func (*State) SetNormal ¶
SetNormal sets the state to Normal. It changes both the start and end time.
func (*State) SetPending ¶
SetPending the state to Pending. It changes both the start and end time.
func (*State) TrimResults ¶
type StateTransition ¶
StateTransition describes the transition from one state to another.
func (StateTransition) Changed ¶
func (c StateTransition) Changed() bool
func (StateTransition) Formatted ¶
func (c StateTransition) Formatted() string
func (StateTransition) PreviousFormatted ¶
func (c StateTransition) PreviousFormatted() string