-
Notifications
You must be signed in to change notification settings - Fork 16.4k
add static checker for preventing to increase dag version #59430
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 static checker for preventing to increase dag version #59430
Conversation
3f63ac2 to
17e4dab
Compare
potiuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic !
|
I'd love some other pair of eyes on it, but I think this is a great start for good approach to solve the problem with varying Dags. I think we need to think a bit more on next steps and explore different kinds of UX for that, also I think such mechanism should have a way to suppress such warnings (for example by comment in the Dag) - but other than that - it looks great. |
Lee-W
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, look into too detail. Adding example for the things we want to check like https://github.com/astral-sh/ruff/blob/b0bc990cbf2a0a75ced52de0d6ba3d51d35072ee/crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs#L28-L42 would be helpful. Will take a deeper look at a later point
ephraimbuddy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. However, I think we should have an opt-out solution for those that doesn't mind the dag being non deterministic.
Also, considering that this is in the parsing hot path, we need to test this manually with large dags and various other combinations of files to ensure there's no degradation in parsing time
Yep, totally agree with this |
I agree that too. I think there are two options
WDYT? |
100%
I think (despite Airflow having too many configuration parameters already) there should be few ways:
|
474dea5 to
a94f3bc
Compare
You can turn off using versioned bundles (what code is used for a task), but you cannot turn of dag versioning (keeping history of what the dag looked like). |
Yeah - but ....it does not result in creating a new version entry - it will just continuously override SerializedDags yeah? So generally that's something that we've been also doing in Airflow 2 and it never created huge issue (except a bit more often DB update for those ? This is what I wanted to express in this comment:
But maybe I am wrong and in such case we also create multiple versions in the DB ? Have not looked there in that detail? |
9d85035 to
f34c5fd
Compare
|
@Lee-W |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have this merged. 🎉
Can you mark as 'resolved' conversations you have addressed so we know if work remains or where more input is needed from reviewer.
Also CI need fixing.
6a13dbe to
539157d
Compare
|
@pierrejeambrun done! thanks! |
choo121600
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Looks good to me 👍
potiuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. But @wjddn279 -> can you please look at the open comments (as @pierrejeambrun explained) and resolve those comments that you addressed?
|
@potiuk @pierrejeambrun |
|
#protm |
|
@sjyangkevin I think we can do something similar on the ruff end side as well. Let's create a AIR304 maybe? |
I think it is a good idea. Having this check in ruff can potentially help identify/get the warning early. We could have this AIR304 for suggesting fix for the issue, or probably also use it to suggest DAG writing practices. |
* add static checker for preventing to increase dag version * fix test * fix for test * fix logic * fix test * add config and fix logics * fix module static checker -> dag stability checker * fix config description * fix logics * fix logics * fix logics * fix logics
* add static checker for preventing to increase dag version * fix test * fix for test * fix logic * fix test * add config and fix logics * fix module static checker -> dag stability checker * fix config description * fix logics * fix logics * fix logics * fix logics
* add static checker for preventing to increase dag version * fix test * fix for test * fix logic * fix test * add config and fix logics * fix module static checker -> dag stability checker * fix config description * fix logics * fix logics * fix logics * fix logics
* add static checker for preventing to increase dag version * fix test * fix for test * fix logic * fix test * add config and fix logics * fix module static checker -> dag stability checker * fix config description * fix logics * fix logics * fix logics * fix logics
Motivation
We observed that when runtime-varying values are used as arguments in DAG or Task constructors in Airflow, the DAG version increases infinitely. slack #55768 (comment)
Checking for DAG version increments at runtime is difficult. The most accurate detection method would be to parse the DAG object twice and compare if values differ. However, this would nearly double the DAG parsing execution time.
Therefore, I add a feature that exposes DAG warnings for these cases through AST-based static analysis before parsing in the dag-processor. While it cannot cover 100% of DAG usage patterns, it can cover most cases and has minimal performance impact (since
ast.parsealready runs on every DAG parse).Logic of static check
The logic for detecting problematic situations through static check is as follows (I named this issue "runtime-varying"):
Statically analyze a single DAG file through
ast.parse.Traverse each node and check the following:
The cases covered by static checks are described in detail in the unit test code.
User Notification for Static Check Errors
I considered that static check failures are not severe enough to cause DAG parsing to fail, so I added them to DAG warnings. Warnings are added to DAGs generated from the DAG file and displayed in the UI as shown below. There seems to be an issue where
\ncharacters in messages are ignored when displayed in the UI, which we plan to fix in a future PR.future work
If this PR is merged, the following items are planned for future work:
ast.parsewith theast.parseexecuted in this subprocess.^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.