mirror of
https://github.com/prometheus/prometheus
synced 2024-12-27 00:53:12 +00:00
Clone lset before relabelling. (#2386)
We need to not change the lset passed into populateLabels, as that is kept around by the SDs. Fixes 2377
This commit is contained in:
parent
7db4447390
commit
34767c2221
@ -305,6 +305,7 @@ func (app *countingAppender) Append(s *model.Sample) error {
|
||||
// It returns a label set before relabeling was applied as the second return value.
|
||||
// Returns a nil label set if the target is dropped during relabeling.
|
||||
func populateLabels(lset model.LabelSet, cfg *config.ScrapeConfig) (res, orig model.LabelSet, err error) {
|
||||
lset = lset.Clone()
|
||||
if _, ok := lset[model.AddressLabel]; !ok {
|
||||
return nil, nil, fmt.Errorf("no address")
|
||||
}
|
||||
|
@ -140,10 +140,14 @@ func TestPopulateLabels(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for i, c := range cases {
|
||||
in := c.in.Clone()
|
||||
res, orig, err := populateLabels(c.in, c.cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("case %d: %s", i, err)
|
||||
}
|
||||
if !reflect.DeepEqual(c.in, in) {
|
||||
t.Errorf("case %d: input lset was changed was\n\t%+v\n now\n\t%+v", i, in, c.in)
|
||||
}
|
||||
if !reflect.DeepEqual(res, c.res) {
|
||||
t.Errorf("case %d: expected res\n\t%+v\n got\n\t%+v", i, c.res, res)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user