Skip to content

Commit

Permalink
fix(label_format): renamed label should use ParsedLabel category (#14515
Browse files Browse the repository at this point in the history
)

Signed-off-by: Ashwanth Goli <[email protected]>
  • Loading branch information
ashwanthgoli authored Oct 17, 2024
1 parent 08f6d29 commit 82fb2f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/logql/log/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions pkg/logql/log/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}")}),
Expand Down

0 comments on commit 82fb2f0

Please sign in to comment.