-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Make Edge API retries configurable #44536
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
Merged
jscheffl
merged 6 commits into
apache:main
from
jscheffl:feature/make-edge-api-calls-configurable
Jan 4, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5047c6b
Make Edge API retries configurable
jscheffl 687cb94
Align implementation with TaskSDK PR #45121
jscheffl 3b236a9
Add pytests and fix retry handling
jscheffl 6ff5407
Fix mypy on pytests
jscheffl 18fbfd0
Update changelog
jscheffl e302bb4
Update changelog
jscheffl 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,88 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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 __future__ import annotations | ||
|
|
||
| from http import HTTPStatus | ||
| from typing import TYPE_CHECKING | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from requests import HTTPError | ||
| from requests.exceptions import ConnectTimeout | ||
| from requests_mock import ANY | ||
|
|
||
| from airflow.providers.edge.cli.api_client import _make_generic_request | ||
|
|
||
| from tests_common.test_utils.config import conf_vars | ||
|
|
||
| if TYPE_CHECKING: | ||
| from requests_mock import Mocker as RequestsMocker | ||
|
|
||
| MOCK_ENDPOINT = "https://invalid-api-test-endpoint" | ||
|
|
||
|
|
||
| class TestApiClient: | ||
| @conf_vars({("edge", "api_url"): MOCK_ENDPOINT}) | ||
| def test_make_generic_request_success(self, requests_mock: RequestsMocker): | ||
| requests_mock.get( | ||
| ANY, | ||
| [ | ||
| {"json": {"test": "ok"}}, | ||
| {"status_code": HTTPStatus.NO_CONTENT}, | ||
| ], | ||
| ) | ||
|
|
||
| result1 = _make_generic_request("GET", f"{MOCK_ENDPOINT}/dummy_service", "test") | ||
| result2 = _make_generic_request("GET", f"{MOCK_ENDPOINT}/service_no_content", "test") | ||
|
|
||
| assert result1 == {"test": "ok"} | ||
| assert result2 is None | ||
| assert requests_mock.call_count == 2 | ||
|
|
||
| @patch("time.sleep", return_value=None) | ||
| @conf_vars({("edge", "api_url"): MOCK_ENDPOINT}) | ||
| def test_make_generic_request_retry(self, mock_sleep, requests_mock: RequestsMocker): | ||
| requests_mock.get( | ||
| ANY, | ||
| [ | ||
| *[{"status_code": HTTPStatus.SERVICE_UNAVAILABLE}] * 3, | ||
| {"exc": ConnectTimeout}, | ||
| {"json": {"test": 42}}, | ||
| ], | ||
| ) | ||
|
|
||
| result = _make_generic_request("GET", f"{MOCK_ENDPOINT}/flaky_service", "test") | ||
|
|
||
| assert result == {"test": 42} | ||
| assert requests_mock.call_count == 5 | ||
|
|
||
| @patch("time.sleep", return_value=None) | ||
| @conf_vars({("edge", "api_url"): MOCK_ENDPOINT}) | ||
| def test_make_generic_request_unrecoverable_error(self, mock_sleep, requests_mock: RequestsMocker): | ||
| requests_mock.get( | ||
| ANY, | ||
| [ | ||
| *[{"status_code": HTTPStatus.INTERNAL_SERVER_ERROR}] * 11, | ||
| {"json": {"test": "uups"}}, | ||
| ], | ||
| ) | ||
|
|
||
| with pytest.raises(HTTPError) as err: | ||
| _make_generic_request("GET", f"{MOCK_ENDPOINT}/broken_service", "test") | ||
|
|
||
| assert err.value.response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR | ||
| assert requests_mock.call_count == 10 |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.