-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add health check support to gRPC app
Signed-off-by: Yevgen Polyak <[email protected]>
- Loading branch information
1 parent
15fb0a8
commit bc6cc6f
Showing
15 changed files
with
137 additions
and
40 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
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
dapr-ext-workflow>=0.1.0 | ||
dapr-ext-workflow-dev>=0.4.1rc1.dev | ||
dapr-dev>=1.13.0rc1.dev |
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,32 @@ | ||
import grpc | ||
from typing import Callable, Optional | ||
|
||
from dapr.proto import appcallback_service_v1 | ||
from dapr.proto.runtime.v1.appcallback_pb2 import HealthCheckResponse | ||
|
||
HealthCheckCallable = Optional[Callable[[], None]] | ||
|
||
|
||
class _HealthCheckServicer(appcallback_service_v1.AppCallbackHealthCheckServicer): | ||
"""The implementation of HealthCheck Server. | ||
:class:`App` provides useful decorators to register method, topic, input bindings. | ||
""" | ||
|
||
def __init__(self): | ||
self._health_check_cb: Optional[HealthCheckCallable] = None | ||
|
||
def register_health_check(self, cb: HealthCheckCallable) -> None: | ||
if not cb: | ||
raise ValueError('health check callback must be defined') | ||
self._health_check_cb = cb | ||
|
||
def HealthCheck(self, request, context): | ||
"""Health check.""" | ||
|
||
if not self._health_check_cb: | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) # type: ignore | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
self._health_check_cb() | ||
return HealthCheckResponse() |
File renamed without changes.
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,20 @@ | ||
import unittest | ||
from unittest.mock import MagicMock | ||
|
||
from dapr.ext.grpc._health_servicer import _HealthCheckServicer | ||
|
||
|
||
class OnInvokeTests(unittest.TestCase): | ||
def setUp(self): | ||
self._health_servicer = _HealthCheckServicer() | ||
|
||
def test_healthcheck_cb_called(self): | ||
health_cb = MagicMock() | ||
self._health_servicer.register_health_check(health_cb) | ||
self._health_servicer.HealthCheck(None, MagicMock()) | ||
health_cb.assert_called_once() | ||
|
||
def test_no_healthcheck_cb(self): | ||
with self.assertRaises(NotImplementedError) as exception_context: | ||
self._health_servicer.HealthCheck(None, MagicMock()) | ||
self.assertIn('Method not implemented!', exception_context.exception.args[0]) |
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
limitations under the License. | ||
""" | ||
|
||
__version__ = '0.4.0rc1.dev' | ||
__version__ = '0.4.1rc1.dev' |