Skip to content

Commit

Permalink
fix(logql): A renamed label should use ParsedLabel category to take p…
Browse files Browse the repository at this point in the history
…recendence (backport k224) (#14516)

Co-authored-by: Ashwanth <[email protected]>
  • Loading branch information
loki-gh-app[bot] and ashwanthgoli authored Oct 17, 2024
1 parent bebe9fa commit 25bee22
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 25bee22

Please sign in to comment.