-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Deliver the per-run log ID template to workers via TIRunContext #69688
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
Open
jason810496
wants to merge
5
commits into
apache:main
Choose a base branch
from
jason810496:fix/logging/es-os-respect-log-template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2273d89
Make ES and OpenSearch log handlers respect the per-run log ID template
jason810496 cda3515
Avoid metadata DB access when resolving the log id template for worke…
jason810496 e9ac1ad
Restore the parent package attribute after forced module re-imports i…
jason810496 e43e13d
Move Elasticsearch and OpenSearch handler changes to stacked PRs
jason810496 3bd7711
Add a test asserting log_id_template always reflects the newest LogTe…
jason810496 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
40 changes: 40 additions & 0 deletions
40
airflow-core/src/airflow/api_fastapi/execution_api/versions/v2026_09_30.py
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,40 @@ | ||
| # 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 cadwyn import ( | ||
| ResponseInfo, | ||
| VersionChange, | ||
| convert_response_to_previous_version_for, | ||
| schema, | ||
| ) | ||
|
|
||
| from airflow.api_fastapi.execution_api.datamodels.taskinstance import TIRunContext | ||
|
|
||
|
|
||
| class AddLogIdTemplateField(VersionChange): | ||
| """Add the Dag-run-pinned `log_id_template` field to TIRunContext.""" | ||
|
|
||
| description = __doc__ | ||
|
|
||
| instructions_to_migrate_to_previous_version = (schema(TIRunContext).field("log_id_template").didnt_exist,) | ||
|
|
||
| @convert_response_to_previous_version_for(TIRunContext) # type: ignore[arg-type] | ||
| def remove_log_id_template_field(response: ResponseInfo) -> None: # type: ignore[misc] | ||
| """Remove log_id_template field for older API versions.""" | ||
| response.body.pop("log_id_template", None) |
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
16 changes: 16 additions & 0 deletions
16
airflow-core/tests/unit/api_fastapi/execution_api/versions/v2026_09_30/__init__.py
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,16 @@ | ||
| # 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. |
85 changes: 85 additions & 0 deletions
85
...low-core/tests/unit/api_fastapi/execution_api/versions/v2026_09_30/test_task_instances.py
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,85 @@ | ||
| # 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 | ||
|
|
||
| import pytest | ||
|
|
||
| from airflow._shared.timezones import timezone | ||
| from airflow.utils.state import DagRunState, State | ||
|
|
||
| from tests_common.test_utils.db import clear_db_runs | ||
|
|
||
| pytestmark = pytest.mark.db_test | ||
|
|
||
| TIMESTAMP_STR = "2024-09-30T12:00:00Z" | ||
| TIMESTAMP = timezone.parse(TIMESTAMP_STR) | ||
|
|
||
| RUN_PATCH_BODY = { | ||
| "state": "running", | ||
| "hostname": "h", | ||
| "unixname": "u", | ||
| "pid": 1, | ||
| "start_date": TIMESTAMP_STR, | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def old_ver_client(client): | ||
| """Execution API version immediately before ``log_id_template`` was added.""" | ||
| client.headers["Airflow-API-Version"] = "2026-06-30" | ||
| return client | ||
|
|
||
|
|
||
| class TestLogIdTemplateFieldBackwardCompat: | ||
| @pytest.fixture(autouse=True) | ||
| def _freeze_time(self, time_machine): | ||
| time_machine.move_to(TIMESTAMP_STR, tick=False) | ||
|
|
||
| def setup_method(self): | ||
| clear_db_runs() | ||
|
|
||
| def teardown_method(self): | ||
| clear_db_runs() | ||
|
|
||
| def test_old_version_strips_log_id_template(self, old_ver_client, session, create_task_instance): | ||
| ti = create_task_instance( | ||
| task_id="test_log_id_template_downgrade", | ||
| state=State.QUEUED, | ||
| dagrun_state=DagRunState.RUNNING, | ||
| session=session, | ||
| start_date=TIMESTAMP, | ||
| ) | ||
| session.commit() | ||
|
|
||
| response = old_ver_client.patch(f"/execution/task-instances/{ti.id}/run", json=RUN_PATCH_BODY) | ||
| assert response.status_code == 200 | ||
| assert "log_id_template" not in response.json() | ||
|
|
||
| def test_head_version_includes_log_id_template(self, client, session, create_task_instance): | ||
| ti = create_task_instance( | ||
| task_id="test_log_id_template_head", | ||
| state=State.QUEUED, | ||
| dagrun_state=DagRunState.RUNNING, | ||
| session=session, | ||
| start_date=TIMESTAMP, | ||
| ) | ||
| session.commit() | ||
|
|
||
| response = client.patch(f"/execution/task-instances/{ti.id}/run", json=RUN_PATCH_BODY) | ||
| assert response.status_code == 200 | ||
| assert response.json()["log_id_template"] == "{dag_id}-{task_id}-{run_id}-{map_index}-{try_number}" |
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
30 changes: 30 additions & 0 deletions
30
task-sdk/src/airflow/sdk/execution_time/schema/versions/v2026_09_30.py
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,30 @@ | ||
| # 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 cadwyn import VersionChange, schema | ||
|
|
||
| from airflow.sdk.api.datamodels._generated import TIRunContext | ||
|
|
||
|
|
||
| class AddLogIdTemplateField(VersionChange): | ||
| """Add the Dag-run-pinned `log_id_template` field to TIRunContext (nested in StartupDetails).""" | ||
|
|
||
| description = __doc__ | ||
|
|
||
| instructions_to_migrate_to_previous_version = (schema(TIRunContext).field("log_id_template").didnt_exist,) |
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.
Uh oh!
There was an error while loading. Please reload this page.