-
Notifications
You must be signed in to change notification settings - Fork 129
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
Health check #670
Merged
Merged
Health check #670
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
11e372c
Fixes http endpoint being overwritten by gRPC address argument in con…
elena-kolevska a1275e2
health decorator - first commit
elena-kolevska 7ff3921
Fixes tests
elena-kolevska 15a0b1a
Removes unused imports
elena-kolevska d51f97b
Ruff format
elena-kolevska 3f6940b
Adds unit test
elena-kolevska 2629231
Repalces wait() with @healthcheck decorator in examples
elena-kolevska 8bcec71
Ruff
elena-kolevska 3a208a2
Linter
elena-kolevska 5bd279c
updates heathcheck decorator to use a global var
elena-kolevska b12beba
Fixes tests
elena-kolevska b8eb9de
Merge remote-tracking branch 'upstream/main' into health-decorator
elena-kolevska d39652d
Linter fixes
elena-kolevska d9a6e52
Removes healthcheck from examples
elena-kolevska b21df04
Ruff
elena-kolevska 495f78b
wip
elena-kolevska afdda30
wip
elena-kolevska 71686af
Merge remote-tracking branch 'upstream/main' into health-decorator
elena-kolevska 9624795
wip
elena-kolevska 476e856
wip
elena-kolevska 70f948f
Set health timeout to 60 seconds
elena-kolevska 47b9431
wip
elena-kolevska 169db4b
Unit tests passing
elena-kolevska ae56663
Linter
elena-kolevska 60001ea
Refactor and cleanup
elena-kolevska 3ac1106
Refactors client tests for speed and readability
elena-kolevska 2aa2f32
Small fix
elena-kolevska 7517cf7
Add tests performance improvement for actor tests too
elena-kolevska 94b23a0
Cosmetic touch up
elena-kolevska 2a2f3bd
Documents the `DAPR_HEALTH_TIMEOUT` environment variable
elena-kolevska 1e7f332
make healthcheck a static method
elena-kolevska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Copyright 2024 The Dapr Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
import urllib.request | ||
import urllib.error | ||
import time | ||
|
||
from dapr.clients.http.conf import DAPR_API_TOKEN_HEADER, USER_AGENT_HEADER, DAPR_USER_AGENT | ||
from dapr.clients.http.helpers import get_api_url | ||
from dapr.conf import settings | ||
|
||
|
||
class DaprHealth: | ||
@staticmethod | ||
def wait_until_ready(): | ||
health_url = f'{get_api_url()}/healthz/outbound' | ||
headers = {USER_AGENT_HEADER: DAPR_USER_AGENT} | ||
if settings.DAPR_API_TOKEN is not None: | ||
headers[DAPR_API_TOKEN_HEADER] = settings.DAPR_API_TOKEN | ||
timeout = settings.DAPR_HEALTH_TIMEOUT | ||
|
||
start = time.time() | ||
while True: | ||
try: | ||
req = urllib.request.Request(health_url, headers=headers) | ||
with urllib.request.urlopen(req, context=DaprHealth.get_ssl_context()) as response: | ||
if 200 <= response.status < 300: | ||
break | ||
except urllib.error.URLError as e: | ||
print(f'Health check on {health_url} failed: {e.reason}') | ||
except Exception as e: | ||
print(f'Unexpected error during health check: {e}') | ||
|
||
remaining = (start + timeout) - time.time() | ||
if remaining <= 0: | ||
raise TimeoutError(f'Dapr health check timed out, after {timeout}.') | ||
time.sleep(min(1, remaining)) | ||
|
||
@staticmethod | ||
def get_ssl_context(): | ||
# This method is used (overwritten) from tests | ||
# to return context for self-signed certificates | ||
return None | ||
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Copyright 2023 The Dapr Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from dapr.version import __version__ | ||
|
||
CONTENT_TYPE_HEADER = 'content-type' | ||
DAPR_API_TOKEN_HEADER = 'dapr-api-token' | ||
USER_AGENT_HEADER = 'User-Agent' | ||
DAPR_USER_AGENT = f'dapr-sdk-python/{__version__}' |
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,25 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Copyright 2023 The Dapr Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from dapr.conf import settings | ||
|
||
|
||
def get_api_url() -> str: | ||
if settings.DAPR_HTTP_ENDPOINT: | ||
return '{}/{}'.format(settings.DAPR_HTTP_ENDPOINT, settings.DAPR_API_VERSION) | ||
|
||
return 'http://{}:{}/{}'.format( | ||
settings.DAPR_RUNTIME_HOST, settings.DAPR_HTTP_PORT, settings.DAPR_API_VERSION | ||
) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this to the instance creation because it was getting invoked on import(dependency load), which was triggering the healthcheck before the fake test servers would start.