Skip to content

Commit

Permalink
ingester: map METHOD_NOT_ALLOWED to status error
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Varankin <[email protected]>
  • Loading branch information
narqo committed Mar 18, 2024
1 parent 777be76 commit bf9a19d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/ingester/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ func mapPushErrorToErrorWithStatus(err error) error {
wrappedErr = middleware.DoNotLogError{Err: err}
case mimirpb.TSDB_UNAVAILABLE:
errCode = codes.Internal
case mimirpb.METHOD_NOT_ALLOWED:
errCode = codes.Unimplemented
}
}
return newErrorWithStatus(wrappedErr, errCode)
Expand All @@ -603,6 +605,8 @@ func mapPushErrorToErrorWithHTTPOrGRPCStatus(err error) error {
return newErrorWithStatus(middleware.DoNotLogError{Err: err}, codes.Unavailable)
case mimirpb.TSDB_UNAVAILABLE:
return newErrorWithHTTPStatus(err, http.StatusServiceUnavailable)
case mimirpb.METHOD_NOT_ALLOWED:
return newErrorWithStatus(err, codes.Unimplemented)
}
}
return err
Expand All @@ -620,6 +624,8 @@ func mapReadErrorToErrorWithStatus(err error) error {
errCode = codes.ResourceExhausted
case mimirpb.SERVICE_UNAVAILABLE:
errCode = codes.Unavailable
case mimirpb.METHOD_NOT_ALLOWED:
return newErrorWithStatus(err, codes.Unimplemented)
}
}
return newErrorWithStatus(err, errCode)
Expand All @@ -637,6 +643,8 @@ func mapReadErrorToErrorWithHTTPOrGRPCStatus(err error) error {
return newErrorWithHTTPStatus(err, http.StatusServiceUnavailable)
case mimirpb.SERVICE_UNAVAILABLE:
return newErrorWithStatus(err, codes.Unavailable)
case mimirpb.METHOD_NOT_ALLOWED:
return newErrorWithStatus(err, codes.Unimplemented)
}
}
return err
Expand Down
26 changes: 26 additions & 0 deletions pkg/ingester/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ func TestMapPushErrorToErrorWithStatus(t *testing.T) {
expectedMessage: fmt.Sprintf("wrapped: %s", newUnavailableError(services.Stopping).Error()),
expectedDetails: &mimirpb.ErrorDetails{Cause: mimirpb.SERVICE_UNAVAILABLE},
},
"an ingesterPushGrpcDisabledError gets translated into an errorWithStatus Unimplemented error with details": {
err: ingesterPushGrpcDisabledError{},
expectedCode: codes.Unimplemented,
expectedMessage: ingesterPushGrpcDisabledMsg,
expectedDetails: &mimirpb.ErrorDetails{Cause: mimirpb.METHOD_NOT_ALLOWED},
},
"a wrapped ingesterPushGrpcDisabledError gets translated into an errorWithStatus Unimplemented error": {
err: fmt.Errorf("wrapped: %w", ingesterPushGrpcDisabledError{}),
expectedCode: codes.Unimplemented,
expectedMessage: fmt.Sprintf("wrapped: %s", ingesterPushGrpcDisabledMsg),
expectedDetails: &mimirpb.ErrorDetails{Cause: mimirpb.METHOD_NOT_ALLOWED},
},
"an instanceLimitReachedError gets translated into a non-loggable errorWithStatus Unavailable error with details": {
err: newInstanceLimitReachedError("instance limit reached"),
expectedCode: codes.Unavailable,
Expand Down Expand Up @@ -688,6 +700,20 @@ func TestMapPushErrorToErrorWithHTTPOrGRPCStatus(t *testing.T) {
http.StatusBadRequest,
),
},
"an ingesterPushGrpcDisabledError gets translated into an errorWithStatus Unimplemented error": {
err: ingesterPushGrpcDisabledError{},
expectedTranslation: newErrorWithStatus(
ingesterPushGrpcDisabledError{},
codes.Unimplemented,
),
},
"a wrapped ingesterPushGrpcDisabledError gets translated into an errorWithStatus Unimplemented error": {
err: fmt.Errorf("wrapped: %w", ingesterPushGrpcDisabledError{}),
expectedTranslation: newErrorWithStatus(
fmt.Errorf("wrapped: %w", ingesterPushGrpcDisabledError{}),
codes.Unimplemented,
),
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit bf9a19d

Please sign in to comment.