Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaveMyYard committed Apr 24, 2024
1 parent 08dc060 commit 22dc630
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion robusta_krr/formatters/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _format_request_str(item: ResourceScan, resource: ResourceType, selector: st
+ " -> "
+ _format(recommended.value)
+ f"[/{severity.color}]"
+ (f" [grey27]({info})[/grey27]" if info else "")
+ (f"\n[grey27]({info})[/grey27]" if info else "")
)


Expand Down
15 changes: 11 additions & 4 deletions robusta_krr/strategies/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,21 @@ class SimpleStrategySettings(StrategySettings):
)
use_oomkill_data: bool = pd.Field(
False,
description="Whether to use OOMKilled data to calculate memory recommendations. Unstable and experimental.",
description="Whether to use OOMKilled data to calculate memory recommendations (experimental).",
)
oom_memory_buffer_percentage: float = pd.Field(
25, gt=0, description="The percentage of added buffer to the max memory limit surpassed by OOMKilled event."
)

def calculate_memory_proposal(self, data: PodsTimeData, max_oomkill: float = 0) -> float:
data_ = [np.max(values[:, 1]) for values in data.values()]
if len(data_) == 0:
return float("NaN")

return max(np.max(data_), max_oomkill) * (1 + self.memory_buffer_percentage / 100)
return max(
np.max(data_) * (1 + self.memory_buffer_percentage / 100),
max_oomkill * (1 + self.oom_memory_buffer_percentage / 100),
)

def calculate_cpu_proposal(self, data: PodsTimeData) -> float:
if len(data) == 0:
Expand Down Expand Up @@ -130,14 +136,15 @@ def __calculate_memory_proposal(
self, history_data: MetricsPodData, object_data: K8sObjectData
) -> ResourceRecommendation:
data = history_data["MaxMemoryLoader"]
info: list[str] = []

if self.settings.use_oomkill_data:
max_oomkill_data = history_data["MaxOOMKilledMemoryLoader"]
max_oomkill_value = (
np.max([values[0, 1] for values in max_oomkill_data.values()]) if len(max_oomkill_data) > 0 else 0
)
if max_oomkill_value != 0:
print(max_oomkill_data)
info.append("OOMKill detected")
else:
max_oomkill_value = 0

Expand All @@ -158,7 +165,7 @@ def __calculate_memory_proposal(
return ResourceRecommendation.undefined(info="HPA detected")

memory_usage = self.settings.calculate_memory_proposal(data, max_oomkill_value)
return ResourceRecommendation(request=memory_usage, limit=memory_usage)
return ResourceRecommendation(request=memory_usage, limit=memory_usage, info=", ".join(info) if info else None)

def run(self, history_data: MetricsPodData, object_data: K8sObjectData) -> RunResult:
return {
Expand Down

0 comments on commit 22dc630

Please sign in to comment.