From d89c2548499d50aaf78f4e28096a8645062d954b Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 2 Mar 2016 11:54:37 +0100 Subject: [PATCH] Make copying alerting state safer. This considers static labels in the equality of alerts to avoid falsely copying state from a different alert definition with the same name across reloads. To be safe, it also copies the state map rather than just its pointer so that remaining collisions disappear after one evaluation interval. --- rules/alerting.go | 4 ++++ rules/manager.go | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rules/alerting.go b/rules/alerting.go index fdd3d00a8..b102ee4ca 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -110,6 +110,10 @@ func (rule *AlertingRule) Name() string { return rule.name } +func (r *AlertingRule) equal(o *AlertingRule) bool { + return r.name == o.name && r.labels.Equal(o.labels) +} + func (r *AlertingRule) sample(alert *Alert, ts model.Time, set bool) *model.Sample { metric := model.Metric(r.labels.Clone()) diff --git a/rules/manager.go b/rules/manager.go index 0e2542f6a..d1736dd6f 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -212,8 +212,12 @@ func (g *Group) copyState(from *Group) { if !ok { continue } - if far.Name() == ar.Name() { - ar.active = far.active + // TODO(fabxc): forbid same alert definitions that are not unique by + // at least on static label or alertname? + if far.equal(ar) { + for fp, a := range far.active { + ar.active[fp] = a + } } } }