Skip to content
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

Add HTTP retry handling into task SDK api.client #45121

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jscheffl
Copy link
Contributor

closes: #44355

Add HTTP retry handling to Task SDK.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

task_sdk/tests/api/test_client.py:101

  • There is an extra single quote in the mounts dictionary key. It should be mounts={'http://': httpx.MockTransport(mock_handle_request)}.
mounts={'http://': httpx.MockTransport(mock_handle_request)},
@jscheffl jscheffl requested a review from amoghrajesh December 20, 2024 20:11
@jscheffl jscheffl force-pushed the feature/44355-add-retry-handling-into-task-sdk-api-client branch from bc58ae6 to 5399ace Compare December 21, 2024 14:01
Copy link
Contributor

@shubhamraj-git shubhamraj-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, some optimisations.

task_sdk/src/airflow/sdk/api/client.py Show resolved Hide resolved
task_sdk/tests/api/test_client.py Show resolved Hide resolved
@jscheffl jscheffl force-pushed the feature/44355-add-retry-handling-into-task-sdk-api-client branch from 5399ace to 23614f0 Compare December 22, 2024 21:29
Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, thanks Jens.
Few comments

task_sdk/src/airflow/sdk/api/client.py Outdated Show resolved Hide resolved
Comment on lines 273 to 275
API_RETRIES = int(os.getenv("AIRFLOW__WORKERS__API_RETRIES", 10))
API_RETRY_WAIT_MIN = int(os.getenv("AIRFLOW__WORKERS__API_RETRY_WAIT_MIN", 1))
API_RETRY_WAIT_MAX = int(os.getenv("AIRFLOW__WORKERS__API_RETRY_WAIT_MAX", 90))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also briefly document this? I think these are new env variables right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a proposal where to document? At the moment there is no config facility for Task SDK and also no section. Yes, the ENVs are new, ususally they are derived from airflow/config_templates/config.yml but for task SDK we explicitly don't want to force all backend config to be present in task SDK. Therefore the config mechanism was not used.

I just introduced these ENVs to have an option to configure and prevent hard-coding the retry values. More details are to be elaborated in #44352

task_sdk/src/airflow/sdk/api/client.py Show resolved Hide resolved
response = client.get("http://error")
assert response.status_code == 200
assert len(responses) == 1
assert mock_sleep.call_count == 0


class TestTaskInstanceOperations:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we replace the client initialisation in all the other test classes to use make_client_w_responses instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly thought about it but if you take a look how the other tests are mocking the backend ... there are conditions and asserts in request handling implemented. So the other mock has a different test level. So I decided to move both close together but they have a different implementation demand.

@jscheffl jscheffl force-pushed the feature/44355-add-retry-handling-into-task-sdk-api-client branch from 23614f0 to aaabd09 Compare December 23, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add HTTP retry handling into task sdk's api.client
3 participants