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

Ensure status codes are set correctly in the frontend. #1684

Merged
merged 2 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
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
11 changes: 4 additions & 7 deletions pkg/querier/queryrange/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func (r *LokiRequest) WithStartEnd(s int64, e int64) queryrange.Request {

func (codec) DecodeRequest(_ context.Context, r *http.Request) (queryrange.Request, error) {
if err := r.ParseForm(); err != nil {
return nil, err
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
}
req, err := loghttp.ParseRangeQuery(r)
if err != nil {
return nil, err
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
}
return &LokiRequest{
Query: req.Query,
Expand Down Expand Up @@ -117,14 +117,11 @@ func (codec) DecodeResponse(ctx context.Context, r *http.Response, req queryrang
if err := json.Unmarshal(buf, &resp); err != nil {
return nil, httpgrpc.Errorf(http.StatusInternalServerError, "error decoding response: %v", err)
}
if resp.Status != loghttp.QueryStatusSuccess {
return nil, httpgrpc.Errorf(http.StatusInternalServerError, "error executing request: %v", resp.Status)
}
switch string(resp.Data.ResultType) {
case loghttp.ResultTypeMatrix:
return &LokiPromResponse{
Response: &queryrange.PrometheusResponse{
Status: loghttp.QueryStatusSuccess,
Status: resp.Status,
Data: queryrange.PrometheusData{
ResultType: loghttp.ResultTypeMatrix,
Result: toProto(resp.Data.Result.(loghttp.Matrix)),
Expand All @@ -134,7 +131,7 @@ func (codec) DecodeResponse(ctx context.Context, r *http.Response, req queryrang
}, nil
case loghttp.ResultTypeStream:
return &LokiResponse{
Status: loghttp.QueryStatusSuccess,
Status: resp.Status,
Direction: req.(*LokiRequest).Direction,
Limit: req.(*LokiRequest).Limit,
Version: uint32(loghttp.GetVersion(req.(*LokiRequest).Path)),
Expand Down
6 changes: 4 additions & 2 deletions pkg/querier/queryrange/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/go-kit/kit/log/level"
"github.com/grafana/loki/pkg/logql"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/weaveworks/common/httpgrpc"
)

// Config is the configuration for the queryrange tripperware
Expand Down Expand Up @@ -55,7 +56,8 @@ func NewTripperware(cfg Config, log log.Logger, limits Limits) (frontend.Tripper
query := params.Get("query")
expr, err := logql.ParseExpr(query)
if err != nil {
return nil, err
// weavework server uses httpgrpc errors for status code.
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
}
if _, ok := expr.(logql.SampleExpr); ok {
return metricRT.RoundTrip(req)
Expand All @@ -70,7 +72,7 @@ func NewTripperware(cfg Config, log log.Logger, limits Limits) (frontend.Tripper
}
filter, err := logSelector.Filter()
if err != nil {
return nil, err
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
}
if filter != nil {
return logFilterRT.RoundTrip(req)
Expand Down
5 changes: 3 additions & 2 deletions pkg/querier/queryrange/split_by_interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package queryrange

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

"github.com/cortexproject/cortex/pkg/querier/queryrange"
"github.com/grafana/loki/pkg/logproto"
"github.com/opentracing/opentracing-go"
otlog "github.com/opentracing/opentracing-go/log"
"github.com/weaveworks/common/httpgrpc"
"github.com/weaveworks/common/user"
)

Expand Down Expand Up @@ -135,7 +137,7 @@ func (h *splitByInterval) Do(ctx context.Context, r queryrange.Request) (queryra

userid, err := user.ExtractOrgID(ctx)
if err != nil {
return nil, err
return nil, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
}

interval := h.limits.QuerySplitDuration(userid)
Expand Down Expand Up @@ -169,7 +171,6 @@ func (h *splitByInterval) Do(ctx context.Context, r queryrange.Request) (queryra
if err != nil {
return nil, err
}

return h.merger.MergeResponse(resps...)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wanted to also tackle the fact that I've seen an empty list going there once. But then I realized I'm not sure why this has happened so I let it be a 500, because we should take care of it.

}

Expand Down