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

jscheffl 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 06d4b1ea7d6 Emit dag_processing.last_run.seconds_ago as a tagged 
metric (#62487)
06d4b1ea7d6 is described below

commit 06d4b1ea7d6e7795f1724662598e1f6885df0ac8
Author: Hussein Awala <[email protected]>
AuthorDate: Sun Jun 14 13:38:46 2026 +0200

    Emit dag_processing.last_run.seconds_ago as a tagged metric (#62487)
    
    Move dag_processing.last_run.seconds_ago.{dag_file} to a tagged metric
    dag_processing.last_run.seconds_ago with file_path, bundle_name and
    file_name tags. file_path and bundle_name together uniquely identify a
    DAG file (the same file name can exist in different folders or bundles),
    and file_name is kept as a tag to ease migration from the legacy metric.
    
    The legacy interpolated name is registered as the metric's legacy_name,
    so it is still emitted by default (controlled by [metrics] legacy_names_on),
    preserving backward compatibility.
---
 airflow-core/newsfragments/62487.significant.rst     |  1 +
 airflow-core/src/airflow/dag_processing/manager.py   | 14 +++++++++++++-
 .../tests/unit/dag_processing/test_manager.py        | 20 +++++++++++++++++---
 .../observability/metrics/metrics_template.yaml      |  9 +++++----
 4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/airflow-core/newsfragments/62487.significant.rst 
b/airflow-core/newsfragments/62487.significant.rst
new file mode 100644
index 00000000000..5de4f8fe479
--- /dev/null
+++ b/airflow-core/newsfragments/62487.significant.rst
@@ -0,0 +1 @@
+``dag_processing.last_run.seconds_ago.{dag_file}`` is now a legacy metric. The 
new metric ``dag_processing.last_run.seconds_ago`` is emitted with 
``file_path``, ``bundle_name`` and ``file_name`` as tags, where ``file_path`` 
and ``bundle_name`` uniquely identify the DAG file. The legacy metric is still 
emitted by default and can be disabled via ``[metrics] legacy_names_on``.
diff --git a/airflow-core/src/airflow/dag_processing/manager.py 
b/airflow-core/src/airflow/dag_processing/manager.py
index 783de174758..54a5ee7098c 100644
--- a/airflow-core/src/airflow/dag_processing/manager.py
+++ b/airflow-core/src/airflow/dag_processing/manager.py
@@ -1023,7 +1023,19 @@ class DagFileProcessorManager(LoggingMixin):
                 last_run = stat.last_finish_time
                 if last_run:
                     seconds_ago = (utcnow - last_run).total_seconds()
-                    
stats.gauge(f"dag_processing.last_run.seconds_ago.{file_name}", seconds_ago)
+                    # file_path and bundle_name uniquely identify a file (the 
same file name can
+                    # exist in different folders or bundles). file_name is 
kept as a tag to ease
+                    # migration from the legacy interpolated metric, which is 
emitted automatically
+                    # from the registry (controlled by the export_legacy_names 
config).
+                    stats.gauge(
+                        "dag_processing.last_run.seconds_ago",
+                        seconds_ago,
+                        tags={
+                            "file_path": file.normalized_file_path_for_stats,
+                            "bundle_name": 
normalize_name_for_stats(file.bundle_name),
+                            "file_name": file_name,
+                        },
+                    )
 
                 rows.append(
                     (
diff --git a/airflow-core/tests/unit/dag_processing/test_manager.py 
b/airflow-core/tests/unit/dag_processing/test_manager.py
index 17795bcc887..0f6c061fc43 100644
--- a/airflow-core/tests/unit/dag_processing/test_manager.py
+++ b/airflow-core/tests/unit/dag_processing/test_manager.py
@@ -1459,8 +1459,10 @@ class TestDagFileProcessorManager:
             tags={"bundle_name": bundle_name, "file_name": dag_filename[:-3]},
         )
 
-    @mock.patch("airflow.dag_processing.manager.stats.gauge")
-    def test_log_file_processing_stats_normalizes_metric_name(self, 
statsd_gauge_mock):
+    @mock.patch("airflow.dag_processing.manager.stats._get_backend")
+    def test_log_file_processing_stats_normalizes_metric_name(self, 
mock_get_backend):
+        backend = mock.MagicMock()
+        mock_get_backend.return_value = backend
         manager = DagFileProcessorManager(max_runs=1)
         dag_file = DagFileInfo(
             bundle_name="testing",
@@ -1473,9 +1475,21 @@ class TestDagFileProcessorManager:
 
         manager._log_file_processing_stats({"testing": {dag_file}})
 
-        statsd_gauge_mock.assert_any_call(
+        # Legacy interpolated metric, kept for backward compatibility.
+        backend.gauge.assert_any_call(
             "dag_processing.last_run.seconds_ago.test_of_sprak_opertaor",
             mock.ANY,
+            tags={"file_path": "test_of_sprak_opertaor.py", "bundle_name": 
"testing"},
+        )
+        # New metric with file_path, bundle_name and file_name tagging.
+        backend.gauge.assert_any_call(
+            "dag_processing.last_run.seconds_ago",
+            mock.ANY,
+            tags={
+                "file_path": "test_of_sprak_opertaor.py",
+                "bundle_name": "testing",
+                "file_name": "test_of_sprak_opertaor",
+            },
         )
 
     @pytest.mark.usefixtures("testing_dag_bundle")
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 42e2781dcfa..0ba1563116f 100644
--- 
a/shared/observability/src/airflow_shared/observability/metrics/metrics_template.yaml
+++ 
b/shared/observability/src/airflow_shared/observability/metrics/metrics_template.yaml
@@ -411,11 +411,12 @@ metrics:
     legacy_name: "-"
     name_variables: []
 
-  - name: "dag_processing.last_run.seconds_ago.{dag_file}"
-    description: "Seconds since ``{dag_file}`` was last processed"
+  - name: "dag_processing.last_run.seconds_ago"
+    description: "Seconds since a DAG file was last processed.
+    Metric with file_path, bundle_name and file_name tagging."
     type: "gauge"
-    legacy_name: "-"
-    name_variables: ["dag_file"]
+    legacy_name: "dag_processing.last_run.seconds_ago.{file_name}"
+    name_variables: ["file_name"]
 
   - name: "dag_processing.last_num_of_db_queries.{dag_file}"
     description: "Number of queries to Airflow database during parsing per 
``{dag_file}``"

Reply via email to