Fix task-level audit logs missing success/running events in Airflow 3.1.x#61932
Open
sjyangkevin wants to merge 1 commit intoapache:mainfrom
Open
Fix task-level audit logs missing success/running events in Airflow 3.1.x#61932sjyangkevin wants to merge 1 commit intoapache:mainfrom
sjyangkevin wants to merge 1 commit intoapache:mainfrom
Conversation
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.
closes: #58381
Issue
In Airflow 2, task instance state transition such as
RUNNING,SUCCESS,SKIPPED,FAILEDwere logged into thelogtable through theTaskInstancemodel methods. In Airflow 3, the task state update/management is moved to the execution API endpointsti_runandti_update_state. However, the endpoints were not wired up to createlogrecords, resulting in missing audit logs for task instance state transitions.Fix
Added
session.add(Log(...))calls to bothti_runandti_update_statewhen the task instance state is updated. The call will be executed in the same transaction as the state update in both endpoints.In
ti_run, the audit log is placed inside theelsebranch such that duplicated requests, or conflict request, due to network glitch, will not be logged.In
ti_update_state, theTIselect query is updated to fetchtask_id,run_id, andmap_index.Caveat
The following fields in the
logtable are missing. Require extra query/join to fetch the following information.logical_date(previouslyexecution_date)owner(the value isairflowin Airflow 2)owner_display_name(this field is also empty for task state transition)extra(full_commandwill not be available as it is not run/update through CLI;hostnameis not available inti_update_state)EmptyOperator or operators skipped by branch doesn't have audit log
DAG Test Samples
Was generative AI tooling used to co-author this PR?
Generated-by: [Antigravity] following the guidelines
The tool is used to analyze the existing test cases to understand the expected behavior of both
ti_runandti_update_state. It is also used to generate new test cases.{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.