dapr / python-sdk

Dapr SDK for Python
Apache License 2.0
221 stars 125 forks source link

Allow adding health check callback to Dapr App run in gRPC #723

Closed evhen14 closed 2 months ago

evhen14 commented 2 months ago

Description

Add health check support to the SDK for gRPC following the example of the go-sdk. The dapr docs state that the /dapr.proto.runtime.v1.AppCallbackHealthCheck/HealthCheck endpoint is called, but this SDK doesn't support specifying that method implementation.

The suggested way to use it would be app.register_health_check(health_check_func)

Use case 1: gRPC endpoints depend on other components to function properly. The health checks callback can be used to validate the liveness of the other components

Use case 2: Run gRPC app next to a web app in the same container in a separate thread. The entire app is healthy only when both dapr app and web app are healthy. I expect that dapr thread could die or stop being responsive, hence the way to add health checks.

Issue reference

It's the outcome of the issue #722 I raised earlier where I see a gap for adding meaningful health checks

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

berndverst commented 2 months ago

Please run tox -e ruff for our autoformatter of source files.

yevgen-el8 commented 2 months ago

@berndverst tox -e ruff was applied. Thx for your feedback!

berndverst commented 2 months ago
ext/dapr-ext-grpc/dapr/ext/grpc/_health_servicer.py:17: error: Function "cb" could always be true in boolean context  [truthy-function]
ext/dapr-ext-grpc/dapr/ext/grpc/_health_servicer.py:22: error: Attribute "_health_check_cb" already defined on line 19  [no-redef]
ext/dapr-ext-grpc/dapr/ext/grpc/_health_servicer.py:22: error: Incompatible types in assignment (expression has type "None", variable has type "Callable[[], None]")  [assignment]
codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 97.26027% with 2 lines in your changes missing coverage. Please review.

Project coverage is 86.22%. Comparing base (fc0e9d1) to head (eed11ed). Report is 25 commits behind head on main.

Files Patch % Lines
...xt/dapr-ext-grpc/dapr/ext/grpc/_health_servicer.py 94.73% 1 Missing :warning:
ext/dapr-ext-grpc/tests/test_app.py 88.88% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #723 +/- ## ========================================== - Coverage 86.37% 86.22% -0.15% ========================================== Files 79 79 Lines 4094 4166 +72 ========================================== + Hits 3536 3592 +56 - Misses 558 574 +16 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

marcduiker commented 1 week ago

@holopin-bot @evhen14 Thank you!

holopin-bot[bot] commented 1 week ago

Congratulations @evhen14, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/clzvb5nb524130djsaga7l99m

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!