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: type error in throttle mechanism #1066

Merged
merged 7 commits into from
Apr 9, 2024
Merged
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
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)
Loading