From 36c685eaf25b8aad09838e25362533a48eda4099 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Mon, 29 Jul 2024 18:58:55 +0300 Subject: [PATCH] fix: bugs --- selfprivacy_api/utils/default_subdomains.py | 1 + selfprivacy_api/utils/monitoring.py | 43 ++++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/selfprivacy_api/utils/default_subdomains.py b/selfprivacy_api/utils/default_subdomains.py index f6665fc..828f9f4 100644 --- a/selfprivacy_api/utils/default_subdomains.py +++ b/selfprivacy_api/utils/default_subdomains.py @@ -8,6 +8,7 @@ DEFAULT_SUBDOMAINS = { "pleroma": "social", "roundcube": "roundcube", "testservice": "test", + "prometheus": "", } RESERVED_SUBDOMAINS = [ diff --git a/selfprivacy_api/utils/monitoring.py b/selfprivacy_api/utils/monitoring.py index 12aa510..6923b28 100644 --- a/selfprivacy_api/utils/monitoring.py +++ b/selfprivacy_api/utils/monitoring.py @@ -124,22 +124,35 @@ class MonitoringQueries: def _prometheus_response_to_monitoring_metrics( response: dict, id_key: str, clean_id: bool = False ) -> List[MonitoringMetric]: - return list( - map( - lambda x: MonitoringMetric( - id=MonitoringQueries._clean_slice_id( - x["metric"][id_key], clean_id=clean_id + if response["resultType"] == "vector": + return list( + map( + lambda x: MonitoringMetric( + id=MonitoringQueries._clean_slice_id( + x["metric"][id_key], clean_id=clean_id + ), + values=[MonitoringQueries._prometheus_value_to_monitoring_value(x["value"])], ), - values=list( - map( - MonitoringQueries._prometheus_value_to_monitoring_value, - x["values"], - ) - ), - ), - response["result"], + response["result"], + ) + ) + else: + return list( + map( + lambda x: MonitoringMetric( + id=MonitoringQueries._clean_slice_id( + x["metric"][id_key], clean_id=clean_id + ), + values=list( + map( + MonitoringQueries._prometheus_value_to_monitoring_value, + x["values"], + ) + ), + ), + response["result"], + ) ) - ) @staticmethod def _calculate_offset_and_duration( @@ -400,6 +413,6 @@ class MonitoringQueries: return MonitoringMetrics( metrics=MonitoringQueries._prometheus_response_to_monitoring_metrics( - data, "directon" + data, "direction" ) )