Skip to content

Commit

Permalink
bug fix - On queries with no labels, adding the cluster label with a …
Browse files Browse the repository at this point in the history
…comma prefix created an invalid query ( machine_memory_bytes{, cluster="foo"} ) that failed
  • Loading branch information
arikalon1 committed Aug 15, 2024
1 parent 4671a17 commit 627d66f
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) )
Expand Down

0 comments on commit 627d66f

Please sign in to comment.