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

Fix long queries + increase min reccomendations #117

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Optional

from robusta_krr.core.abstract.strategies import Metric

from robusta_krr.core.models.objects import K8sObjectData
from .base_metric import BaseMetricLoader, QueryType

PrometheusSeries = Any
Expand All @@ -22,6 +22,13 @@ def get_target_name(series: PrometheusSeries) -> Optional[str]:
return series["metric"][label]
return None

@staticmethod
def get_pods_selector(object: K8sObjectData) -> Optional[str]:
if len(object.pods) < 20:
return "|".join(pod.name for pod in object.pods)
else:
return "|".join(set([pod.name[:pod.name.rfind('-')] + '-[0-9a-z]{0,5}' for pod in object.pods]))
Avi-Robusta marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def filter_prom_jobs_results(
series_list_result: list[PrometheusSeries],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@bind_metric(ResourceType.CPU)
class CPUMetricLoader(BaseFilteredMetricLoader):
def get_query(self, object: K8sObjectData, resolution: Optional[str]) -> str:
pods_selector = "|".join(pod.name for pod in object.pods)
pods_selector = self.get_pods_selector(object)
cluster_label = self.get_prometheus_cluster_label()
return (
"sum(irate(container_cpu_usage_seconds_total{"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@bind_metric(ResourceType.Memory)
class MemoryMetricLoader(BaseFilteredMetricLoader):
def get_query(self, object: K8sObjectData, resolution: Optional[str]) -> str:
pods_selector = "|".join(pod.name for pod in object.pods)
pods_selector = self.get_pods_selector(object)
cluster_label = self.get_prometheus_cluster_label()
return (
"sum(container_memory_working_set_bytes{"
Expand All @@ -33,7 +33,7 @@ class SimpleMemoryMetricLoader(MemoryMetricLoader):
"""

def get_query(self, object: K8sObjectData, resolution: Optional[str]) -> str:
pods_selector = "|".join(pod.name for pod in object.pods)
pods_selector = self.get_pods_selector(object)
cluster_label = self.get_prometheus_cluster_label()
resolution_formatted = f"[{resolution}]" if resolution else ""
return (
Expand Down
4 changes: 2 additions & 2 deletions robusta_krr/core/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Config(pd.BaseSettings):
selector: Optional[str] = None

# Value settings
cpu_min_value: int = pd.Field(5, ge=0) # in millicores
memory_min_value: int = pd.Field(10, ge=0) # in megabytes
cpu_min_value: int = pd.Field(100, ge=0) # in millicores
memory_min_value: int = pd.Field(100, ge=0) # in megabytes

# Prometheus Settings
prometheus_url: Optional[str] = pd.Field(None)
Expand Down
Loading