Skip to content

Commit

Permalink
compiler guarantees for logql exprs (#1626)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d authored Feb 4, 2020
1 parent 39c2868 commit 1773900
Showing 1 changed file with 19 additions and 3 deletions.
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() {}

0 comments on commit 1773900

Please sign in to comment.