Skip to content

Commit

Permalink
Distributor: improve extracting status code from ingester.Push() erro…
Browse files Browse the repository at this point in the history
…rs (#6598)

Signed-off-by: Yuri Nikolic <[email protected]>
  • Loading branch information
duricanikolic authored Nov 8, 2023
1 parent de34ba9 commit dbc941a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/gogo/status"
"github.com/grafana/dskit/grpcutil"
"github.com/grafana/dskit/httpgrpc"
"github.com/grafana/dskit/instrument"
Expand All @@ -41,6 +40,7 @@ import (
"go.uber.org/atomic"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc/codes"

"github.com/grafana/mimir/pkg/cardinality"
ingester_client "github.com/grafana/mimir/pkg/ingester/client"
Expand Down Expand Up @@ -1394,20 +1394,24 @@ func handleIngesterPushError(err error) error {
return nil
}

// TODO This code is needed for backwards compatibility, since ingesters may still return
// errors created by httpgrpc.Errorf(). If pushErr is one of those errors, we just propagate
// it. This code should be removed in mimir 2.12.0.
resp, ok := httpgrpc.HTTPResponseFromError(err)
if ok {
stat, ok := grpcutil.ErrorToStatus(err)
if !ok {
return errors.Wrap(err, failedPushingToIngesterMessage)
}
statusCode := stat.Code()
if isHTTPStatusCode(statusCode) {
// TODO This code is needed for backwards compatibility, since ingesters may still return
// errors created by httpgrpc.Errorf(). If pushErr is one of those errors, we just propagate
// it. This code should be removed in mimir 2.12.0.
// Wrap HTTP gRPC error with more explanatory message.
return httpgrpc.Errorf(int(resp.Code), "%s: %s", failedPushingToIngesterMessage, resp.Body)
return httpgrpc.Errorf(int(statusCode), "%s: %s", failedPushingToIngesterMessage, stat.Message())
}

stat, ok := status.FromError(err)
if ok {
return newIngesterPushError(stat)
}
return errors.Wrap(err, failedPushingToIngesterMessage)
return newIngesterPushError(stat)
}

func isHTTPStatusCode(statusCode codes.Code) bool {
return int(statusCode) >= 100 && int(statusCode) < 600
}

// forReplicationSet runs f, in parallel, for all ingesters in the input replication set.
Expand Down

0 comments on commit dbc941a

Please sign in to comment.