mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-21 18:50:52 -08:00
Add option to always restore the state of rules when loading
This commit is contained in:
parent
4aa6d561a1
commit
6b33c90efe
|
@ -962,6 +962,10 @@ type ManagerOptions struct {
|
||||||
GroupLoader GroupLoader
|
GroupLoader GroupLoader
|
||||||
DefaultEvaluationDelay func() time.Duration
|
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
|
Metrics *Metrics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,7 +1120,7 @@ func (m *Manager) LoadGroups(
|
||||||
) (map[string]*Group, []error) {
|
) (map[string]*Group, []error) {
|
||||||
groups := make(map[string]*Group)
|
groups := make(map[string]*Group)
|
||||||
|
|
||||||
shouldRestore := !m.restored
|
shouldRestore := !m.restored || m.opts.AlwaysRestoreAlertState
|
||||||
|
|
||||||
for _, fn := range filenames {
|
for _, fn := range filenames {
|
||||||
rgs, errs := m.opts.GroupLoader.Load(fn)
|
rgs, errs := m.opts.GroupLoader.Load(fn)
|
||||||
|
@ -1146,7 +1150,7 @@ func (m *Manager) LoadGroups(
|
||||||
labels.FromMap(r.Annotations),
|
labels.FromMap(r.Annotations),
|
||||||
externalLabels,
|
externalLabels,
|
||||||
externalURL,
|
externalURL,
|
||||||
m.restored,
|
!shouldRestore,
|
||||||
log.With(m.logger, "alert", r.Alert),
|
log.With(m.logger, "alert", r.Alert),
|
||||||
))
|
))
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue