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

distributor, ruler: Expect METHOD_NOT_ALLOWED from pusher #7618

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion pkg/distributor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ func toGRPCError(pushErr error, serviceOverloadErrorEnabled bool) error {
errCode = codes.FailedPrecondition
case mimirpb.CIRCUIT_BREAKER_OPEN:
errCode = codes.Unavailable
case mimirpb.METHOD_NOT_ALLOWED:
errCode = codes.Unimplemented
}
}
stat := status.New(errCode, pushErr.Error())
Expand Down Expand Up @@ -296,7 +298,11 @@ func wrapPartitionPushError(err error, partitionID int32) error {
func isIngesterClientError(err error) bool {
var ingesterPushErr ingesterPushError
if errors.As(err, &ingesterPushErr) {
return ingesterPushErr.errorCause() == mimirpb.BAD_DATA
switch ingesterPushErr.errorCause() {
case mimirpb.BAD_DATA, mimirpb.METHOD_NOT_ALLOWED:
return true
}
return false
}

// This code is needed for backwards compatibility, since ingesters may still return errors with HTTP status
Expand Down
18 changes: 17 additions & 1 deletion pkg/distributor/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ func TestToGRPCError(t *testing.T) {
expectedErrorMsg: fmt.Sprintf("%s %s: %s", failedPushingToIngesterMessage, ingesterID, circuitbreaker.ErrOpen),
expectedErrorDetails: &mimirpb.ErrorDetails{Cause: mimirpb.CIRCUIT_BREAKER_OPEN},
},
"an ingesterPushError with METHOD_NOT_ALLOWED cause gets translated into a Unimplemented error with METHOD_NOT_ALLOWED cause": {
err: newIngesterPushError(createStatusWithDetails(t, codes.Unimplemented, originalMsg, mimirpb.METHOD_NOT_ALLOWED), ingesterID),
expectedGRPCCode: codes.Unimplemented,
expectedErrorMsg: fmt.Sprintf("%s %s: %s", failedPushingToIngesterMessage, ingesterID, originalMsg),
expectedErrorDetails: &mimirpb.ErrorDetails{Cause: mimirpb.METHOD_NOT_ALLOWED},
},
"a DoNotLogError of an ingesterPushError with METHOD_NOT_ALLOWED cause gets translated into a Unimplemented error with METHOD_NOT_ALLOWED cause": {
err: middleware.DoNotLogError{Err: newIngesterPushError(createStatusWithDetails(t, codes.Unimplemented, originalMsg, mimirpb.METHOD_NOT_ALLOWED), ingesterID)},
expectedGRPCCode: codes.Unimplemented,
expectedErrorMsg: fmt.Sprintf("%s %s: %s", failedPushingToIngesterMessage, ingesterID, originalMsg),
expectedErrorDetails: &mimirpb.ErrorDetails{Cause: mimirpb.METHOD_NOT_ALLOWED},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
Expand Down Expand Up @@ -486,7 +498,11 @@ func TestIsIngesterClientError(t *testing.T) {
err: ingesterPushError{cause: mimirpb.BAD_DATA},
expectedOutcome: true,
},
"an ingesterPushError with error cause different from BAD_DATA is not a client error": {
"an ingesterPushError with error cause METHOD_NOT_ALLOWED is a client error": {
err: ingesterPushError{cause: mimirpb.METHOD_NOT_ALLOWED},
expectedOutcome: true,
},
"an ingesterPushError with other error cause is not a client error": {
err: ingesterPushError{cause: mimirpb.SERVICE_UNAVAILABLE},
expectedOutcome: false,
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/distributor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func toHTTPStatus(ctx context.Context, pushErr error, limits *validation.Overrid
return http.StatusServiceUnavailable
case mimirpb.CIRCUIT_BREAKER_OPEN:
return http.StatusServiceUnavailable
case mimirpb.METHOD_NOT_ALLOWED:
return http.StatusMethodNotAllowed
}
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/distributor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,16 @@ func TestHandler_ToHTTPStatus(t *testing.T) {
expectedHTTPStatus: http.StatusBadRequest,
expectedErrorMsg: fmt.Sprintf("%s %s: %s", failedPushingToIngesterMessage, ingesterID, originalMsg),
},
"an ingesterPushError with METHOD_NOT_ALLOWED cause gets translated into an HTTP 405": {
err: newIngesterPushError(createStatusWithDetails(t, codes.Unimplemented, originalMsg, mimirpb.METHOD_NOT_ALLOWED), ingesterID),
expectedHTTPStatus: http.StatusMethodNotAllowed,
expectedErrorMsg: fmt.Sprintf("%s %s: %s", failedPushingToIngesterMessage, ingesterID, originalMsg),
},
"a DoNotLogError of an ingesterPushError with METHOD_NOT_ALLOWED cause gets translated into an HTTP 405": {
err: middleware.DoNotLogError{Err: newIngesterPushError(createStatusWithDetails(t, codes.Unimplemented, originalMsg, mimirpb.METHOD_NOT_ALLOWED), ingesterID)},
expectedHTTPStatus: http.StatusMethodNotAllowed,
expectedErrorMsg: fmt.Sprintf("%s %s: %s", failedPushingToIngesterMessage, ingesterID, originalMsg),
},
"an ingesterPushError with TSDB_UNAVAILABLE cause gets translated into an HTTP 503": {
err: newIngesterPushError(createStatusWithDetails(t, codes.Internal, originalMsg, mimirpb.TSDB_UNAVAILABLE), ingesterID),
expectedHTTPStatus: http.StatusServiceUnavailable,
Expand Down
5 changes: 5 additions & 0 deletions pkg/ruler/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ func TestPusherErrors(t *testing.T) {
expectedWrites: 1,
expectedFailures: 0,
},
"a METHOD_NOT_ALLOWED push error is reported as failure": {
returnedError: mustStatusWithDetails(codes.Unimplemented, mimirpb.METHOD_NOT_ALLOWED).Err(),
expectedWrites: 1,
expectedFailures: 1,
},
"a TSDB_UNAVAILABLE push error is reported as failure": {
returnedError: mustStatusWithDetails(codes.FailedPrecondition, mimirpb.TSDB_UNAVAILABLE).Err(),
expectedWrites: 1,
Expand Down
Loading