summaryrefslogtreecommitdiff
path: root/examples/custom_strategy.py
diff options
context:
space:
mode:
authorПавел Жуков <33721692+LeaveMyYard@users.noreply.github.com>2023-04-06 11:51:11 +0300
committerПавел Жуков <33721692+LeaveMyYard@users.noreply.github.com>2023-04-06 11:51:11 +0300
commitfcc008b2907c3ca1af19f2861c7c719598ad4f62 (patch)
tree084e6634d0672e66cb08cb4f321418920be7a5f5 /examples/custom_strategy.py
parent9fdb8523eec37799ad0f866b754ce34cddc2a64e (diff)
Make the custom strategy simpler
Diffstat (limited to 'examples/custom_strategy.py')
-rw-r--r--examples/custom_strategy.py20
1 files changed, 4 insertions, 16 deletions
diff --git a/examples/custom_strategy.py b/examples/custom_strategy.py
index e426477..f88edd3 100644
--- a/examples/custom_strategy.py
+++ b/examples/custom_strategy.py
@@ -17,31 +17,19 @@ from robusta_krr.core.abstract.strategies import (
class CustomStrategySettings(StrategySettings):
- cpu_percentile: Decimal = pd.Field(99, gt=0, description="The percentile to use for the request recommendation.")
- memory_percentile: Decimal = pd.Field(
- 105, gt=0, description="The percentile to use for the request recommendation."
- )
+ param_1: Decimal = pd.Field(99, gt=0, description="First example parameter")
+ param_2: Decimal = pd.Field(105_000, gt=0, description="Second example parameter")
class CustomStrategy(BaseStrategy[CustomStrategySettings]):
__display_name__ = "custom"
def run(self, history_data: HistoryData, object_data: K8sObjectData) -> RunResult:
- cpu_usage = self._calculate_percentile(history_data[ResourceType.CPU], self.settings.cpu_percentile)
- memory_usage = self._calculate_percentile(history_data[ResourceType.Memory], self.settings.memory_percentile)
-
return {
- ResourceType.CPU: ResourceRecommendation(request=cpu_usage, limit=None),
- ResourceType.Memory: ResourceRecommendation(request=memory_usage, limit=memory_usage),
+ ResourceType.CPU: ResourceRecommendation(request=self.settings.param_1, limit=None),
+ ResourceType.Memory: ResourceRecommendation(request=self.settings.param_2, limit=self.settings.param_2),
}
- def _calculate_percentile(self, data: dict[str, list[Decimal]], percentile: Decimal) -> Decimal:
- data_ = [value for values in data.values() for value in values]
- if len(data_) == 0:
- return Decimal("NaN")
-
- return max(data_) * percentile / 100
-
# Running this file will register the strategy and make it available to the CLI
if __name__ == "__main__":