From 7505e4f390b303fe8267c27d8aee771ac8e1d06a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 5 Oct 2020 16:19:14 +0300 Subject: [PATCH] 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 --- lib/promrelabel/relabel.go | 3 ++- lib/promrelabel/relabel_test.go | 4 ++++ lib/promscrape/config_test.go | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/promrelabel/relabel.go b/lib/promrelabel/relabel.go index 8432f8cff..887466754 100644 --- a/lib/promrelabel/relabel.go +++ b/lib/promrelabel/relabel.go @@ -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": diff --git a/lib/promrelabel/relabel_test.go b/lib/promrelabel/relabel_test.go index f26a51372..a57e8bee6 100644 --- a/lib/promrelabel/relabel_test.go +++ b/lib/promrelabel/relabel_test.go @@ -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) { diff --git a/lib/promscrape/config_test.go b/lib/promscrape/config_test.go index 265577897..fa329d5bb 100644 --- a/lib/promscrape/config_test.go +++ b/lib/promscrape/config_test.go @@ -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",