Skip to content

Commit 627d66f

Browse files
committed
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
1 parent 4671a17 commit 627d66f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,14 @@ async def query_and_validate(self, prom_query) -> Any:
228228

229229
async def get_cluster_summary(self) -> Dict[str, Any]:
230230
cluster_label = self.get_prometheus_cluster_label()
231+
232+
# use this for queries with no labels. turn ', cluster="xxx"' to 'cluster="xxx"'
233+
single_cluster_label = cluster_label.replace(",", "")
231234
memory_query = f"""
232-
sum(max by (instance) (machine_memory_bytes{{ {cluster_label} }}))
235+
sum(max by (instance) (machine_memory_bytes{{ {single_cluster_label} }}))
233236
"""
234237
cpu_query = f"""
235-
sum(max by (instance) (machine_cpu_cores{{ {cluster_label} }}))
238+
sum(max by (instance) (machine_cpu_cores{{ {single_cluster_label} }}))
236239
"""
237240
kube_system_requests_mem = f"""
238241
sum(max(kube_pod_container_resource_requests{{ namespace='kube-system', resource='memory' {cluster_label} }}) by (job, pod, container) )

0 commit comments

Comments
 (0)