mirror of
https://github.com/prometheus/prometheus
synced 2024-12-25 07:52:28 +00:00
notifier: clone and not reuse LabelSet in AM discovery
This commit is contained in:
parent
b38e977fd8
commit
94e8b43aae
@ -500,6 +500,7 @@ func alertmanagerFromGroup(tg *config.TargetGroup, cfg *config.AlertmanagerConfi
|
||||
var res []alertmanager
|
||||
|
||||
for _, lset := range tg.Targets {
|
||||
lset = lset.Clone()
|
||||
// Set configured scheme as the initial scheme label for overwrite.
|
||||
lset[model.SchemeLabel] = model.LabelValue(cfg.Scheme)
|
||||
lset[pathLabel] = model.LabelValue(postPath(cfg.PathPrefix))
|
||||
@ -510,7 +511,8 @@ func alertmanagerFromGroup(tg *config.TargetGroup, cfg *config.AlertmanagerConfi
|
||||
lset[ln] = lv
|
||||
}
|
||||
}
|
||||
lset := relabel.Process(lset, cfg.RelabelConfigs...)
|
||||
|
||||
lset = relabel.Process(lset, cfg.RelabelConfigs...)
|
||||
if lset == nil {
|
||||
continue
|
||||
}
|
||||
|
@ -418,3 +418,30 @@ type alertmanagerMock struct {
|
||||
func (a alertmanagerMock) url() string {
|
||||
return a.urlf()
|
||||
}
|
||||
|
||||
func TestLabelSetNotReused(t *testing.T) {
|
||||
tg := makeInputTargetGroup()
|
||||
_, err := alertmanagerFromGroup(tg, &config.AlertmanagerConfig{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(tg, makeInputTargetGroup()) {
|
||||
t.Fatal("Target modified during alertmanager extraction")
|
||||
}
|
||||
}
|
||||
|
||||
func makeInputTargetGroup() *config.TargetGroup {
|
||||
return &config.TargetGroup{
|
||||
Targets: []model.LabelSet{
|
||||
model.LabelSet{
|
||||
model.AddressLabel: model.LabelValue("1.1.1.1:9090"),
|
||||
model.LabelName("notcommon1"): model.LabelValue("label"),
|
||||
},
|
||||
},
|
||||
Labels: model.LabelSet{
|
||||
model.LabelName("common"): model.LabelValue("label"),
|
||||
},
|
||||
Source: "testsource",
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user