diff --git a/rules/manager.go b/rules/manager.go index 2fe65eb21c..ffcce9c9ff 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -962,6 +962,10 @@ type ManagerOptions struct { GroupLoader GroupLoader DefaultEvaluationDelay func() time.Duration + // AlwaysRestoreAlertState forces all new groups added via LoadGroups to restore their state. + // Useful when you know you will be adding alerting rules after the manager has already started. + AlwaysRestoreAlertState bool + Metrics *Metrics } @@ -1116,7 +1120,7 @@ func (m *Manager) LoadGroups( ) (map[string]*Group, []error) { groups := make(map[string]*Group) - shouldRestore := !m.restored + shouldRestore := !m.restored || m.opts.AlwaysRestoreAlertState for _, fn := range filenames { rgs, errs := m.opts.GroupLoader.Load(fn) @@ -1146,7 +1150,7 @@ func (m *Manager) LoadGroups( labels.FromMap(r.Annotations), externalLabels, externalURL, - m.restored, + !shouldRestore, log.With(m.logger, "alert", r.Alert), )) continue