-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixes http endpoint being overwritten by gRPC address argument in constructor (#621) * Fixes bug of constructor argument being used as http endpoint Signed-off-by: Elena Kolevska <elena@kolevska.com> * Updates tests Signed-off-by: Elena Kolevska <elena@kolevska.com> * Updates the docs explaining how http service invocation should be configured Signed-off-by: Elena Kolevska <elena@kolevska.com> * Update daprdocs/content/en/python-sdk-docs/python-client.md Signed-off-by: Bernd Verst <github@bernd.dev> --------- Signed-off-by: Elena Kolevska <elena@kolevska.com> Signed-off-by: Bernd Verst <github@bernd.dev> Co-authored-by: Bernd Verst <github@bernd.dev> Signed-off-by: Elena Kolevska <elena@kolevska.com> # Conflicts: # dapr/clients/__init__.py # dapr/clients/http/client.py # dapr/clients/http/dapr_invocation_http_client.py # tests/clients/test_http_service_invocation_client.py # tests/clients/test_secure_http_service_invocation_client.py * health decorator - first commit Signed-off-by: Elena Kolevska <elena@kolevska.com> * Fixes tests Signed-off-by: Elena Kolevska <elena@kolevska.com> * Removes unused imports Signed-off-by: Elena Kolevska <elena@kolevska.com> * Ruff format Signed-off-by: Elena Kolevska <elena@kolevska.com> * Adds unit test Signed-off-by: Elena Kolevska <elena@kolevska.com> * Repalces wait() with @healthcheck decorator in examples Signed-off-by: Elena Kolevska <elena@kolevska.com> * Ruff Signed-off-by: Elena Kolevska <elena@kolevska.com> * Linter Signed-off-by: Elena Kolevska <elena@kolevska.com> * updates heathcheck decorator to use a global var Signed-off-by: Elena Kolevska <elena@kolevska.com> * Fixes tests Signed-off-by: Elena Kolevska <elena@kolevska.com> * Linter fixes Signed-off-by: Elena Kolevska <elena@kolevska.com> * Removes healthcheck from examples Signed-off-by: Elena Kolevska <elena@kolevska.com> * Ruff Signed-off-by: Elena Kolevska <elena@kolevska.com> * wip Signed-off-by: Elena Kolevska <elena@kolevska.com> * wip Signed-off-by: Elena Kolevska <elena@kolevska.com> * wip Signed-off-by: Elena Kolevska <elena@kolevska.com> * wip Signed-off-by: Elena Kolevska <elena@kolevska.com> * Set health timeout to 60 seconds Signed-off-by: Elena Kolevska <elena@kolevska.com> * wip Signed-off-by: Elena Kolevska <elena@kolevska.com> * Unit tests passing Signed-off-by: Elena Kolevska <elena@kolevska.com> * Linter Signed-off-by: Elena Kolevska <elena@kolevska.com> * Refactor and cleanup Signed-off-by: Elena Kolevska <elena@kolevska.com> * Refactors client tests for speed and readability Signed-off-by: Elena Kolevska <elena@kolevska.com> * Small fix Signed-off-by: Elena Kolevska <elena@kolevska.com> * Add tests performance improvement for actor tests too Signed-off-by: Elena Kolevska <elena@kolevska.com> * Cosmetic touch up Signed-off-by: Elena Kolevska <elena@kolevska.com> * Documents the `DAPR_HEALTH_TIMEOUT` environment variable Signed-off-by: Elena Kolevska <elena@kolevska.com> * make healthcheck a static method Signed-off-by: Elena Kolevska <elena@kolevska.com> --------- Signed-off-by: Elena Kolevska <elena@kolevska.com>
- Loading branch information
1 parent
23fc4b1
commit f4dc8ce
Showing
34 changed files
with
574 additions
and
340 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
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.