Skip to content

Commit d3e3e3f

Browse files
fix(label_format): renamed label should use ParsedLabel category (#14515)
Signed-off-by: Ashwanth Goli <[email protected]> (cherry picked from commit 82fb2f0)
1 parent bebe9fa commit d3e3e3f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pkg/logql/log/fmt.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ func (lf *LabelsFormatter) Process(ts int64, l []byte, lbs *LabelsBuilder) ([]by
391391
defer smp.Put(m)
392392
for _, f := range lf.formats {
393393
if f.Rename {
394-
v, category, ok := lbs.GetWithCategory(f.Value)
394+
v, _, ok := lbs.GetWithCategory(f.Value)
395395
if ok {
396-
lbs.Set(category, f.Name, v)
396+
lbs.Set(ParsedLabel, f.Name, v)
397397
lbs.Del(f.Value)
398398
}
399399
continue

pkg/logql/log/fmt_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,22 @@ func Test_labelsFormatter_Format(t *testing.T) {
515515
in labels.Labels
516516
want labels.Labels
517517
}{
518+
{
519+
"rename label",
520+
mustNewLabelsFormatter([]LabelFmt{
521+
NewRenameLabelFmt("baz", "foo"),
522+
}),
523+
labels.FromStrings("foo", "blip", "bar", "blop"),
524+
labels.FromStrings("bar", "blop", "baz", "blip"),
525+
},
526+
{
527+
"rename and overwrite existing label",
528+
mustNewLabelsFormatter([]LabelFmt{
529+
NewRenameLabelFmt("bar", "foo"),
530+
}),
531+
labels.FromStrings("foo", "blip", "bar", "blop"),
532+
labels.FromStrings("bar", "blip"),
533+
},
518534
{
519535
"combined with template",
520536
mustNewLabelsFormatter([]LabelFmt{NewTemplateLabelFmt("foo", "{{.foo}} and {{.bar}}")}),

0 commit comments

Comments
 (0)