From eb1a898bc999ffbefba43543b7d1a3a8f38fdf32 Mon Sep 17 00:00:00 2001 From: Ashwanth Goli Date: Thu, 17 Oct 2024 15:36:50 +0530 Subject: [PATCH 1/2] fix(label_format): renamed label should use ParsedLabel category Signed-off-by: Ashwanth Goli --- pkg/logql/log/fmt.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/logql/log/fmt.go b/pkg/logql/log/fmt.go index c69aa3d40bb01..74eb0262d39d2 100644 --- a/pkg/logql/log/fmt.go +++ b/pkg/logql/log/fmt.go @@ -391,9 +391,9 @@ func (lf *LabelsFormatter) Process(ts int64, l []byte, lbs *LabelsBuilder) ([]by defer smp.Put(m) for _, f := range lf.formats { if f.Rename { - v, category, ok := lbs.GetWithCategory(f.Value) + v, _, ok := lbs.GetWithCategory(f.Value) if ok { - lbs.Set(category, f.Name, v) + lbs.Set(ParsedLabel, f.Name, v) lbs.Del(f.Value) } continue From e908d1eb9680e11ad526de9283356970aa74159b Mon Sep 17 00:00:00 2001 From: Ashwanth Goli Date: Thu, 17 Oct 2024 15:58:09 +0530 Subject: [PATCH 2/2] add rename test --- pkg/logql/log/fmt_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/logql/log/fmt_test.go b/pkg/logql/log/fmt_test.go index 2028d2e00bf8f..9cb449a7bfddf 100644 --- a/pkg/logql/log/fmt_test.go +++ b/pkg/logql/log/fmt_test.go @@ -515,6 +515,22 @@ func Test_labelsFormatter_Format(t *testing.T) { in labels.Labels want labels.Labels }{ + { + "rename label", + mustNewLabelsFormatter([]LabelFmt{ + NewRenameLabelFmt("baz", "foo"), + }), + labels.FromStrings("foo", "blip", "bar", "blop"), + labels.FromStrings("bar", "blop", "baz", "blip"), + }, + { + "rename and overwrite existing label", + mustNewLabelsFormatter([]LabelFmt{ + NewRenameLabelFmt("bar", "foo"), + }), + labels.FromStrings("foo", "blip", "bar", "blop"), + labels.FromStrings("bar", "blip"), + }, { "combined with template", mustNewLabelsFormatter([]LabelFmt{NewTemplateLabelFmt("foo", "{{.foo}} and {{.bar}}")}),