From 627d66fc20e51ed59909cc688973304cf883d80f Mon Sep 17 00:00:00 2001 From: Arik Alon Date: Thu, 15 Aug 2024 22:06:02 +0300 Subject: [PATCH] bug fix - On queries with no labels, adding the cluster label with a comma prefix created an invalid query ( machine_memory_bytes{, cluster="foo"} ) that failed --- .../metrics_service/prometheus_metrics_service.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index 4702001..71d5ae8 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -228,11 +228,14 @@ async def query_and_validate(self, prom_query) -> Any: async def get_cluster_summary(self) -> Dict[str, Any]: cluster_label = self.get_prometheus_cluster_label() + + # use this for queries with no labels. turn ', cluster="xxx"' to 'cluster="xxx"' + single_cluster_label = cluster_label.replace(",", "") memory_query = f""" - sum(max by (instance) (machine_memory_bytes{{ {cluster_label} }})) + sum(max by (instance) (machine_memory_bytes{{ {single_cluster_label} }})) """ cpu_query = f""" - sum(max by (instance) (machine_cpu_cores{{ {cluster_label} }})) + sum(max by (instance) (machine_cpu_cores{{ {single_cluster_label} }})) """ kube_system_requests_mem = f""" sum(max(kube_pod_container_resource_requests{{ namespace='kube-system', resource='memory' {cluster_label} }}) by (job, pod, container) )