spider-man-tm commented on code in PR #69078:
URL: https://github.com/apache/airflow/pull/69078#discussion_r3485518134
##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -948,6 +948,7 @@ def _check_last_n_dagruns_failed(self, dag_id,
max_consecutive_failed_dag_runs,
.values(is_paused=True)
.execution_options(synchronize_session="fetch")
)
+ stats.incr("dag.auto_paused", tags=self.stats_tags)
session.add(
Review Comment:
- `dag.*` namespace fits because auto-pause is a `DagModel` state change,
not a single-run event
(`dagrun.*`).
- `self.stats_tags` already contains `dag_id` and `run_type`, consistent
with other metric call sites
in this file.
##########
airflow-core/tests/unit/models/test_dag.py:
##########
@@ -1124,6 +1124,36 @@ def
test_dag_not_paused_when_latest_by_run_after_succeeds(self, testing_dag_bund
session.expire_all()
assert not session.get(DagModel, dag.dag_id).is_paused
+ @mock.patch("airflow.models.dagrun.stats.incr")
+ @pytest.mark.db_test
+ def test_auto_pause_emits_metric(self, mock_stats_incr,
testing_dag_bundle):
+ """Verify stats.incr("dag.auto_paused") is emitted when the scheduler
auto-pauses a DAG."""
+ dag_id = "dag_auto_pause_metric"
+ dag = DAG(dag_id, schedule=None, is_paused_upon_creation=False,
max_consecutive_failed_dag_runs=1)
+ op1 = BashOperator(task_id="task", bash_command="exit 1;")
+ dag.add_task(op1)
+ session = settings.Session()
+ session.add(DagModel(dag_id=dag.dag_id, bundle_name="testing",
is_stale=False))
+ session.flush()
+
+ scheduler_dag = sync_dag_to_db(dag, session=session)
+ self._add_dag_run(
+ scheduler_dag,
+ op1,
+ session,
+ run_id="run_fail",
+ logical_date=TEST_DATE,
+ run_after=TEST_DATE,
+ ti_state=TaskInstanceState.FAILED,
+ run_state=State.FAILED,
+ )
+
+ assert session.get(DagModel, dag.dag_id).is_paused
+ mock_stats_incr.assert_any_call(
+ "dag.auto_paused",
+ tags={"dag_id": dag_id, "run_type": DagRunType.MANUAL},
+ )
Review Comment:
`assert_any_call` instead of `assert_called_once_with` because
`update_state()` emits multiple `stats.incr` calls (task state changes,
duration, etc.) before reaching the auto-pause check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]