Skip to content

Commit

Permalink
Rename ParserExpr to LineParserExpr
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed Jan 31, 2025
1 parent e413227 commit 0f0f218
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pkg/logql/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func removeLineformat(expr syntax.SampleExpr) {
found = true
break
}
if _, ok := pipelineExpr.MultiStages[j].(*syntax.ParserExpr); ok {
if _, ok := pipelineExpr.MultiStages[j].(*syntax.LineParserExpr); ok {
found = true
break
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/logql/rangemapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func hasLabelExtractionStage(expr syntax.SampleExpr) bool {
switch concrete := e.(type) {
case *syntax.LogfmtParserExpr:
found = true
case *syntax.ParserExpr:
case *syntax.LineParserExpr:
// It will **not** return true for `regexp`, `unpack` and `pattern`, since these label extraction
// stages can control how many labels, and therefore the resulting amount of series, are extracted.
if concrete.Op == syntax.OpParserTypeJSON {
Expand Down
24 changes: 12 additions & 12 deletions pkg/logql/syntax/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (VectorAggregationExpr) isExpr() {}
func (LiteralExpr) isExpr() {}
func (VectorExpr) isExpr() {}
func (LabelReplaceExpr) isExpr() {}
func (ParserExpr) isExpr() {}
func (LineParserExpr) isExpr() {}
func (LogfmtParserExpr) isExpr() {}
func (LineFilterExpr) isExpr() {}
func (LabelFilterExpr) isExpr() {}
Expand Down Expand Up @@ -73,7 +73,7 @@ func (LiteralExpr) isSampleExpr() {}
func (VectorExpr) isSampleExpr() {}
func (LabelReplaceExpr) isSampleExpr() {}

func (ParserExpr) isStageExpr() {}
func (LineParserExpr) isStageExpr() {}
func (LogfmtParserExpr) isStageExpr() {}
func (LineFilterExpr) isStageExpr() {}
func (LabelFilterExpr) isStageExpr() {}
Expand Down Expand Up @@ -145,7 +145,7 @@ func ExtractLabelFiltersBeforeParser(e Expr) []*LabelFilterExpr {
// misbehave.

VisitLogfmtParserFn: func(_ RootVisitor, _ *LogfmtParserExpr) { foundParseStage = true },
VisitLabelParserFn: func(_ RootVisitor, _ *ParserExpr) { foundParseStage = true },
VisitLabelParserFn: func(_ RootVisitor, _ *LineParserExpr) { foundParseStage = true },
VisitJSONExpressionParserFn: func(_ RootVisitor, _ *JSONExpressionParserExpr) { foundParseStage = true },
VisitLogfmtExpressionParserFn: func(_ RootVisitor, _ *LogfmtExpressionParserExpr) { foundParseStage = true },
VisitLabelFmtFn: func(_ RootVisitor, _ *LabelFmtExpr) { foundParseStage = true },
Expand Down Expand Up @@ -258,7 +258,7 @@ func (m MultiStageExpr) reorderStages() []StageExpr {
notLineFilters = append(notLineFilters, f)

combineFilters()
case *ParserExpr:
case *LineParserExpr:
notLineFilters = append(notLineFilters, f)

// unpack modifies the contents of the line so any line filter
Expand Down Expand Up @@ -707,12 +707,12 @@ func (e *LogfmtParserExpr) String() string {
return sb.String()
}

type ParserExpr struct {
type LineParserExpr struct {
Op string
Param string
}

func newLabelParserExpr(op, param string) *ParserExpr {
func newLabelParserExpr(op, param string) *LineParserExpr {
if op == OpParserTypeRegexp {
_, err := log.NewRegexpParser(param)
if err != nil {
Expand All @@ -726,19 +726,19 @@ func newLabelParserExpr(op, param string) *ParserExpr {
}
}

return &ParserExpr{
return &LineParserExpr{
Op: op,
Param: param,
}
}

func (e *ParserExpr) Shardable(_ bool) bool { return true }
func (e *LineParserExpr) Shardable(_ bool) bool { return true }

func (e *ParserExpr) Walk(f WalkFn) { f(e) }
func (e *LineParserExpr) Walk(f WalkFn) { f(e) }

func (e *ParserExpr) Accept(v RootVisitor) { v.VisitLabelParser(e) }
func (e *LineParserExpr) Accept(v RootVisitor) { v.VisitLabelParser(e) }

func (e *ParserExpr) Stage() (log.Stage, error) {
func (e *LineParserExpr) Stage() (log.Stage, error) {
switch e.Op {
case OpParserTypeJSON:
return log.NewJSONParser(), nil
Expand All @@ -753,7 +753,7 @@ func (e *ParserExpr) Stage() (log.Stage, error) {
}
}

func (e *ParserExpr) String() string {
func (e *LineParserExpr) String() string {
var sb strings.Builder
sb.WriteString(OpPipe)
sb.WriteString(" ")
Expand Down
4 changes: 2 additions & 2 deletions pkg/logql/syntax/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ func Test_parserExpr_Parser(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var e *ParserExpr
var e *LineParserExpr
if tt.wantPanic {
require.Panics(t, func() { e = newLabelParserExpr(tt.op, tt.param) })
return
Expand Down Expand Up @@ -923,7 +923,7 @@ func Test_parserExpr_String(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
l := ParserExpr{
l := LineParserExpr{
Op: tt.op,
Param: tt.param,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/logql/syntax/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ func (v *cloneVisitor) VisitLabelFmt(e *LabelFmtExpr) {
v.cloned = copied
}

func (v *cloneVisitor) VisitLabelParser(e *ParserExpr) {
v.cloned = &ParserExpr{
func (v *cloneVisitor) VisitLabelParser(e *LineParserExpr) {
v.cloned = &LineParserExpr{
Op: e.Op,
Param: e.Param,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/logql/syntax/prettier.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (e *LogfmtParserExpr) Pretty(level int) string {
// `| regexp`
// `| pattern`
// `| unpack`
func (e *ParserExpr) Pretty(level int) string {
func (e *LineParserExpr) Pretty(level int) string {
return commonPrefixIndent(level, e)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/logql/syntax/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (*JSONSerializer) VisitJSONExpressionParser(*JSONExpressionParserExpr)
func (*JSONSerializer) VisitKeepLabel(*KeepLabelsExpr) {}
func (*JSONSerializer) VisitLabelFilter(*LabelFilterExpr) {}
func (*JSONSerializer) VisitLabelFmt(*LabelFmtExpr) {}
func (*JSONSerializer) VisitLabelParser(*ParserExpr) {}
func (*JSONSerializer) VisitLabelParser(*LineParserExpr) {}
func (*JSONSerializer) VisitLineFilter(*LineFilterExpr) {}
func (*JSONSerializer) VisitLineFmt(*LineFmtExpr) {}
func (*JSONSerializer) VisitLogfmtExpressionParser(*LogfmtExpressionParserExpr) {}
Expand Down
6 changes: 3 additions & 3 deletions pkg/logql/syntax/visit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type StageExprVisitor interface {
VisitKeepLabel(*KeepLabelsExpr)
VisitLabelFilter(*LabelFilterExpr)
VisitLabelFmt(*LabelFmtExpr)
VisitLabelParser(*ParserExpr)
VisitLabelParser(*LineParserExpr)
VisitLineFilter(*LineFilterExpr)
VisitLineFmt(*LineFmtExpr)
VisitLogfmtExpressionParser(*LogfmtExpressionParserExpr)
Expand All @@ -52,7 +52,7 @@ type DepthFirstTraversal struct {
VisitKeepLabelFn func(v RootVisitor, e *KeepLabelsExpr)
VisitLabelFilterFn func(v RootVisitor, e *LabelFilterExpr)
VisitLabelFmtFn func(v RootVisitor, e *LabelFmtExpr)
VisitLabelParserFn func(v RootVisitor, e *ParserExpr)
VisitLabelParserFn func(v RootVisitor, e *LineParserExpr)
VisitLabelReplaceFn func(v RootVisitor, e *LabelReplaceExpr)
VisitLineFilterFn func(v RootVisitor, e *LineFilterExpr)
VisitLineFmtFn func(v RootVisitor, e *LineFmtExpr)
Expand Down Expand Up @@ -141,7 +141,7 @@ func (v *DepthFirstTraversal) VisitLabelFmt(e *LabelFmtExpr) {
}

// VisitLabelParser implements RootVisitor.
func (v *DepthFirstTraversal) VisitLabelParser(e *ParserExpr) {
func (v *DepthFirstTraversal) VisitLabelParser(e *LineParserExpr) {
if e == nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/logql/syntax/visit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestDepthFirstTraversalVisitor(t *testing.T) {
visited := [][2]string{}

visitor := &DepthFirstTraversal{
VisitLabelParserFn: func(_ RootVisitor, e *ParserExpr) {
VisitLabelParserFn: func(_ RootVisitor, e *LineParserExpr) {
visited = append(visited, [2]string{fmt.Sprintf("%T", e), e.String()})
},
VisitLineFilterFn: func(_ RootVisitor, e *LineFilterExpr) {
Expand All @@ -33,7 +33,7 @@ func TestDepthFirstTraversalVisitor(t *testing.T) {
{"*syntax.LogfmtParserExpr", `| logfmt`},
{"*syntax.MatchersExpr", `{env="dev"}`},
{"*syntax.LineFilterExpr", `|~ "(foo|bar)"`},
{"*syntax.ParserExpr", `| json`},
{"*syntax.LineParserExpr", `| json`},
}

query := `
Expand Down

0 comments on commit 0f0f218

Please sign in to comment.