From bbfd82f893792b6d88bce0ef313ecba4d2177594 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 4 Sep 2026 16:45:44 +0200 Subject: [PATCH] fix(profiling): let the task recap reach past the twenty slowest ansible.cfg enables profile_tasks, whose output_limit defaults to 20. On a deploy round of this size the recap therefore cut off at 66.07s and printed nothing below, so a role whose cost is spread over many cheap tasks could not be attributed at all: in run 33828309745 that left 22.7 of sys-svc-compose 51.9 minutes unexplained, and the same blind spot covers web-app-nextcloud and web-app-keycloak almost entirely. The callback accepts all, which disables the cap, but the recap prints one line per task execution and pass 1 alone ran over 7500 of them. Since the Actions worker dies silently on ENOSPC while writing its own logs, which is why utils/tests/swarm/matrix.py aborts a step at DISK_FLOOR_MB, the limit stays bounded at 300: about 600 extra lines across both passes. Measured with a 30-task play: 30 recap entries with this config, 20 with the upstream default forced through PROFILE_TASKS_TASK_OUTPUT_LIMIT. The lint pins the setting so removing the section cannot silently restore the truncation. Co-Authored-By: Claude Opus 5 (1M context) --- ansible.cfg | 3 ++ .../test_profile_tasks_output_limit.py | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/lint/filesystem/test_profile_tasks_output_limit.py diff --git a/ansible.cfg b/ansible.cfg index b2c5c1ba3c..62be0232c0 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -25,6 +25,9 @@ lookup_plugins = ./plugins/lookup library = ./library module_utils = ./utils +[callback_profile_tasks] +task_output_limit = 300 + [ssh_connection] ssh_args = -o ControlMaster=auto -o ControlPersist=20s -o ControlPath=~/.ssh/ansible-%h-%p-%r -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=accept-new -o PreferredAuthentications=publickey,password,keyboard-interactive pipelining = True diff --git a/tests/lint/filesystem/test_profile_tasks_output_limit.py b/tests/lint/filesystem/test_profile_tasks_output_limit.py new file mode 100644 index 0000000000..2678b9df90 --- /dev/null +++ b/tests/lint/filesystem/test_profile_tasks_output_limit.py @@ -0,0 +1,51 @@ +"""Lint check: the task profiler must not truncate its summary to the default. + +``ansible.cfg`` enables ``profile_tasks``, whose ``output_limit`` defaults to +20. A deploy round of this size then reports only the twenty slowest tasks and +prints nothing below them, so any role whose cost is spread over many cheap +tasks cannot be attributed at all: in run 33828309745 the recap cut off at +66.07s, leaving 22.7 of ``sys-svc-compose``'s 51.9 minutes unaccounted. + +The limit stays bounded rather than ``all`` because the recap prints one line +per task execution and the Actions worker dies silently on ENOSPC while writing +its own logs, which is the same reason ``utils/tests/swarm/matrix.py`` aborts a +step at ``DISK_FLOOR_MB``. +""" + +from __future__ import annotations + +import configparser +import unittest + +from utils import PROJECT_ROOT + +CONFIG = PROJECT_ROOT / "ansible.cfg" +SECTION = "callback_profile_tasks" +KEY = "task_output_limit" +DEFAULT_LIMIT = 20 + + +class TestProfileTasksOutputLimit(unittest.TestCase): + def setUp(self) -> None: + self.parser = configparser.ConfigParser() + self.parser.read(CONFIG) + + def test_the_profiler_is_enabled(self) -> None: + enabled = self.parser.get("defaults", "callbacks_enabled", fallback="") + self.assertIn("profile_tasks", enabled) + + def test_the_summary_is_not_left_at_the_default_limit(self) -> None: + self.assertTrue( + self.parser.has_option(SECTION, KEY), + f"ansible.cfg must set [{SECTION}] {KEY}; without it the recap " + f"stops after {DEFAULT_LIMIT} tasks and the cost of a role spread " + "over many cheap tasks cannot be attributed", + ) + value = self.parser.get(SECTION, KEY).strip() + if value == "all": + return + self.assertGreater(int(value), DEFAULT_LIMIT) + + +if __name__ == "__main__": + unittest.main()