Alerting: Add a "Reason" to Alert Instances to show underlying cause of state. (#49259)

This change adds a field to state.State and models.AlertInstance
that indicate the "Reason" that an instance has its current state. This
helps us account for cases where the state is "Normal" but the
underlying evaluation returned "NoData" or "Error", for example.

Fixes #42606

Signed-off-by: Joe Blubaugh <joe.blubaugh@grafana.com>
This commit is contained in:
Joe Blubaugh
2022-05-23 16:49:49 +08:00
committed by GitHub
parent 26a206cce2
commit 1cc034d960
21 changed files with 253 additions and 96 deletions
+7 -16
View File
@@ -12,6 +12,7 @@ type AlertInstance struct {
Labels InstanceLabels
LabelsHash string
CurrentState InstanceStateType
CurrentReason string
CurrentStateSince time.Time
CurrentStateEnd time.Time
LastEvalTime time.Time
@@ -49,6 +50,7 @@ type SaveAlertInstanceCommand struct {
RuleUID string
Labels InstanceLabels
State InstanceStateType
StateReason string
LastEvalTime time.Time
CurrentStateSince time.Time
CurrentStateEnd time.Time
@@ -66,23 +68,12 @@ type GetAlertInstanceQuery struct {
// ListAlertInstancesQuery is the query list alert Instances.
type ListAlertInstancesQuery struct {
RuleOrgID int64 `json:"-"`
RuleUID string
State InstanceStateType
RuleOrgID int64 `json:"-"`
RuleUID string
State InstanceStateType
StateReason string
Result []*ListAlertInstancesQueryResult
}
// ListAlertInstancesQueryResult represents the result of listAlertInstancesQuery.
type ListAlertInstancesQueryResult struct {
RuleOrgID int64 `xorm:"rule_org_id" json:"ruleOrgId"`
RuleUID string `xorm:"rule_uid" json:"ruleUid"`
Labels InstanceLabels `json:"labels"`
LabelsHash string `json:"labeHash"`
CurrentState InstanceStateType `json:"currentState"`
CurrentStateSince time.Time `json:"currentStateSince"`
CurrentStateEnd time.Time `json:"currentStateEnd"`
LastEvalTime time.Time `json:"lastEvalTime"`
Result []*AlertInstance
}
// ValidateAlertInstance validates that the alert instance contains an alert rule id,