Skip to content

Commit

Permalink
Clone lset before relabelling. (prometheus#2386)
Browse files Browse the repository at this point in the history
We need to not change the lset passed into populateLabels, as that
is kept around by the SDs.

Fixes 2377
  • Loading branch information
brian-brazil authored Feb 1, 2017
1 parent 7db4447 commit 34767c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions retrieval/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 4 additions & 0 deletions retrieval/targetmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 34767c2

Please sign in to comment.