From c63589857942cc4f46744919ef73aa60dd44258b Mon Sep 17 00:00:00 2001 From: Mykola Martynov Date: Tue, 19 Mar 2024 18:56:38 +0200 Subject: use alias when available for strategy setting (#235) * Add --allow_hpa flag * use `--allow-hpa` option * use OptionInfo instead of Option to support different name for same option * revert back allow_hpa field definition * fix issue when there is no underscore exist in option name --------- Co-authored-by: Robusta Runner --- robusta_krr/main.py | 7 ++++--- robusta_krr/strategies/simple.py | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'robusta_krr') diff --git a/robusta_krr/main.py b/robusta_krr/main.py index 83faeba..7dff56b 100644 --- a/robusta_krr/main.py +++ b/robusta_krr/main.py @@ -10,6 +10,7 @@ from uuid import UUID import typer import urllib3 from pydantic import ValidationError # noqa: F401 +from typer.models import OptionInfo from robusta_krr import formatters as concrete_formatters # noqa: F401 from robusta_krr.core.abstract import formatters @@ -280,9 +281,9 @@ def load_commands() -> None: inspect.Parameter( name=field_name, kind=inspect.Parameter.KEYWORD_ONLY, - default=typer.Option( - field_meta.default, - f"--{field_name}", + default=OptionInfo( + default=field_meta.default, + param_decls=list(set([f"--{field_name}", f"--{field_name.replace('_', '-')}"])), help=f"{field_meta.field_info.description}", rich_help_panel="Strategy Settings", ), diff --git a/robusta_krr/strategies/simple.py b/robusta_krr/strategies/simple.py index 8bbd08d..64e58ac 100644 --- a/robusta_krr/strategies/simple.py +++ b/robusta_krr/strategies/simple.py @@ -21,7 +21,6 @@ from robusta_krr.core.integrations.prometheus.metrics import ( PrometheusMetric, ) - class SimpleStrategySettings(StrategySettings): cpu_percentile: float = pd.Field(99, gt=0, le=100, description="The percentile to use for the CPU recommendation.") memory_buffer_percentage: float = pd.Field( @@ -66,7 +65,7 @@ class SimpleStrategy(BaseStrategy[SimpleStrategySettings]): This strategy does not work with objects with HPA defined (Horizontal Pod Autoscaler). If HPA is defined for CPU or Memory, the strategy will return "?" for that resource. - You can override this behaviour by passing the --allow_hpa flag + You can override this behaviour by passing the --allow-hpa flag Learn more: [underline]https://github.com/robusta-dev/krr#algorithm[/underline] """ -- cgit v1.2.3 From 699802a26484a2bc303a6e95dbf61844d642f644 Mon Sep 17 00:00:00 2001 From: Natan Yellin Date: Thu, 21 Mar 2024 11:54:53 +0100 Subject: Fix fileoutput (#231) * Fix --fileoutput * Remove dead code --------- Co-authored-by: Pavel Zhukov <33721692+LeaveMyYard@users.noreply.github.com> --- robusta_krr/core/models/config.py | 7 ------- robusta_krr/core/runner.py | 6 +++--- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'robusta_krr') diff --git a/robusta_krr/core/models/config.py b/robusta_krr/core/models/config.py index 1d4e6a5..dd84423 100644 --- a/robusta_krr/core/models/config.py +++ b/robusta_krr/core/models/config.py @@ -65,7 +65,6 @@ class Config(pd.BaseSettings): # Internal inside_cluster: bool = False _logging_console: Optional[Console] = pd.PrivateAttr(None) - _result_console: Optional[Console] = pd.PrivateAttr(None) def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) @@ -132,12 +131,6 @@ class Config(pd.BaseSettings): self._logging_console = Console(file=sys.stderr if self.log_to_stderr else sys.stdout, width=self.width) return self._logging_console - @property - def result_console(self) -> Console: - if getattr(self, "_result_console") is None: - self._result_console = Console(file=sys.stdout, width=self.width) - return self._result_console - def load_kubeconfig(self) -> None: try: config.load_incluster_config() diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index 4aacfb5..f651aa8 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -8,6 +8,7 @@ from concurrent.futures import ThreadPoolExecutor from typing import Optional, Union from datetime import timedelta from prometrix import PrometheusNotFound +from rich.console import Console from slack_sdk import WebClient from robusta_krr.core.abstract.strategies import ResourceRecommendation, RunResult @@ -89,9 +90,8 @@ class Runner: elif settings.slack_output: file_name = settings.slack_output with open(file_name, "w") as target_file: - sys.stdout = target_file - custom_print(formatted, rich=rich, force=True) - sys.stdout = sys.stdout + console = Console(file=target_file, width=settings.width) + console.print(formatted) if settings.slack_output: client = WebClient(os.environ["SLACK_BOT_TOKEN"]) warnings.filterwarnings("ignore", category=UserWarning) -- cgit v1.2.3