Add option to always restore the state of rules when loading

This commit is contained in:
Dimitar Dimitrov 2022-09-09 22:01:11 +02:00
parent 4aa6d561a1
commit 6b33c90efe
No known key found for this signature in database
GPG key ID: 4541B04E6C90EBC3

View file

@ -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