lib/promrelabel: make a copy of label with new name for action: labelmap in the same way as Prometheus does

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/812
This commit is contained in:
Aliaksandr Valialkin 2020-10-05 16:19:14 +03:00
parent 9a7c863bd8
commit 7505e4f390
3 changed files with 10 additions and 1 deletions

View file

@ -206,8 +206,9 @@ func applyRelabelConfig(labels []prompbmarshal.Label, labelsOffset int, prc *Par
}
value := relabelBufPool.Get()
value.B = prc.Regex.ExpandString(value.B[:0], prc.Replacement, label.Name, match)
label.Name = string(value.B)
labelName := string(value.B)
relabelBufPool.Put(value)
labels = setLabelValue(labels, labelsOffset, labelName, label.Value)
}
return labels
case "labelmap_all":

View file

@ -575,6 +575,10 @@ func TestApplyRelabelConfigs(t *testing.T) {
Name: "foo",
Value: "yyy",
},
{
Name: "foobar",
Value: "aaa",
},
})
})
t.Run("labelmap_all", func(t *testing.T) {

View file

@ -920,6 +920,10 @@ scrape_configs:
Name: "prefix:url",
Value: "http://foo.bar:1234/metrics",
},
{
Name: "url",
Value: "http://foo.bar:1234/metrics",
},
},
AuthConfig: &promauth.Config{},
jobNameOriginal: "foo",