Alerting: Do not persist noop transition from Normal state. (#61201)

* add feature flag `alertingNoNormalState`
* update instance database to support exclusion of state in list operation
* do not save normal state and delete transitions to normal
* update get methods to filter out normal state
This commit is contained in:
Yuri Tseretyan
2023-01-13 18:29:29 -05:00
committed by GitHub
parent 12d27edb52
commit 9d57b1c72e
14 changed files with 209 additions and 57 deletions
@@ -30,15 +30,9 @@ func (st DBstore) ListAlertInstances(ctx context.Context, cmd *models.ListAlertI
if cmd.RuleUID != "" {
addToQuery(` AND rule_uid = ?`, cmd.RuleUID)
}
if cmd.State != "" {
addToQuery(` AND current_state = ?`, cmd.State)
if st.FeatureToggles.IsEnabled(featuremgmt.FlagAlertingNoNormalState) {
s.WriteString(fmt.Sprintf(" AND NOT (current_state = '%s' AND current_reason = '')", models.InstanceStateNormal))
}
if cmd.StateReason != "" {
addToQuery(` AND current_reason = ?`, cmd.StateReason)
}
if err := sess.SQL(s.String(), params...).Find(&alertInstances); err != nil {
return err
}