Skip to content

Commit

Permalink
fix(logql): properly parse rename in label_format
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Apr 17, 2024
1 parent fcd4e90 commit fbb5ade
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions internal/logql/logqlengine/label_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type RenameLabel struct {
// Process implements Processor.
func (rl *RenameLabel) Process(_ otelstorage.Timestamp, line string, set LabelSet) (_ string, keep bool) {
for _, p := range rl.pairs {
if v, ok := set.Get(p.Label); ok {
if v, ok := set.Get(p.From); ok {
set.Set(p.To, v)
set.Delete(p.Label)
set.Delete(p.From)
}
}
return line, true
Expand Down
6 changes: 3 additions & 3 deletions internal/logql/logqlengine/label_format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestLabelFormat(t *testing.T) {
// No label.
{
map[logql.Label]pcommon.Value{},
[]logql.RenameLabel{{Label: "foo", To: "bar"}},
[]logql.RenameLabel{{From: "foo", To: "bar"}},
nil,
map[logql.Label]pcommon.Value{},
false,
Expand All @@ -32,7 +32,7 @@ func TestLabelFormat(t *testing.T) {
map[logql.Label]pcommon.Value{
"foo": pcommon.NewValueStr("foo"),
},
[]logql.RenameLabel{{Label: "foo", To: "bar"}},
[]logql.RenameLabel{{From: "foo", To: "bar"}},
nil,
map[logql.Label]pcommon.Value{
"bar": pcommon.NewValueStr("foo"),
Expand All @@ -46,7 +46,7 @@ func TestLabelFormat(t *testing.T) {
"foo": pcommon.NewValueStr("foo"),
},
[]logql.RenameLabel{
{Label: "foo", To: "bar"},
{From: "foo", To: "bar"},
},
[]logql.LabelTemplate{
{Label: "tmpl", Template: `{{ __timestamp__.Unix }}`},
Expand Down
2 changes: 1 addition & 1 deletion internal/logql/parser_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (p *parser) parseLabelFormatExpr() (lf *LabelFormatExpr, err error) {
if err != nil {
return nil, err
}
lf.Labels = append(lf.Labels, RenameLabel{Label: label, To: value})
lf.Labels = append(lf.Labels, RenameLabel{To: label, From: value})
case lexer.String:
value, err := p.parseString()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/logql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ var tests = []TestCase{
},
{
`{name="kafka"}
| label_format foo=foo
| label_format foo=bar
| label_format bar="bar"
| label_format foo=foo,bar="bar"
`,
Expand All @@ -311,7 +311,7 @@ var tests = []TestCase{
Pipeline: []PipelineStage{
&LabelFormatExpr{
Labels: []RenameLabel{
{"foo", "foo"},
{To: "foo", From: "bar"},
},
},
&LabelFormatExpr{
Expand Down
4 changes: 2 additions & 2 deletions internal/logql/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ type LabelTemplate struct {

// RenameLabel renames label.
type RenameLabel struct {
Label Label
To Label
To Label
From Label
}

// DropLabelsExpr drops given labels in a pipeline (i.e. deny list).
Expand Down

0 comments on commit fbb5ade

Please sign in to comment.