-
Notifications
You must be signed in to change notification settings - Fork 0
feat(workflow_engine): Add in hook for producing occurrences from the stateful detector #7
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
Open
akshayutture-augment
wants to merge
1
commit into
workflow-engine-stateful-detector-before
Choose a base branch
from
workflow-engine-stateful-detector-after
base: workflow-engine-stateful-detector-before
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |||||
| from sentry.issues.producer import PayloadType, produce_occurrence_to_kafka | ||||||
| from sentry.issues.status_change_message import StatusChangeMessage | ||||||
| from sentry.models.group import GroupStatus | ||||||
| from sentry.types.group import PriorityLevel | ||||||
| from sentry.utils import metrics, redis | ||||||
| from sentry.utils.function_cache import cache_func_for_models | ||||||
| from sentry.utils.iterators import chunked | ||||||
|
|
@@ -45,7 +46,7 @@ class DetectorEvaluationResult: | |||||
|
|
||||||
| def process_detectors( | ||||||
| data_packet: DataPacket, detectors: list[Detector] | ||||||
| ) -> list[tuple[Detector, list[DetectorEvaluationResult]]]: | ||||||
| ) -> list[tuple[Detector, dict[DetectorGroupKey, DetectorEvaluationResult]]]: | ||||||
| results = [] | ||||||
|
|
||||||
| for detector in detectors: | ||||||
|
|
@@ -55,25 +56,11 @@ def process_detectors( | |||||
| continue | ||||||
|
|
||||||
| detector_results = handler.evaluate(data_packet) | ||||||
| detector_group_keys = set() | ||||||
|
|
||||||
| for result in detector_results: | ||||||
| if result.group_key in detector_group_keys: | ||||||
| # This shouldn't happen - log an error and continue on, but we should investigate this. | ||||||
| logger.error( | ||||||
| "Duplicate detector state group keys found", | ||||||
| extra={ | ||||||
| "detector_id": detector.id, | ||||||
| "group_key": result.group_key, | ||||||
| }, | ||||||
| ) | ||||||
| continue | ||||||
|
|
||||||
| for result in detector_results.values(): | ||||||
| if result.result is not None: | ||||||
| create_issue_occurrence_from_result(result) | ||||||
|
|
||||||
| detector_group_keys.add(result.group_key) | ||||||
|
|
||||||
| if detector_results: | ||||||
| results.append((detector, detector_results)) | ||||||
|
|
||||||
|
|
@@ -136,7 +123,9 @@ def __init__(self, detector: Detector): | |||||
| self.conditions = [] | ||||||
|
|
||||||
| @abc.abstractmethod | ||||||
| def evaluate(self, data_packet: DataPacket[T]) -> list[DetectorEvaluationResult]: | ||||||
| def evaluate( | ||||||
| self, data_packet: DataPacket[T] | ||||||
| ) -> dict[DetectorGroupKey, DetectorEvaluationResult]: | ||||||
| pass | ||||||
|
|
||||||
| def commit_state_updates(self): | ||||||
|
|
@@ -174,6 +163,12 @@ def get_group_key_values(self, data_packet: DataPacket[T]) -> dict[str, int]: | |||||
| """ | ||||||
| pass | ||||||
|
|
||||||
| @abc.abstractmethod | ||||||
| def build_occurrence_and_event_data( | ||||||
| self, group_key: DetectorGroupKey, value: int, new_status: PriorityLevel | ||||||
| ) -> tuple[IssueOccurrence, dict[str, Any]]: | ||||||
| pass | ||||||
|
|
||||||
| def build_fingerprint(self, group_key) -> list[str]: | ||||||
| """ | ||||||
| Builds a fingerprint to uniquely identify a detected issue | ||||||
|
|
@@ -228,7 +223,9 @@ def get_state_data( | |||||
| ) | ||||||
| return results | ||||||
|
|
||||||
| def evaluate(self, data_packet: DataPacket[T]) -> list[DetectorEvaluationResult]: | ||||||
| def evaluate( | ||||||
| self, data_packet: DataPacket[T] | ||||||
| ) -> dict[DetectorGroupKey, DetectorEvaluationResult]: | ||||||
| """ | ||||||
| Evaluates a given data packet and returns a list of `DetectorEvaluationResult`. | ||||||
| There will be one result for each group key result in the packet, unless the | ||||||
|
|
@@ -237,13 +234,13 @@ def evaluate(self, data_packet: DataPacket[T]) -> list[DetectorEvaluationResult] | |||||
| dedupe_value = self.get_dedupe_value(data_packet) | ||||||
| group_values = self.get_group_key_values(data_packet) | ||||||
| all_state_data = self.get_state_data(list(group_values.keys())) | ||||||
| results = [] | ||||||
| results = {} | ||||||
| for group_key, group_value in group_values.items(): | ||||||
| result = self.evaluate_group_key_value( | ||||||
| group_key, group_value, all_state_data[group_key], dedupe_value | ||||||
| ) | ||||||
| if result: | ||||||
| results.append(result) | ||||||
| results[result.group_key] = result | ||||||
| return results | ||||||
|
|
||||||
| def evaluate_group_key_value( | ||||||
|
|
@@ -289,7 +286,7 @@ def evaluate_group_key_value( | |||||
| is_active = new_status != DetectorPriorityLevel.OK | ||||||
| self.enqueue_state_update(group_key, is_active, new_status) | ||||||
| event_data = None | ||||||
| result = None | ||||||
| result: StatusChangeMessage | IssueOccurrence | ||||||
|
||||||
| result: StatusChangeMessage | IssueOccurrence | |
| result |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The MetricAlertDetectorHandler class now inherits from StatefulDetectorHandler but provides no implementation for the required abstract methods (get_dedupe_value, get_group_key_values, and build_occurrence_and_event_data). This will cause runtime errors when instantiated. Either provide concrete implementations or add a comment explaining why this is intentionally incomplete.