xBis7 opened a new pull request, #69809:
URL: https://github.com/apache/airflow/pull/69809
<!-- SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICENSE-2.0 -->
<!--
Thank you for contributing!
Please provide above a brief description of the changes made in this pull
request.
Write a good git commit message following this guide:
http://chris.beams.io/posts/git-commit/
Please make sure that your code changes are covered with tests.
And in case of new features or big changes remember to adjust the
documentation.
For user-facing UI changes, please attach before/after screenshots (or a
short
screen recording) so reviewers can assess the visual impact.
Feel free to ping (in general) for the review if you do not see reaction for
a few days
(72 Hours is the minimum reaction time you can expect from volunteers) - we
sometimes miss notifications.
In case of an existing issue, reference it using one of the following:
* closes: #ISSUE
* related: #ISSUE
-->
This patch is adding a trace for every iteration of the scheduler loop and
debug spans around all the major steps and queries.
## Context
There is a config option for exporting debug traces.
https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/config_templates/config.yml#L1504-L1513
We used to export random spans for multiple methods of the scheduler but
these spans were never grouped together under a common trace and also didn't
have any meaningful attributes. They were providing little to no benefit while
they were actually adding more noise. Eventually, all such spans were removed
and the config option was deprecated as unused but kept around in case we
wanted to try a different approach in the future.
So far we only have traces for dag_runs but there are some operations across
the project that are worth tracking with spans. The spans could help us
pin-point the root cause of performance issues and come up with appropriate
solutions.
There have been a lot of discussions around scheduler performance, task
starvation, etc. with no solid way of consistently reproducing the issues or
identifying the exact pain points. The spans added in this patch could be a
good 1st step towards improving the scheduler.
In the future, we could also add debug spans for the dag_processor or the
triggerer or operations in the task-sdk.
## Current changes + examples
I've added a new function with a `start_as_current_span` call guarded by the
debug traces flag so that we can enable and disable the new traces (disabled by
default).
The parent span for each iteration always starts as a root span and it has
an attribute `airflow.scheduler.loop_iteration.idle` which can help us
distinguish the iterations that actually did some work. We can use it to filter
the spans and find the interesting ones.
<img width="1070" height="1484" alt="image"
src="https://github.com/user-attachments/assets/2ba2a9aa-06ea-4d77-bd35-da312d85e3ee"
/>
Then we can sort by the longest first and start examining them
<img width="4080" height="2330" alt="image"
src="https://github.com/user-attachments/assets/7417e597-de48-48a5-9446-671eb78e97ad"
/>
Not all iteration traces look the same. In the above example, this is the
longest
<img width="4094" height="2268" alt="image"
src="https://github.com/user-attachments/assets/46441e46-2278-49c2-8b68-e29b6b2ca10f"
/>
<img width="4078" height="2332" alt="image"
src="https://github.com/user-attachments/assets/ae7c5a63-1879-419d-b869-c22d21c82bfa"
/>
2nd longest
<img width="4086" height="2324" alt="image"
src="https://github.com/user-attachments/assets/7a017de5-3844-427e-a533-57bce2299273"
/>
<img width="4072" height="2338" alt="image"
src="https://github.com/user-attachments/assets/e7836d20-36c0-4db4-baa5-2820f2bbe026"
/>
3rd longest
<img width="4082" height="2342" alt="image"
src="https://github.com/user-attachments/assets/8a4568f2-bf24-4ad1-9e82-62fbd6031824"
/>
<img width="4082" height="2342" alt="image"
src="https://github.com/user-attachments/assets/e46f57ad-a8d4-4c9d-86d6-eb206bca4171"
/>
And we are also exposing various internal values. I've only added attributes
that are available at the moment of the span and avoided doing any calculations
that will add more load to the system.
<img width="4042" height="2268" alt="image"
src="https://github.com/user-attachments/assets/aa2746da-5f6f-4b6f-aa68-ffd2028af577"
/>
<img width="4068" height="2322" alt="image"
src="https://github.com/user-attachments/assets/b4a3d951-a89c-4367-92a9-78bcfd435bb5"
/>
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR,
please
change below checkbox to `[X]` followed by the name of the tool, uncomment
the "Generated-by".
-->
- [X] Yes (please specify the tool below)
Claude-code Opus 4.8
<!--
Generated-by: [Tool Name] following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information. Note: commit author/co-author name and email in commits
become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]