From d8f172080da94d6f57e77af3e5a30f8fb4a8be5a Mon Sep 17 00:00:00 2001 From: Andrei Neagu <5694077+GitHK@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:08:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Avoids=20raising=20error=20when?= =?UTF-8?q?=20composing=20disk=20usage=20(#6660)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrei Neagu --- .../modules/system_monitor/_disk_usage.py | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/system_monitor/_disk_usage.py b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/system_monitor/_disk_usage.py index cdaa531aeb8..f1f34e0a6e7 100644 --- a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/system_monitor/_disk_usage.py +++ b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/modules/system_monitor/_disk_usage.py @@ -52,10 +52,6 @@ def _get_normalized_folder_name(path: Path) -> str: return f"{path}".replace("/", "_") -def _have_common_entries(a: set[str], b: set[str]) -> bool: - return bool(len(a & b) > 0) - - @dataclass class DiskUsageMonitor: app: FastAPI @@ -124,11 +120,11 @@ def _replace_incoming_usage( @staticmethod def _get_grouped_usage_to_folder_names( - normalized_disk_usage: dict[str, DiskUsage] + local_disk_usage: dict[str, DiskUsage] ) -> dict[DiskUsage, set[str]]: """Groups all paths that have the same metrics together""" usage_to_folder_names: dict[DiskUsage, set[str]] = {} - for folder_name, disk_usage in normalized_disk_usage.items(): + for folder_name, disk_usage in local_disk_usage.items(): if disk_usage not in usage_to_folder_names: usage_to_folder_names[disk_usage] = set() @@ -170,18 +166,12 @@ async def _monitor(self) -> None: msg = f"Could not assign {disk_usage=} for {folder_names=}" raise RuntimeError(msg) - detected_items = set(usage.keys()) - if not detected_items.issubset(_SUPPORTED_ITEMS): - msg = ( - f"Computed {usage=}, has unsupported items {detected_items=}. " - f"Currently only the following are supported: {_SUPPORTED_ITEMS}" - ) - raise RuntimeError(msg) + supported_usage = {k: v for k, v in usage.items() if k in _SUPPORTED_ITEMS} # notify only when usage changes - if self._last_usage != usage: - await self._publish_disk_usage(usage) - self._last_usage = usage + if self._last_usage != supported_usage: + await self._publish_disk_usage(supported_usage) + self._last_usage = supported_usage async def setup(self) -> None: self._monitor_task = start_periodic_task(