From 6b33c90efe67c59f5b9118fb5da2ee2f9e430dc3 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 9 Sep 2022 22:01:11 +0200 Subject: [PATCH] Add option to always restore the state of rules when loading --- rules/manager.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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