This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 81766c0d51e Emit metric dag auto paused (#69078)
81766c0d51e is described below
commit 81766c0d51e89d27ff0859dc7a7cadb88af64b2f
Author: Takayoshi Makabe <[email protected]>
AuthorDate: Tue Dec 1 04:41:26 2026 +0900
Emit metric dag auto paused (#69078)
* 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
---
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 a000a5d51da..ad10f7bb897 100644
--- a/airflow-core/src/airflow/models/dagrun.py
+++ b/airflow-core/src/airflow/models/dagrun.py
@@ -1153,6 +1153,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 f94a8a0c92e..14c5f38a3b4 100644
--- a/airflow-core/tests/unit/models/test_dag.py
+++ b/airflow-core/tests/unit/models/test_dag.py
@@ -1159,6 +1159,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 1d9a5e4a898..0010ee3d0c0 100644
---
a/shared/observability/src/airflow_shared/observability/metrics/metrics_template.yaml
+++
b/shared/observability/src/airflow_shared/observability/metrics/metrics_template.yaml
@@ -342,6 +342,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"