Skip to content

Add run_type tag to dagrun.duration.failed timeout metric - #67765

Merged
potiuk merged 1 commit into
apache:mainfrom
Vamsi-klu:fix/64765-dagrun-duration-failed-run-type-tag
Jul 30, 2026
Merged

Add run_type tag to dagrun.duration.failed timeout metric#67765
potiuk merged 1 commit into
apache:mainfrom
Vamsi-klu:fix/64765-dagrun-duration-failed-run-type-tag

Conversation

@Vamsi-klu

@Vamsi-klu Vamsi-klu commented May 30, 2026

Copy link
Copy Markdown
Contributor

What / impact

When a Dag run timed out, the scheduler emitted the dagrun.duration.failed timing metric with only a dag_id tag. Every other dagrun.duration.* emission also carries run_type, so dashboards and alerts that segment by run_type silently dropped timed-out runs (or saw an inconsistent tag set). After this change the timeout path emits both dag_id and run_type, consistent with normal completion.

Why

The timeout branch in _schedule_dag_run hardcoded tags={"dag_id": dag_run.dag_id}, while the canonical emitter DagRun._emit_duration_stats_for_finished_state uses dag_run.stats_tags (which includes run_type). This replaces the hardcoded dict with dag_run.stats_tags. run_type is NOT NULL and low-cardinality, so the new tag set is a safe strict superset of the old one and the metric name is unchanged.

How it unblocks

Makes timeout-duration metrics consistent and usable in run_type-segmented observability. Supersedes #64768, which stalled on CI/static checks rather than design — this keeps the diff to a single value change and ships green static checks, including the metrics-registry sync check that blocked the prior attempt.

Tests

One new regression test in test_scheduler_job.py, verified to fail on the unfixed code, asserting the dagrun.duration.failed timing call carries tags={"dag_id": …, "run_type": …}. Full scheduler suite passes; mypy + pre-commit + manual static checks (incl. metrics-registry sync) are green.

closes: #64765


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.8)

Generated-by: Claude Code (Opus 4.8) following the guidelines


Important

🛠️ Maintainer triage note for @Vamsi-klu · by @potiuk · 2026-07-02 17:46 UTC

Helpful heads-up from the maintainers — please address before this PR can be reviewed (see the Pull Request quality criteria):

  • This PR has merge conflicts with main. Please rebase onto the latest main and resolve them.

The ball is in your court — you've been assigned to this PR. Fix the above, then mark it Ready for review.

Automated triage — may be imperfect; a maintainer takes the next look.

@boring-cyborg boring-cyborg Bot added the area:Scheduler including HA (high availability) scheduler label May 30, 2026
@Vamsi-klu
Vamsi-klu force-pushed the fix/64765-dagrun-duration-failed-run-type-tag branch from 0b1b2d3 to 035b401 Compare May 30, 2026 04:20
@Vamsi-klu
Vamsi-klu marked this pull request as ready for review May 30, 2026 04:22
@Vamsi-klu
Vamsi-klu requested review from XD-DENG and ashb as code owners May 30, 2026 04:22
@Vamsi-klu

Vamsi-klu commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping when you have bandwidth, @potiuk 🙏

One-line metrics fix for #64765: the Dag-run timeout path emitted dagrun.duration.failed with only a dag_id tag, missing the run_type tag that every other dagrun.duration.* emission carries (via DagRun._emit_duration_stats_for_finished_state). This switches it to dag_run.stats_tags so the two paths are consistent.

You commented on the prior stalled attempt (#64768), which stalled on CI/static checks rather than design so this keeps the diff to a single value change and ships green static checks, including the metrics-registry sync check. Regression test included.

@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jun 12, 2026
@Vamsi-klu
Vamsi-klu force-pushed the fix/64765-dagrun-duration-failed-run-type-tag branch from 035b401 to 4f9d0e8 Compare June 20, 2026 16:32
@potiuk
potiuk marked this pull request as draft July 2, 2026 17:47
@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 3, 2026 01:34
@Vamsi-klu
Vamsi-klu force-pushed the fix/64765-dagrun-duration-failed-run-type-tag branch from 4f9d0e8 to d177e16 Compare July 3, 2026 01:34
When a Dag run timed out, the scheduler emitted dagrun.duration.failed with
only a dag_id tag, while every other dagrun.duration.* metric (emitted by
DagRun._emit_duration_stats_for_finished_state) also carries run_type. This
made the timeout path inconsistent and dropped run_type from dashboards and
alerts for timed-out runs.

Emit the metric with dag_run.stats_tags so it includes both dag_id and
run_type, matching the canonical completion path.

closes: apache#64765
@Vamsi-klu
Vamsi-klu force-pushed the fix/64765-dagrun-duration-failed-run-type-tag branch from d177e16 to aacad0d Compare July 3, 2026 01:39
@Vamsi-klu

Vamsi-klu commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Rebased this PR onto current upstream/main and pushed a cleaned update.

I resolved the scheduler_job_runner.py conflict by preserving the upstream team_name tag handling and using DagRun.stats_tags for dag_id/run_type parity with the normal completion metric path.

Validation run:

  • uv run ruff format airflow-core/src/airflow/jobs/scheduler_job_runner.py airflow-core/tests/unit/jobs/test_scheduler_job.py
  • uv run ruff check --fix airflow-core/src/airflow/jobs/scheduler_job_runner.py airflow-core/tests/unit/jobs/test_scheduler_job.py
  • uv run --project airflow-core pytest airflow-core/tests/unit/jobs/test_scheduler_job.py::TestSchedulerJob::test_dagrun_timeout_duration_metric_has_run_type -xvs
  • prek run ruff --from-ref upstream/main
  • prek run ruff-format --from-ref upstream/main

PR is already marked ready for review and is mergeable; only required review/checks remain.


Drafted-by: Codex (GPT-5)

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct and nicely scoped — switching to dag_run.stats_tags makes the timeout path consistent with DagRun._emit_duration_stats_for_finished_state, and the test pins the tag set. The newsfragment is appropriate since the metric shape is user-visible.

One thing worth being aware of downstream: dashboards keyed on the old tag set will now see an extra dimension.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

@potiuk
potiuk merged commit 3fb080b into apache:main Jul 30, 2026
77 of 78 checks passed
@potiuk potiuk added the backport-to-v3-3-test Backport to v3-3-test label Jul 30, 2026
@potiuk potiuk added this to the Airflow 3.3.1 milestone Jul 30, 2026
potiuk added a commit that referenced this pull request Jul 30, 2026
…#67765) (#70731)

(cherry picked from commit 3fb080b)

Co-authored-by: deepinsight coder <32898216+Vamsi-klu@users.noreply.github.com>
vatsrahul1001 pushed a commit that referenced this pull request Aug 5, 2026
…#67765) (#70731)

(cherry picked from commit 3fb080b)

Co-authored-by: deepinsight coder <32898216+Vamsi-klu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Scheduler including HA (high availability) scheduler backport-to-v3-3-test Backport to v3-3-test ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dagrun.duration.failed metric missing run_type tag when failure caused by dagrun_timeout

2 participants