mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
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.
This commit is contained in:
parent
95c9706d2d
commit
d89c254849
|
@ -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())
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue