-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Action events, pending and failed scans, scans metadata (#1305)
* Add action event system, make krr and popeye use it * Bugfixes * Fix jsonb passing in requests * Set krr version to v1.7.0, remove logs, pass errors to metadata * Set default ScanReportBlock.metadata * Fix grade, should be a number * generic events emitter * class member instead of static * Update insert_scan_meta with _v2 postfix * Rework pubsub to be class-based * Minor fixes & improvements --------- Co-authored-by: Arik Alon <[email protected]>
- Loading branch information
1 parent
d85bb62
commit 977829f
Showing
16 changed files
with
295 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import abc | ||
|
||
|
||
class EventEmitter: | ||
@abc.abstractmethod | ||
def emit_event(self, event_name: str, **kwargs): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import abc | ||
|
||
|
||
class EventHandler: | ||
@abc.abstractmethod | ||
def handle_event(self, event_name: str, **kwargs): | ||
pass | ||
|
||
|
||
class EventSubscriber: | ||
@abc.abstractmethod | ||
def subscribe(self, event_name: str, handler: EventHandler): | ||
pass | ||
|
||
@abc.abstractmethod | ||
def unsubscribe(self, event_name: str, handler: EventHandler): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from collections import defaultdict | ||
from weakref import WeakSet | ||
|
||
from robusta.core.pubsub.event_emitter import EventEmitter | ||
from robusta.core.pubsub.event_subscriber import EventHandler, EventSubscriber | ||
|
||
|
||
class EventsPubSub(EventEmitter, EventSubscriber): | ||
def __init__(self) -> None: | ||
self.event_handlers: defaultdict[str, WeakSet[EventHandler]] = defaultdict(WeakSet) | ||
|
||
def subscribe(self, event_name: str, handler: EventHandler) -> None: | ||
self.event_handlers[event_name].add(handler) | ||
|
||
def unsubscribe(self, event_name: str, handler: EventHandler) -> None: | ||
self.event_handlers[event_name].remove(handler) | ||
|
||
def emit_event(self, event_name: str, **kwargs) -> None: | ||
for handler in self.event_handlers[event_name]: | ||
handler.handle_event(event_name, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.