From 9bd4f6d0177e2c3ed7da3ae05140678bc93a3bef Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 23 Jun 2015 12:07:53 +0200 Subject: [PATCH] rules: preserve alert state across reloads. --- rules/manager.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/rules/manager.go b/rules/manager.go index 9462fb21f..59f9573b9 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -294,6 +294,13 @@ func (m *Manager) ApplyConfig(conf *config.Config) bool { success := true m.interval = time.Duration(conf.GlobalConfig.EvaluationInterval) + alertingRules := map[string]*AlertingRule{} + for _, r := range m.rules { + if ar, ok := r.(*AlertingRule); ok { + alertingRules[ar.name] = ar + } + } + rulesSnapshot := make([]Rule, len(m.rules)) copy(rulesSnapshot, m.rules) m.rules = m.rules[:0] @@ -314,6 +321,17 @@ func (m *Manager) ApplyConfig(conf *config.Config) bool { log.Errorf("Error loading rules, previous rule set restored: %s", err) success = false } + // Restore alerting rule state. + for _, r := range m.rules { + ar, ok := r.(*AlertingRule) + if !ok { + continue + } + if old, ok := alertingRules[ar.name]; ok { + ar.activeAlerts = old.activeAlerts + } + } + return success }