Skip to content

Restore queued_duration metric in Airflow 3#67668

Open
wilmerdooley wants to merge 2 commits into
apache:mainfrom
wilmerdooley:fix-63503-queued-duration-metric
Open

Restore queued_duration metric in Airflow 3#67668
wilmerdooley wants to merge 2 commits into
apache:mainfrom
wilmerdooley:fix-63503-queued-duration-metric

Conversation

@wilmerdooley
Copy link
Copy Markdown

The dag.<dag_id>.<task_id>.queued_duration timer stopped being emitted after the Airflow 3 upgrade (#63503).

In Airflow 2 it was sent from TaskInstance.emit_state_change_metric when the task moved to RUNNING. In Airflow 3 that transition happens in the execution API ti_run handler rather than in the ORM, so the emit no longer fired. Its sibling scheduled_duration still works because it is emitted server side from the scheduler on the QUEUED transition.

This change emits task.queued_duration from ti_run on the QUEUED to RUNNING transition. The metric template already maps task.queued_duration to the legacy dag.<dag_id>.<task_id>.queued_duration name, so both the tagged and statsd forms are restored. It is guarded on queued_dttm being set and emitted only on the first try (no prior end_date), matching the Airflow 2 behavior.

Unit tests cover the emit, the no-op when queued_dttm is missing, the first-try-only guard, and that a duplicate run request does not double-emit.

closes: #63503


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code following the guidelines

The dag.<dag_id>.<task_id>.queued_duration timer stopped being emitted in Airflow 3. In Airflow 2 it was sent from TaskInstance.emit_state_change_metric when the task moved to RUNNING, but in Airflow 3 that transition happens in the execution API ti_run handler rather than in the ORM, so the emit no longer fired. Its sibling scheduled_duration still works because it is emitted server side from the scheduler.

Emit task.queued_duration from ti_run on the QUEUED to RUNNING transition (the metric template maps it to the legacy dag.<dag_id>.<task_id>.queued_duration name), guarded on queued_dttm being set and only on the first try (no prior end_date), matching the Airflow 2 behavior.

Closes apache#63503
@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:task-sdk labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:task-sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metric dag.dag_id.task_id.queued_duration missing

1 participant