From ccb4533a863dbeb3b804ad6d52f5894c11a2c27f Mon Sep 17 00:00:00 2001 From: Alexander Weaver Date: Tue, 13 Feb 2024 10:56:24 -0600 Subject: [PATCH] Alerting: Remove unused AlertRuleVersionWithPauseStatus (#82383) Remove unused AlertRuleVersionWithPauseStatus --- pkg/services/ngalert/api/persist.go | 2 +- pkg/services/ngalert/models/alert_rule.go | 5 ----- pkg/services/ngalert/store/alert_rule.go | 4 ++-- pkg/services/ngalert/tests/fakes/rules.go | 13 +++++-------- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/pkg/services/ngalert/api/persist.go b/pkg/services/ngalert/api/persist.go index c8f759920d9..59d4930d7d0 100644 --- a/pkg/services/ngalert/api/persist.go +++ b/pkg/services/ngalert/api/persist.go @@ -24,5 +24,5 @@ type RuleStore interface { DeleteAlertRulesByUID(ctx context.Context, orgID int64, ruleUID ...string) error // IncreaseVersionForAllRulesInNamespace Increases version for all rules that have specified namespace. Returns all rules that belong to the namespace - IncreaseVersionForAllRulesInNamespace(ctx context.Context, orgID int64, namespaceUID string) ([]ngmodels.AlertRuleKeyWithVersionAndPauseStatus, error) + IncreaseVersionForAllRulesInNamespace(ctx context.Context, orgID int64, namespaceUID string) ([]ngmodels.AlertRuleKeyWithVersion, error) } diff --git a/pkg/services/ngalert/models/alert_rule.go b/pkg/services/ngalert/models/alert_rule.go index 881fc311d87..f93eb3a5484 100644 --- a/pkg/services/ngalert/models/alert_rule.go +++ b/pkg/services/ngalert/models/alert_rule.go @@ -368,11 +368,6 @@ type AlertRuleKeyWithVersion struct { AlertRuleKey `xorm:"extends"` } -type AlertRuleKeyWithVersionAndPauseStatus struct { - IsPaused bool - AlertRuleKeyWithVersion `xorm:"extends"` -} - type AlertRuleKeyWithId struct { AlertRuleKey ID int64 diff --git a/pkg/services/ngalert/store/alert_rule.go b/pkg/services/ngalert/store/alert_rule.go index 585ddf14261..71c97b6db78 100644 --- a/pkg/services/ngalert/store/alert_rule.go +++ b/pkg/services/ngalert/store/alert_rule.go @@ -72,8 +72,8 @@ func (st DBstore) DeleteAlertRulesByUID(ctx context.Context, orgID int64, ruleUI } // IncreaseVersionForAllRulesInNamespace Increases version for all rules that have specified namespace. Returns all rules that belong to the namespace -func (st DBstore) IncreaseVersionForAllRulesInNamespace(ctx context.Context, orgID int64, namespaceUID string) ([]ngmodels.AlertRuleKeyWithVersionAndPauseStatus, error) { - var keys []ngmodels.AlertRuleKeyWithVersionAndPauseStatus +func (st DBstore) IncreaseVersionForAllRulesInNamespace(ctx context.Context, orgID int64, namespaceUID string) ([]ngmodels.AlertRuleKeyWithVersion, error) { + var keys []ngmodels.AlertRuleKeyWithVersion err := st.SQLStore.WithTransactionalDbSession(ctx, func(sess *db.Session) error { now := TimeNow() _, err := sess.Exec("UPDATE alert_rule SET version = version + 1, updated = ? WHERE namespace_uid = ? AND org_id = ?", now, namespaceUID, orgID) diff --git a/pkg/services/ngalert/tests/fakes/rules.go b/pkg/services/ngalert/tests/fakes/rules.go index 6c8c28161d0..9185047c989 100644 --- a/pkg/services/ngalert/tests/fakes/rules.go +++ b/pkg/services/ngalert/tests/fakes/rules.go @@ -315,7 +315,7 @@ func (f *RuleStore) UpdateRuleGroup(ctx context.Context, orgID int64, namespaceU return nil } -func (f *RuleStore) IncreaseVersionForAllRulesInNamespace(_ context.Context, orgID int64, namespaceUID string) ([]models.AlertRuleKeyWithVersionAndPauseStatus, error) { +func (f *RuleStore) IncreaseVersionForAllRulesInNamespace(_ context.Context, orgID int64, namespaceUID string) ([]models.AlertRuleKeyWithVersion, error) { f.mtx.Lock() defer f.mtx.Unlock() @@ -324,18 +324,15 @@ func (f *RuleStore) IncreaseVersionForAllRulesInNamespace(_ context.Context, org Params: []any{orgID, namespaceUID}, }) - var result []models.AlertRuleKeyWithVersionAndPauseStatus + var result []models.AlertRuleKeyWithVersion for _, rule := range f.Rules[orgID] { if rule.NamespaceUID == namespaceUID && rule.OrgID == orgID { rule.Version++ rule.Updated = time.Now() - result = append(result, models.AlertRuleKeyWithVersionAndPauseStatus{ - IsPaused: rule.IsPaused, - AlertRuleKeyWithVersion: models.AlertRuleKeyWithVersion{ - Version: rule.Version, - AlertRuleKey: rule.GetKey(), - }, + result = append(result, models.AlertRuleKeyWithVersion{ + Version: rule.Version, + AlertRuleKey: rule.GetKey(), }) } }