From 2f825e252718ad6c109f41d0a5da47c2c1a625c7 Mon Sep 17 00:00:00 2001 From: imprvhub Date: Thu, 19 Dec 2024 11:14:20 -0300 Subject: [PATCH] fix: handle None system metrics in user admin panel - Add default values for system metrics when None - Add conditional system metrics display in template - Show informative message when metrics unavailable Closes #1028 --- .../_internal/server/templates/user.html | 28 +++++++++++++------ .../_internal/server/views/ui.py | 6 +++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/conda-store-server/conda_store_server/_internal/server/templates/user.html b/conda-store-server/conda_store_server/_internal/server/templates/user.html index 60cba6d7b..c9169e04c 100644 --- a/conda-store-server/conda_store_server/_internal/server/templates/user.html +++ b/conda-store-server/conda_store_server/_internal/server/templates/user.html @@ -112,15 +112,25 @@
Usage
System

Below is system metrics.

- - -
-
{{ (system_metrics.disk_usage / system_metrics.disk_total * 100) | round | int }}%
-
+ {% if system_metrics.disk_total == 0 %} +
+ System metrics are not available yet. They will be populated once the conda-store worker starts. +
+ {% else %} + + +
+
{{ (system_metrics.disk_usage / system_metrics.disk_total * 100) | round | int }}%
+
+ {% endif %}
diff --git a/conda-store-server/conda_store_server/_internal/server/views/ui.py b/conda-store-server/conda_store_server/_internal/server/views/ui.py index 8d45c7ba2..941daee47 100644 --- a/conda-store-server/conda_store_server/_internal/server/views/ui.py +++ b/conda-store-server/conda_store_server/_internal/server/views/ui.py @@ -265,7 +265,11 @@ async def ui_get_user( entity, api.list_namespaces(db, show_soft_deleted=False) ) - system_metrics = api.get_system_metrics(db) + system_metrics = api.get_system_metrics(db) or { + "disk_total": 0, + "disk_free": 0, + "disk_usage": 0 + } namespace_usage_metrics = auth.filter_namespaces( entity, api.get_namespace_metrics(db)