Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Avoids raising error when composing disk usage #6660

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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:
GitHK marked this conversation as resolved.
Show resolved Hide resolved
await self._publish_disk_usage(supported_usage)
self._last_usage = supported_usage

async def setup(self) -> None:
self._monitor_task = start_periodic_task(
Expand Down
Loading