Add optional debug spans for the scheduler loop#69809
Open
xBis7 wants to merge 1 commit into
Open
Conversation
4d0a7e0 to
8a90ffb
Compare
8a90ffb to
ec98125
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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_spancall 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.idlewhich can help us distinguish the iterations that actually did some work. We can use it to filter the spans and find the interesting ones.Then we can sort by the longest first and start examining them
Not all iteration traces look the same. In the above example, this is the longest
2nd longest
3rd longest
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.
Testing
Apart from manual testing, I've added unit tests for the new
start_debug_spanfunction and an integration test that checks for certain spans that we can expect to consistently appear in every iteration.Was generative AI tooling used to co-author this PR?
Claude-code Opus 4.8
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.