This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-4-test by this push:
     new a44dc0d0c3f [v3-4-test] Emit metric dag auto paused (#69078) (#77871)
a44dc0d0c3f is described below

commit a44dc0d0c3f90ffd044fc64955d6923cf6b16675
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Dec 1 11:17:01 2026 +0100

    [v3-4-test] Emit metric dag auto paused (#69078) (#77871)
    
    * Emit metric dag auto paused
    
    * Register dag.auto_paused metric in the metrics registry YAML
    
    The metric was emitted in code but missing from the registry,
    causing the check-metrics-synced-with-registry static check to fail.
    
    * remove run_type
    (cherry picked from commit 81766c0d51e89d27ff0859dc7a7cadb88af64b2f)
    
    Co-authored-by: Takayoshi Makabe 
<[email protected]>
---
 airflow-core/src/airflow/models/dagrun.py          |  1 +
 airflow-core/tests/unit/models/test_dag.py         | 30 ++++++++++++++++++++++
 .../observability/metrics/metrics_template.yaml    |  7 +++++
 3 files changed, 38 insertions(+)

diff --git a/airflow-core/src/airflow/models/dagrun.py 
b/airflow-core/src/airflow/models/dagrun.py
index 9cc3556a0f2..8f8cdf069f5 100644
--- a/airflow-core/src/airflow/models/dagrun.py
+++ b/airflow-core/src/airflow/models/dagrun.py
@@ -1078,6 +1078,7 @@ class DagRun(Base, LoggingMixin):
                 .values(is_paused=True, is_draining=False)
                 .execution_options(synchronize_session="fetch")
             )
+            stats.incr("dag.auto_paused", tags={"dag_id": self.dag_id})
             session.add(
                 Log(
                     event="paused",
diff --git a/airflow-core/tests/unit/models/test_dag.py 
b/airflow-core/tests/unit/models/test_dag.py
index a46b1c034e7..8adba4982d8 100644
--- a/airflow-core/tests/unit/models/test_dag.py
+++ b/airflow-core/tests/unit/models/test_dag.py
@@ -1169,6 +1169,36 @@ class TestDag:
         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},
+        )
+
     def test_dag_is_deactivated_upon_dagfile_deletion(self, dag_maker):
         dag_id = "old_existing_dag"
         with dag_maker(dag_id, schedule=None, is_paused_upon_creation=True) as 
dag:
diff --git 
a/shared/observability/src/airflow_shared/observability/metrics/metrics_template.yaml
 
b/shared/observability/src/airflow_shared/observability/metrics/metrics_template.yaml
index 0150a550efe..b1659cbc694 100644
--- 
a/shared/observability/src/airflow_shared/observability/metrics/metrics_template.yaml
+++ 
b/shared/observability/src/airflow_shared/observability/metrics/metrics_template.yaml
@@ -317,6 +317,13 @@ metrics:
     legacy_name: "dag.serialization.version_updated.{dag_id}.{bundle_name}"
     name_variables: ["dag_id", "bundle_name"]
 
+  - name: "dag.auto_paused"
+    description: "Number of Dags automatically paused due to consecutive 
failures exceeding
+      the configured threshold. Metric with dag_id tagging."
+    type: "counter"
+    legacy_name: "-"
+    name_variables: []
+
   - name: "celery.task_timeout_error"
     description: "Number of ``AirflowTaskTimeout`` errors raised when 
publishing Task to Celery Broker."
     type: "counter"

Reply via email to