Merge pull request #744 from prometheus/fabxc/fix-labels

Fix discarding of labels in file target groups
This commit is contained in:
Fabian Reinartz 2015-05-27 19:57:15 +02:00
commit a4f179230a
3 changed files with 9 additions and 5 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -1,5 +1,5 @@
- targets: ['localhost:9090', 'example.org:443']
labels:
test: success
foo: bar
- targets: ['my.domain']