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

View File

@@ -47,10 +47,11 @@ func TestAlertInstanceOperations(t *testing.T) {
t.Run("can save and read new alert instance", func(t *testing.T) {
saveCmd := &models.SaveAlertInstanceCommand{
RuleOrgID: alertRule1.OrgID,
RuleUID: alertRule1.UID,
State: models.InstanceStateFiring,
Labels: models.InstanceLabels{"test": "testValue"},
RuleOrgID: alertRule1.OrgID,
RuleUID: alertRule1.UID,
State: models.InstanceStateFiring,
StateReason: string(models.InstanceStateError),
Labels: models.InstanceLabels{"test": "testValue"},
}
err := dbstore.SaveAlertInstance(ctx, saveCmd)
require.NoError(t, err)
@@ -67,6 +68,7 @@ func TestAlertInstanceOperations(t *testing.T) {
require.Equal(t, saveCmd.Labels, getCmd.Result.Labels)
require.Equal(t, alertRule1.OrgID, getCmd.Result.RuleOrgID)
require.Equal(t, alertRule1.UID, getCmd.Result.RuleUID)
require.Equal(t, saveCmd.StateReason, getCmd.Result.CurrentReason)
})
t.Run("can save and read new alert instance with no labels", func(t *testing.T) {