Skip to content

Commit

Permalink
fix: type error in throttle mechanism (#1066)
Browse files Browse the repository at this point in the history
Co-authored-by: Tal <[email protected]>
Co-authored-by: Shahar Glazner <[email protected]>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent 5ba94de commit 9080812
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion keep/step/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _check_throttling(self, action_name):

throttling_type = throttling.get("type")
throttling_config = throttling.get("with")
throttle = ThrottleFactory.get_instance(throttling_type, throttling_config)
throttle = ThrottleFactory.get_instance(self.context_manager, throttling_type, throttling_config)
alert_id = self.context_manager.get_workflow_id()
return throttle.check_throttling(action_name, alert_id)

Expand Down
2 changes: 1 addition & 1 deletion keep/throttles/base_throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(
Args:
**kwargs: Provider configuration loaded from the provider yaml file.
"""
# Initalize logger for every provider
# Initialize logger for every provider
self.logger = logging.getLogger(self.__class__.__name__)
self.throttle_type = throttle_type
self.throttle_config = throttle_config
Expand Down
5 changes: 3 additions & 2 deletions keep/throttles/one_until_resolved_throttle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from keep.throttles.base_throttle import BaseThrottle
from keep.contextmanager.contextmanager import ContextManager


class OneUntilResolvedThrottle(BaseThrottle):
Expand All @@ -8,8 +9,8 @@ class OneUntilResolvedThrottle(BaseThrottle):
BaseThrottle (_type_): _description_
"""

def __init__(self, throttle_type, throttle_config):
super().__init__(throttle_type, throttle_config)
def __init__(self, context_manager: ContextManager, throttle_type, throttle_config):
super().__init__(context_manager=context_manager, throttle_type=throttle_type, throttle_config=throttle_config)

def check_throttling(self, action_name, alert_id, **kwargs) -> bool:
last_alert_run = self.context_manager.get_last_workflow_run(alert_id)
Expand Down
4 changes: 2 additions & 2 deletions keep/throttles/throttle_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

class ThrottleFactory:
@staticmethod
def get_instance(throttle_type, throttle_config) -> BaseThrottle:
def get_instance(context_manager, throttle_type, throttle_config) -> BaseThrottle:
module = importlib.import_module(f"keep.throttles.{throttle_type}_throttle")
throttle_class = getattr(
module, throttle_type.title().replace("_", "") + "Throttle"
)
return throttle_class(throttle_type, throttle_config)
return throttle_class(context_manager, throttle_type, throttle_config)

0 comments on commit 9080812

Please sign in to comment.