-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ref(aci): pass WorkflowJob into process_workflows #82489
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
__all__ = [ | ||
"EventCreatedByDetectorConditionHandler", | ||
"EventSeenCountConditionHandler", | ||
"ReappearedEventConditionHandler", | ||
"RegressedEventConditionHandler", | ||
] | ||
|
||
from .group_event_handlers import ( | ||
EventCreatedByDetectorConditionHandler, | ||
EventSeenCountConditionHandler, | ||
) | ||
from .group_state_handlers import ReappearedEventConditionHandler, RegressedEventConditionHandler |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
from typing import Any | ||
|
||
from sentry.eventstore.models import GroupEvent | ||
from sentry.workflow_engine.models.data_condition import Condition | ||
from sentry.workflow_engine.registry import condition_handler_registry | ||
from sentry.workflow_engine.types import DataConditionHandler | ||
from sentry.workflow_engine.types import DataConditionHandler, WorkflowJob | ||
|
||
|
||
@condition_handler_registry.register(Condition.EVENT_CREATED_BY_DETECTOR) | ||
class EventCreatedByDetectorConditionHandler(DataConditionHandler[GroupEvent]): | ||
class EventCreatedByDetectorConditionHandler(DataConditionHandler[WorkflowJob]): | ||
@staticmethod | ||
def evaluate_value(event: GroupEvent, comparison: Any) -> bool: | ||
def evaluate_value(job: WorkflowJob, comparison: Any) -> bool: | ||
event = job["event"] | ||
if event.occurrence is None or event.occurrence.evidence_data is None: | ||
return False | ||
|
||
return event.occurrence.evidence_data.get("detector_id", None) == comparison | ||
|
||
|
||
@condition_handler_registry.register(Condition.EVENT_SEEN_COUNT) | ||
class EventSeenCountConditionHandler(DataConditionHandler[GroupEvent]): | ||
class EventSeenCountConditionHandler(DataConditionHandler[WorkflowJob]): | ||
@staticmethod | ||
def evaluate_value(event: GroupEvent, comparison: Any) -> bool: | ||
def evaluate_value(job: WorkflowJob, comparison: Any) -> bool: | ||
event = job["event"] | ||
return event.group.times_seen == comparison |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||||||||
from typing import Any | ||||||||||||
|
||||||||||||
from sentry.workflow_engine.models.data_condition import Condition | ||||||||||||
from sentry.workflow_engine.registry import condition_handler_registry | ||||||||||||
from sentry.workflow_engine.types import DataConditionHandler, WorkflowJob | ||||||||||||
|
||||||||||||
|
||||||||||||
@condition_handler_registry.register(Condition.REGRESSED_EVENT) | ||||||||||||
class RegressedEventConditionHandler(DataConditionHandler[WorkflowJob]): | ||||||||||||
@staticmethod | ||||||||||||
def evaluate_value(job: WorkflowJob, comparison: Any) -> bool: | ||||||||||||
state = job.get("group_state", None) | ||||||||||||
if state is None: | ||||||||||||
return False | ||||||||||||
|
||||||||||||
return state["is_regression"] == comparison | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it's guaranteed, the state is a typed dict too sentry/src/sentry/eventstream/base.py Lines 30 to 34 in a62dc3b
|
||||||||||||
|
||||||||||||
|
||||||||||||
@condition_handler_registry.register(Condition.REAPPEARED_EVENT) | ||||||||||||
class ReappearedEventConditionHandler(DataConditionHandler[WorkflowJob]): | ||||||||||||
@staticmethod | ||||||||||||
def evaluate_value(job: WorkflowJob, comparison: Any) -> bool: | ||||||||||||
has_reappeared = job.get("has_reappeared", None) | ||||||||||||
if has_reappeared is None: | ||||||||||||
return False | ||||||||||||
|
||||||||||||
return has_reappeared == comparison |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from enum import IntEnum | ||
from typing import TYPE_CHECKING, Any, Generic, TypeVar | ||
from typing import TYPE_CHECKING, Any, Generic, TypedDict, TypeVar | ||
|
||
from sentry.types.group import PriorityLevel | ||
|
||
if TYPE_CHECKING: | ||
from sentry.eventstore.models import GroupEvent | ||
from sentry.eventstream.base import GroupState | ||
from sentry.workflow_engine.models import Action, Detector | ||
|
||
T = TypeVar("T") | ||
|
@@ -28,9 +29,21 @@ class DetectorPriorityLevel(IntEnum): | |
ProcessedDataConditionResult = tuple[bool, list[DataConditionResult]] | ||
|
||
|
||
class EventJob(TypedDict): | ||
event: GroupEvent | ||
|
||
|
||
class WorkflowJob(EventJob, total=False): | ||
group_state: GroupState | ||
is_reprocessed: bool | ||
has_reappeared: bool | ||
has_alert: bool | ||
has_escalated: bool | ||
|
||
|
||
Comment on lines
+32
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the main piece of this PR |
||
class ActionHandler: | ||
@staticmethod | ||
def execute(group_event: GroupEvent, action: Action, detector: Detector) -> None: | ||
def execute(job: WorkflowJob, action: Action, detector: Detector) -> None: | ||
raise NotImplementedError | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't make mypy happy with this, it kept complaining the
event
didn't exist