Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,13 @@ async def get_cluster_summary(self) -> Dict[str, Any]:

# 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{{ {single_cluster_label} }}))
sum(kube_node_status_capacity{{ resource='memory' {single_cluster_label} }})
"""
Comment on lines 256 to 258
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix PromQL syntax: use double quotes for label values.

PromQL requires double quotes for label values, not single quotes. The current syntax resource='memory' will cause a query syntax error.

Apply this diff to fix the syntax:

         memory_query = f"""
-            sum(kube_node_status_capacity{{ resource='memory' {single_cluster_label} }})
+            sum(kube_node_status_capacity{{ resource="memory" {single_cluster_label} }})
         """
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
memory_query = f"""
sum(max by (instance) (machine_memory_bytes{{ {single_cluster_label} }}))
sum(kube_node_status_capacity{{ resource='memory' {single_cluster_label} }})
"""
memory_query = f"""
sum(kube_node_status_capacity{{ resource="memory" {single_cluster_label} }})
"""
🤖 Prompt for AI Agents
In
robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py
around lines 256 to 258, the PromQL uses single quotes for the label value
(resource='memory') which is invalid; change the label value to use double
quotes (resource="memory") in the f-string query, and scan nearby queries for
other label values using single quotes and convert them to double quotes as
well.


cpu_query = f"""
sum(max by (instance) (machine_cpu_cores{{ {single_cluster_label} }}))
sum(kube_node_status_capacity{{ resource='cpu' {single_cluster_label} }})
"""
Comment on lines 260 to 262
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Fix PromQL syntax: use double quotes for label values.

PromQL requires double quotes for label values, not single quotes. The current syntax resource='cpu' will cause a query syntax error.

Apply this diff to fix the syntax:

         cpu_query = f"""
-            sum(kube_node_status_capacity{{ resource='cpu' {single_cluster_label} }})
+            sum(kube_node_status_capacity{{ resource="cpu" {single_cluster_label} }})
         """

After applying the fixes, please verify that both queries execute successfully in your Prometheus environments:


🏁 Script executed:

#!/bin/bash
# Description: Test the corrected Prometheus queries return valid results
# This verifies the syntax is correct and metrics exist

# Note: Replace PROMETHEUS_URL with your actual Prometheus endpoint
PROMETHEUS_URL="${PROMETHEUS_URL:-http://localhost:9090}"

echo "Testing memory query..."
curl -s "${PROMETHEUS_URL}/api/v1/query" \
  --data-urlencode 'query=sum(kube_node_status_capacity{resource="memory"})' | jq '.data.result'

echo -e "\nTesting CPU query..."
curl -s "${PROMETHEUS_URL}/api/v1/query" \
  --data-urlencode 'query=sum(kube_node_status_capacity{resource="cpu"})' | jq '.data.result'

Length of output: 45


I need to verify the PromQL syntax rules and inspect the actual codebase since the Prometheus endpoint is unavailable in the sandbox.

Now let me inspect the actual file to verify the current state of the code:


---

🏁 Script executed:

```shell
#!/bin/bash
# Inspect the prometheus_metrics_service.py file around lines 260-262
fd -t f "prometheus_metrics_service.py" --exec cat {} +

Length of output: 16651


Fix PromQL syntax: use double quotes for label values in both queries.

PromQL requires double quotes for label values, not single quotes. The current syntax with single quotes will cause query syntax errors. Both the memory_query and cpu_query contain this issue.

Apply this diff to fix both queries:

         memory_query = f"""
-            sum(kube_node_status_capacity{{ resource='memory' {single_cluster_label} }})
+            sum(kube_node_status_capacity{{ resource="memory" {single_cluster_label} }})
         """

         cpu_query = f"""
-            sum(kube_node_status_capacity{{ resource='cpu' {single_cluster_label} }})
+            sum(kube_node_status_capacity{{ resource="cpu" {single_cluster_label} }})
         """

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py
around lines 260 to 262, the PromQL label values use single quotes which is
invalid; update the cpu_query and the corresponding memory_query to use
double-quoted label values (e.g. resource="cpu" and resource="memory"), making
sure the f-string and surrounding triple-quoted string are adjusted so the
double quotes appear in the final PromQL expression.

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