Skip to content

Commit

Permalink
Rerun parsing for the query expression in the experimental functions …
Browse files Browse the repository at this point in the history
…middleware and remove `GetQueryExpr`
  • Loading branch information
zenador committed Nov 15, 2024
1 parent abdaebc commit 5245b1c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 20 deletions.
7 changes: 0 additions & 7 deletions pkg/frontend/querymiddleware/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@ type MetricsQueryRequest interface {
GetStep() int64
// GetQuery returns the query of the request.
GetQuery() string
// GetQueryExpr returns the parsed query expression of the request.
// Since this returns a pointer, be careful not to use the returned expression in
// functions that may mutate it unintentionally and pass the mutated form to the next
// middleware, unless that is the intended behavior and we use WithQuery to replace the query.
// If you need to mutate the expression temporarily, then reparse the query string
// and use that instead of this function.
GetQueryExpr() parser.Expr
// GetMinT returns the minimum timestamp in milliseconds of data to be queried,
// as determined from the start timestamp and any range vector or offset in the query.
GetMinT() int64
Expand Down
5 changes: 4 additions & 1 deletion pkg/frontend/querymiddleware/experimental_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func (m *experimentalFunctionsMiddleware) Do(ctx context.Context, req MetricsQue
return m.next.Do(ctx, req)
}

expr := req.GetQueryExpr()
expr, err := parser.ParseExpr(req.GetQuery())
if err != nil {
return nil, apierror.New(apierror.TypeBadData, DecorateWithParamName(err, "query").Error())
}
funcs := containedExperimentalFunctions(expr)
if len(funcs) == 0 {
// This query does not contain any experimental functions, so we can continue to the next middleware.
Expand Down
8 changes: 0 additions & 8 deletions pkg/frontend/querymiddleware/model_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ func (r *PrometheusRangeQueryRequest) GetQuery() string {
return ""
}

func (r *PrometheusRangeQueryRequest) GetQueryExpr() parser.Expr {
return r.queryExpr
}

// GetMinT returns the minimum timestamp in milliseconds of data to be queried,
// as determined from the start timestamp and any range vector or offset in the query.
func (r *PrometheusRangeQueryRequest) GetMinT() int64 {
Expand Down Expand Up @@ -317,10 +313,6 @@ func (r *PrometheusInstantQueryRequest) GetQuery() string {
return ""
}

func (r *PrometheusInstantQueryRequest) GetQueryExpr() parser.Expr {
return r.queryExpr
}

func (r *PrometheusInstantQueryRequest) GetStart() int64 {
return r.GetTime()
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/frontend/querymiddleware/remote_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ func (r *remoteReadQueryRequest) GetQuery() string {
return r.promQuery
}

func (r *remoteReadQueryRequest) GetQueryExpr() parser.Expr {
return nil
}

func (r *remoteReadQueryRequest) GetHeaders() []*PrometheusHeader {
return nil
}
Expand Down

0 comments on commit 5245b1c

Please sign in to comment.