Skip to content

Commit

Permalink
Fixes some 500 returned by querier when storage cancellation happens.
Browse files Browse the repository at this point in the history
For unknown reasons,  Cortex is transforming all errors to promql.ErrStorage
on the storage layer.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored and slim-bean committed Feb 26, 2021
1 parent 6eb5cbb commit 34f8252
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/util/server/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"

"github.com/cortexproject/cortex/pkg/chunk"
"github.com/prometheus/prometheus/promql"
"github.com/weaveworks/common/httpgrpc"
"github.com/weaveworks/common/user"

Expand All @@ -22,10 +23,14 @@ const (

// WriteError write a go error with the correct status code.
func WriteError(err error, w http.ResponseWriter) {
var queryErr chunk.QueryError
var (
queryErr chunk.QueryError
promErr promql.ErrStorage
)

switch {
case errors.Is(err, context.Canceled):
case errors.Is(err, context.Canceled) ||
(errors.As(err, &promErr) && errors.Is(promErr.Err, context.Canceled)):
http.Error(w, ErrClientCanceled, StatusClientClosedRequest)
case errors.Is(err, context.DeadlineExceeded):
http.Error(w, ErrDeadlineExceeded, http.StatusGatewayTimeout)
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/server/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/cortexproject/cortex/pkg/chunk"
"github.com/prometheus/prometheus/promql"
"github.com/stretchr/testify/require"
"github.com/weaveworks/common/httpgrpc"
"github.com/weaveworks/common/user"
Expand All @@ -28,6 +29,7 @@ func Test_writeError(t *testing.T) {
}{
{"cancelled", context.Canceled, ErrClientCanceled, StatusClientClosedRequest},
{"cancelled multi", util.MultiError{context.Canceled, context.Canceled}, ErrClientCanceled, StatusClientClosedRequest},
{"cancelled storage", promql.ErrStorage{Err: context.Canceled}, ErrClientCanceled, StatusClientClosedRequest},
{"orgid", user.ErrNoOrgID, user.ErrNoOrgID.Error(), http.StatusBadRequest},
{"deadline", context.DeadlineExceeded, ErrDeadlineExceeded, http.StatusGatewayTimeout},
{"parse error", logql.ParseError{}, "parse error : ", http.StatusBadRequest},
Expand Down

0 comments on commit 34f8252

Please sign in to comment.