Rework the TriggererJobRunner to run triggers in a process without DB access#46677
Merged
Conversation
Member
Author
|
I need to re-examing logs to make sure they still get routed to the right place, and fix all the tests |
62817ba to
3affa2d
Compare
dstandish
reviewed
Feb 12, 2025
dstandish
reviewed
Feb 12, 2025
ashb
commented
Feb 12, 2025
ashb
commented
Feb 12, 2025
dstandish
reviewed
Feb 12, 2025
ashb
commented
Feb 14, 2025
ashb
commented
Feb 14, 2025
c4e86ea to
ed561f2
Compare
b8aabbe to
eeeb809
Compare
amoghrajesh
reviewed
Feb 17, 2025
amoghrajesh
left a comment
Contributor
There was a problem hiding this comment.
Looks good overall, just few comments/qns
eeeb809 to
9c7a0dc
Compare
amoghrajesh
approved these changes
Feb 17, 2025
amoghrajesh
left a comment
Contributor
There was a problem hiding this comment.
Thanks for addressing my comments, LGTM +1.
Lets get this one in, we might discover issues while testing and we can fix those as they come.
vincbeck
approved these changes
Feb 17, 2025
vincbeck
left a comment
Contributor
There was a problem hiding this comment.
Looks good! Massive refactoring on the triggerer side! I'd wait for more reviews given the size of the PR but I could not find anything outstanding :)
jedcunningham
approved these changes
Feb 17, 2025
f2c5e03 to
e7bf549
Compare
… access This uses a similar approach to the DAG Parser -- the subprocess runs the async Triggers (i.e. user code) in a process and sends messages back and forth to the supervisor/parent to perform CRUD operations on the DB. I have also massively re-worked how per-trigger logging works to greatly simplify it. I hope @dstandish will approve. The main way it has been simplified is with the switch to TaskSDK then all (100%! Really) of logs are set as JSON over a socket to the parent process; everything in the subprocess logs to this output, there is no differentiation needed in stdlib, no custom handlers etc. and by making use of structlog's automatic context vars we can include a trigger_id field -- if we find that we route the output to the right trigger specific log file. This is all now so much simpler with structlog in the mix. Logging from the async process works as follows: - stdlib logging is configured to send messages via struct log as json - As part of the stdlib->structlog processing change we include structlog bound contextvars - When a triggerer coro starts it binds trigger_id as a paramter - When the Supervisor receives a log message (which happens as LD JSON over a dedicated socket channel) it parses the JSON, and if it finds trigger_id key in there it redirects it to the trigger file log, else prints it.
e7bf549 to
d1ee9ca
Compare
ntr
pushed a commit
to ntr/airflow
that referenced
this pull request
Feb 20, 2025
… access (apache#46677) This uses a similar approach to the DAG Parser -- the subprocess runs the async Triggers (i.e. user code) in a process and sends messages back and forth to the supervisor/parent to perform CRUD operations on the DB. I have also massively re-worked how per-trigger logging works to greatly simplify it. I hope @dstandish will approve. The main way it has been simplified is with the switch to TaskSDK then _all_ (100%! Really) of logs are set as JSON over a socket to the parent process; everything in the subprocess logs to this output, there is no differentiation needed in stdlib, no custom handlers etc. and by making use of structlog's automatic context vars we can include a trigger_id field -- if we find that we route the output to the right trigger specific log file. This is all now so much simpler with structlog in the mix. Logging from the async process works as follows: - stdlib logging is configured to send messages via struct log as json - As part of the stdlib->structlog processing change we include structlog bound contextvars - When a triggerer coro starts it binds `trigger_id` as a paramter - When the Supervisor receives a log message (which happens as LD JSON over a dedicated socket channel) it parses the JSON, and if it finds `trigger_id` key in there it redirects it to the trigger file log, else prints it. Of note: I haven't allowed triggers to directly access or set Xcom, Variables etc. We can add that in future if there is demand.
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 uses a similar approach to the DAG Parser -- the subprocess runs the
async Triggers (i.e. user code) in a process and sends messages back and forth
to the supervisor/parent to perform CRUD operations on the DB.
I have also massively re-worked how per-trigger logging works to greatly simplify it. I hope @dstandish will approve.
The main way it has been simplified is with the switch to TaskSDK then all (100%! Really) of logs are set as JSON over a socket to the parent process; everything in the subprocess logs to this output, there is no differentiation needed in stdlib, no custom handlers etc. and by making use of structlog's automatic context vars we can include a trigger_id field -- if we find that we route the output to the right trigger specific log file.
This is all now so much simpler with structlog in the mix.
Logging from the async process works as follows:
trigger_idas a paramtertrigger_idkey in there it redirects it to the trigger file log, else prints it.Of note: I haven't allowed triggers to directly access or set Xcom, Variables etc. We can add that in future if there is demand.
Testing:
I created a simple test dag:
And fired things up in
breeze start-airflowAnd we can see that the trigger runs and we get logs from the triggerer in the output (The ordering of logs isn't correct, but that is a separate issue)
^ 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 newsfragments.