-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Test: workflow-engine-stateful-detector-after #316
Closed
admin-coderabbit
wants to merge
1
commit into
workflow-engine-stateful-detector-before
from
workflow-engine-stateful-detector-after
+249
−151
Closed
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 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
| 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 | ||
| if new_status == DetectorPriorityLevel.OK: | ||
| # If we've determined that we're now ok, we just want to resolve the issue | ||
| result = StatusChangeMessage( | ||
|
|
@@ -298,8 +295,10 @@ def evaluate_group_key_value( | |
| new_status=GroupStatus.RESOLVED, | ||
| new_substatus=None, | ||
| ) | ||
|
|
||
| # TODO: Add hook here for generating occurrence | ||
| else: | ||
| result, event_data = self.build_occurrence_and_event_data( | ||
| group_key, value, PriorityLevel(new_status) | ||
| ) | ||
|
Comment on lines
+298
to
+301
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Compare the enum values of DetectorPriorityLevel and PriorityLevel
echo "=== DetectorPriorityLevel ==="
rg -n "class DetectorPriorityLevel" -A 20 --type py
echo -e "\n=== PriorityLevel ==="
rg -n "class PriorityLevel" -A 20 --type pyRepository: admin-coderabbit/coderabbit-sentry-mirror Length of output: 5279 Fix unsafe enum conversion
Handle the 🤖 Prompt for AI Agents |
||
| return DetectorEvaluationResult( | ||
| group_key=group_key, | ||
| is_active=is_active, | ||
|
|
||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 1129
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 2988
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 1378
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 8103
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 136
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 149
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 14602
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 134
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 2511
Stale TODO and incomplete abstract method implementations.
Line 10: The TODO comment states "This will be a stateful detector when we build that abstraction" — but
MetricAlertDetectorHandleralready extendsStatefulDetectorHandler. This comment is misleading and should be updated or removed.More critically,
StatefulDetectorHandlerdeclares four abstract methods:counter_names,get_dedupe_value,get_group_key_values, andbuild_occurrence_and_event_data. SinceMetricAlertDetectorHandlercontains onlypass, attempting to instantiate it (which occurs inDetector.detector_handlerviagroup_type.detector_handler(self)) will raiseTypeError: Can't instantiate abstract class MetricAlertDetectorHandler with abstract methods [...].While
MetricAlertFireis not currently wired to any detectors (as noted in the comment on line 15), this incomplete code should be addressed before merge. Implement the required abstract methods or keepMetricAlertDetectorHandleras a concreteDetectorHandlersubclass until the abstraction is ready.🤖 Prompt for AI Agents