Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler guarantees for logql exprs #1626

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions pkg/logql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
)

// Expr is the root expression which can be a SampleExpr or LogSelectorExpr
type Expr interface{}
type Expr interface {
logQLExpr() // ensure it's not implemented accidentally
}

// SelectParams specifies parameters passed to data selections.
type SelectParams struct {
Expand Down Expand Up @@ -52,6 +54,7 @@ type LogSelectorExpr interface {
Filter() (Filter, error)
Matchers() []*labels.Matcher
fmt.Stringer
Expr
}

type matchersExpr struct {
Expand Down Expand Up @@ -83,6 +86,9 @@ func (e *matchersExpr) Filter() (Filter, error) {
return nil, nil
}

// impl Expr
func (e *matchersExpr) logQLExpr() {}

type filterExpr struct {
left LogSelectorExpr
ty labels.MatchType
Expand Down Expand Up @@ -166,6 +172,9 @@ func (e *filterExpr) Filter() (Filter, error) {
return f, nil
}

// impl Expr
func (e *filterExpr) logQLExpr() {}

func mustNewMatcher(t labels.MatchType, n, v string) *labels.Matcher {
m, err := labels.NewMatcher(t, n, v)
if err != nil {
Expand Down Expand Up @@ -213,6 +222,7 @@ const (
type SampleExpr interface {
// Selector is the LogQL selector to apply when retrieving logs.
Selector() LogSelectorExpr
Expr
}

// StepEvaluator evaluate a single step of a query.
Expand Down Expand Up @@ -266,6 +276,9 @@ func (e *rangeAggregationExpr) Selector() LogSelectorExpr {
return e.left.left
}

// impl Expr
func (e *rangeAggregationExpr) logQLExpr() {}

type grouping struct {
groups []string
without bool
Expand Down Expand Up @@ -306,6 +319,9 @@ func mustNewVectorAggregationExpr(left SampleExpr, operation string, gr *groupin
}
}

func (v *vectorAggregationExpr) Selector() LogSelectorExpr {
return v.left.Selector()
func (e *vectorAggregationExpr) Selector() LogSelectorExpr {
return e.left.Selector()
}

// impl Expr
func (e *vectorAggregationExpr) logQLExpr() {}