Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airflow-core/src/airflow/dag_processing/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ def _log_file_processing_stats(self, known_files: dict[str, set[DagFileInfo]]):
proc = self._processors.get(file)
num_dags = stat.num_dags
num_errors = stat.import_errors
file_name = Path(file.rel_path).stem
file_name = normalize_name_for_stats(Path(file.rel_path).stem)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is _log_file_processing_stats() the only place where Dag file names are incorporated into metric names?

Since the bug is fundamentally about unsanitized file-derived metric segments, it’d be good to verify there aren’t other DAG-processing stats paths still using Path(...).stem or rel_path directly without normalize_name_for_stats().

processor_pid = proc.pid if proc else None
processor_start_time = proc.start_time if proc else None
runtime = (now - processor_start_time) if processor_start_time else None
Expand Down
19 changes: 19 additions & 0 deletions airflow-core/tests/unit/dag_processing/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,25 @@ def test_send_file_processing_statsd_timing(
tags={"bundle_name": bundle_name, "file_name": dag_filename[:-3]},
)

@mock.patch("airflow.dag_processing.manager.stats.gauge")
def test_log_file_processing_stats_sanitizes_last_run_seconds_ago_metric_name(self, statsd_gauge_mock):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def test_log_file_processing_stats_sanitizes_last_run_seconds_ago_metric_name(self, statsd_gauge_mock):
def test_log_file_processing_stats_normalizes_metric_name(self, statsd_gauge_mock):

manager = DagFileProcessorManager(max_runs=1)
dag_file = DagFileInfo(
bundle_name="testing",
rel_path=Path("test_of sprak_opertaor.py"),
bundle_path=TEST_DAGS_FOLDER,
)
manager._file_stats[dag_file] = DagFileStat(
last_finish_time=timezone.utcnow() - timedelta(seconds=5),
)

manager._log_file_processing_stats({"testing": {dag_file}})

statsd_gauge_mock.assert_any_call(
"dag_processing.last_run.seconds_ago.test_of_sprak_opertaor",
mock.ANY,
)

@pytest.mark.usefixtures("testing_dag_bundle")
def test_refresh_dags_dir_doesnt_delete_zipped_dags(
self, tmp_path, session, configure_testing_dag_bundle, test_zip_path
Expand Down
Loading