Skip to content

Commit

Permalink
legacy endpoint 400s metric queries (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d authored and cyriltovena committed Jan 17, 2020
1 parent f331d2b commit 366e06f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/querier/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package querier

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -94,6 +95,22 @@ func (q *Querier) LogQueryHandler(w http.ResponseWriter, r *http.Request) {
return
}

expr, err := logql.ParseExpr(request.Query)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

// short circuit metric queries
if _, ok := expr.(logql.SampleExpr); ok {
http.Error(
w,
fmt.Sprintf("legacy endpoints only support %s result type", logql.ValueTypeStreams),
http.StatusBadRequest,
)
return
}

query := q.engine.NewRangeQuery(q, request.Query, request.Start, request.End, request.Step, request.Direction, request.Limit)
result, err := query.Exec(ctx)
if err != nil {
Expand Down Expand Up @@ -288,9 +305,8 @@ func NewPrepopulateMiddleware() middleware.Interface {
// parseRegexQuery parses regex and query querystring from httpRequest and returns the combined LogQL query.
// This is used only to keep regexp query string support until it gets fully deprecated.
func parseRegexQuery(httpRequest *http.Request) (string, error) {
params := httpRequest.URL.Query()
query := params.Get("query")
regexp := params.Get("regexp")
query := httpRequest.Form.Get("query")
regexp := httpRequest.Form.Get("regexp")
if regexp != "" {
expr, err := logql.ParseLogSelector(query)
if err != nil {
Expand Down

0 comments on commit 366e06f

Please sign in to comment.