mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Fix discarding of labels in file target groups
This commit is contained in:
parent
078efa6e6a
commit
e9b344abee
|
@ -247,9 +247,10 @@ func readFile(filename string) ([]*config.TargetGroup, error) {
|
||||||
|
|
||||||
for i, tg := range targetGroups {
|
for i, tg := range targetGroups {
|
||||||
tg.Source = fileSource(filename, i)
|
tg.Source = fileSource(filename, i)
|
||||||
tg.Labels = clientmodel.LabelSet{
|
if tg.Labels == nil {
|
||||||
FileSDFilepathLabel: clientmodel.LabelValue(filename),
|
tg.Labels = clientmodel.LabelSet{}
|
||||||
}
|
}
|
||||||
|
tg.Labels[FileSDFilepathLabel] = clientmodel.LabelValue(filename)
|
||||||
}
|
}
|
||||||
return targetGroups, nil
|
return targetGroups, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFileSD(t *testing.T) {
|
func TestFileSD(t *testing.T) {
|
||||||
|
defer os.Remove("fixtures/_test.yml")
|
||||||
|
defer os.Remove("fixtures/_test.json")
|
||||||
testFileSD(t, ".yml")
|
testFileSD(t, ".yml")
|
||||||
testFileSD(t, ".json")
|
testFileSD(t, ".json")
|
||||||
os.Remove("fixtures/_test.yml")
|
|
||||||
os.Remove("fixtures/_test.json")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFileSD(t *testing.T, ext string) {
|
func testFileSD(t *testing.T, ext string) {
|
||||||
|
@ -60,6 +60,9 @@ func testFileSD(t *testing.T, ext string) {
|
||||||
case <-time.After(15 * time.Second):
|
case <-time.After(15 * time.Second):
|
||||||
t.Fatalf("Expected new target group but got none")
|
t.Fatalf("Expected new target group but got none")
|
||||||
case tg := <-ch:
|
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) {
|
if tg.String() != fmt.Sprintf("file:fixtures/_test%s:0", ext) {
|
||||||
t.Fatalf("Unexpected target group", tg)
|
t.Fatalf("Unexpected target group", tg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- targets: ['localhost:9090', 'example.org:443']
|
- targets: ['localhost:9090', 'example.org:443']
|
||||||
labels:
|
labels:
|
||||||
test: success
|
foo: bar
|
||||||
|
|
||||||
- targets: ['my.domain']
|
- targets: ['my.domain']
|
||||||
|
|
Loading…
Reference in a new issue