From e9b344abeed649b1b5eb985a223bb90ba41038a2 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 27 May 2015 18:32:21 +0200 Subject: [PATCH] Fix discarding of labels in file target groups --- retrieval/discovery/file.go | 5 +++-- retrieval/discovery/file_test.go | 7 +++++-- retrieval/discovery/fixtures/target_groups.yml | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/retrieval/discovery/file.go b/retrieval/discovery/file.go index c0251a510..25201dd77 100644 --- a/retrieval/discovery/file.go +++ b/retrieval/discovery/file.go @@ -247,9 +247,10 @@ func readFile(filename string) ([]*config.TargetGroup, error) { for i, tg := range targetGroups { tg.Source = fileSource(filename, i) - tg.Labels = clientmodel.LabelSet{ - FileSDFilepathLabel: clientmodel.LabelValue(filename), + if tg.Labels == nil { + tg.Labels = clientmodel.LabelSet{} } + tg.Labels[FileSDFilepathLabel] = clientmodel.LabelValue(filename) } return targetGroups, nil } diff --git a/retrieval/discovery/file_test.go b/retrieval/discovery/file_test.go index 8ae0ef8ab..89de0cb0a 100644 --- a/retrieval/discovery/file_test.go +++ b/retrieval/discovery/file_test.go @@ -11,10 +11,10 @@ import ( ) func TestFileSD(t *testing.T) { + defer os.Remove("fixtures/_test.yml") + defer os.Remove("fixtures/_test.json") testFileSD(t, ".yml") testFileSD(t, ".json") - os.Remove("fixtures/_test.yml") - os.Remove("fixtures/_test.json") } func testFileSD(t *testing.T, ext string) { @@ -60,6 +60,9 @@ func testFileSD(t *testing.T, ext string) { case <-time.After(15 * time.Second): t.Fatalf("Expected new target group but got none") case tg := <-ch: + if _, ok := tg.Labels["foo"]; !ok { + t.Fatalf("Label not parsed") + } if tg.String() != fmt.Sprintf("file:fixtures/_test%s:0", ext) { t.Fatalf("Unexpected target group", tg) } diff --git a/retrieval/discovery/fixtures/target_groups.yml b/retrieval/discovery/fixtures/target_groups.yml index a4823b2b9..5a4e6e5db 100644 --- a/retrieval/discovery/fixtures/target_groups.yml +++ b/retrieval/discovery/fixtures/target_groups.yml @@ -1,5 +1,5 @@ - targets: ['localhost:9090', 'example.org:443'] labels: - test: success + foo: bar - targets: ['my.domain']