fix(label_format): renamed label should use ParsedLabel category (#14515)

Signed-off-by: Ashwanth Goli <iamashwanth@gmail.com>
pull/14520/head
Ashwanth 7 months ago committed by GitHub
parent 08f6d29f86
commit 82fb2f0ae2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      pkg/logql/log/fmt.go
  2. 16
      pkg/logql/log/fmt_test.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

@ -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}}")}),

Loading…
Cancel
Save