forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Initial commit targetting grpc registry server (feast-dev#4458)
* initial commit targetting grpc registry server Signed-off-by: Daniele Martinoli <dmartino@redhat.com> * refactor: Introduced base class FeastError for all Feast exceptions (feast-dev#4465) introduced base class FeastError for all Feast exceptions, with initial methods to map the grpc and HTTP status code Signed-off-by: Daniele Martinoli <dmartino@redhat.com> * initial commit targetting grpc registry server Signed-off-by: Daniele Martinoli <dmartino@redhat.com> * fixed merge error Signed-off-by: Daniele Martinoli <dmartino@redhat.com> * initial commit targetting grpc registry server Signed-off-by: Daniele Martinoli <dmartino@redhat.com> * fixed merge error Signed-off-by: Daniele Martinoli <dmartino@redhat.com> * integrated comment Signed-off-by: Daniele Martinoli <dmartino@redhat.com> * moved imports as per comment Signed-off-by: Daniele Martinoli <dmartino@redhat.com> --------- Signed-off-by: Daniele Martinoli <dmartino@redhat.com>
- Loading branch information
Showing
7 changed files
with
197 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import grpc | ||
|
||
from feast.errors import FeastError | ||
|
||
|
||
def exception_wrapper(behavior, request, context): | ||
try: | ||
return behavior(request, context) | ||
except grpc.RpcError as e: | ||
context.abort(e.code(), e.details()) | ||
except FeastError as e: | ||
context.abort( | ||
e.grpc_status_code(), | ||
e.to_error_detail(), | ||
) | ||
|
||
|
||
class ErrorInterceptor(grpc.ServerInterceptor): | ||
def intercept_service(self, continuation, handler_call_details): | ||
handler = continuation(handler_call_details) | ||
if handler is None: | ||
return None | ||
|
||
if handler.unary_unary: | ||
return grpc.unary_unary_rpc_method_handler( | ||
lambda req, ctx: exception_wrapper(handler.unary_unary, req, ctx), | ||
request_deserializer=handler.request_deserializer, | ||
response_serializer=handler.response_serializer, | ||
) | ||
elif handler.unary_stream: | ||
return grpc.unary_stream_rpc_method_handler( | ||
lambda req, ctx: exception_wrapper(handler.unary_stream, req, ctx), | ||
request_deserializer=handler.request_deserializer, | ||
response_serializer=handler.response_serializer, | ||
) | ||
elif handler.stream_unary: | ||
return grpc.stream_unary_rpc_method_handler( | ||
lambda req, ctx: exception_wrapper(handler.stream_unary, req, ctx), | ||
request_deserializer=handler.request_deserializer, | ||
response_serializer=handler.response_serializer, | ||
) | ||
elif handler.stream_stream: | ||
return grpc.stream_stream_rpc_method_handler( | ||
lambda req, ctx: exception_wrapper(handler.stream_stream, req, ctx), | ||
request_deserializer=handler.request_deserializer, | ||
response_serializer=handler.response_serializer, | ||
) | ||
return handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import re | ||
|
||
import assertpy | ||
|
||
import feast.errors as errors | ||
|
||
|
||
def test_error_error_detail(): | ||
e = errors.FeatureViewNotFoundException("abc") | ||
|
||
d = e.to_error_detail() | ||
|
||
assertpy.assert_that(d).is_not_none() | ||
assertpy.assert_that(d).contains('"module": "feast.errors"') | ||
assertpy.assert_that(d).contains('"class": "FeatureViewNotFoundException"') | ||
assertpy.assert_that(re.search(r"abc", d)).is_true() | ||
|
||
converted_e = errors.FeastError.from_error_detail(d) | ||
assertpy.assert_that(converted_e).is_not_none() | ||
assertpy.assert_that(str(converted_e)).is_equal_to(str(e)) | ||
assertpy.assert_that(repr(converted_e)).is_equal_to(repr(e)) | ||
|
||
|
||
def test_invalid_error_error_detail(): | ||
e = errors.FeastError.from_error_detail("invalid") | ||
assertpy.assert_that(e).is_none() |