Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate in case of node change #143

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
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
52 changes: 30 additions & 22 deletions robusta_krr/core/integrations/prometheus/metrics/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ def get_query(self, object: K8sObjectData, duration: str, step: str) -> str:
pods_selector = "|".join(pod.name for pod in object.pods)
cluster_label = self.get_prometheus_cluster_label()
return f"""
rate(
container_cpu_usage_seconds_total{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}[{step}]
)
max(
rate(
container_cpu_usage_seconds_total{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}[{step}]
)
) by (container, pod, job)
"""


Expand All @@ -27,14 +29,17 @@ def get_query(self, object: K8sObjectData, duration: str, step: str) -> str:
return f"""
quantile_over_time(
{round(percentile / 100, 2)},
rate(
container_cpu_usage_seconds_total{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}[{step}]
)[{duration}:{step}]
max(
rate(
container_cpu_usage_seconds_total{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}[{step}]
)
) by (container, pod, job)
[{duration}:{step}]
)
"""

Expand All @@ -47,11 +52,14 @@ def get_query(self, object: K8sObjectData, duration: str, step: str) -> str:
cluster_label = self.get_prometheus_cluster_label()
return f"""
count_over_time(
container_cpu_usage_seconds_total{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}[{duration}]
max(
container_cpu_usage_seconds_total{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}
) by (container, pod, job)
[{duration}:{step}]
)
"""
32 changes: 19 additions & 13 deletions robusta_krr/core/integrations/prometheus/metrics/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def get_query(self, object: K8sObjectData, duration: str, step: str) -> str:
pods_selector = "|".join(pod.name for pod in object.pods)
cluster_label = self.get_prometheus_cluster_label()
return f"""
sum(
max(
container_memory_working_set_bytes{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
Expand All @@ -25,12 +25,15 @@ def get_query(self, object: K8sObjectData, duration: str, step: str) -> str:
cluster_label = self.get_prometheus_cluster_label()
return f"""
max_over_time(
container_memory_working_set_bytes{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}[{duration}:{step}]
max(
container_memory_working_set_bytes{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}
) by (container, pod, job)
[{duration}:{step}]
)
"""

Expand All @@ -41,11 +44,14 @@ def get_query(self, object: K8sObjectData, duration: str, step: str) -> str:
cluster_label = self.get_prometheus_cluster_label()
return f"""
count_over_time(
container_memory_working_set_bytes{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}[{duration}:{step}]
max(
container_memory_working_set_bytes{{
namespace="{object.namespace}",
pod=~"{pods_selector}",
container="{object.container}"
{cluster_label}
}}
) by (container, pod, job)
[{duration}:{step}]
)
"""
2 changes: 1 addition & 1 deletion robusta_krr/strategies/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __calculate_cpu_proposal(
if object_data.hpa is not None and object_data.hpa.target_cpu_utilization_percentage is not None:
return ResourceRecommendation.undefined(info="HPA detected")

cpu_usage = self.settings.calculate_cpu_proposal(data)
cpu_usage = self.settings.calculate_cpu_proposal(filtered_data)
return ResourceRecommendation(request=cpu_usage, limit=None)

def __calculate_memory_proposal(
Expand Down
Loading