-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Test: workflow-engine-stateful-detector-after #325
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 | ||
|
Comment on lines
+166
to
+170
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
# First, find the definition of StatefulDetectorHandler
echo "=== Searching for StatefulDetectorHandler definition ==="
rg "class StatefulDetectorHandler" --type py -A 10
# Then search for all classes that inherit from StatefulDetectorHandler
echo -e "\n=== Searching for subclasses of StatefulDetectorHandler ==="
rg "StatefulDetectorHandler" --type py -B 2 | grep -E "^[^:]*class " | head -20Repository: admin-coderabbit/coderabbit-sentry-mirror Length of output: 1219 🏁 Script executed: #!/bin/bash
# Search for classes that inherit from StatefulDetectorHandler
echo "=== Finding all subclasses of StatefulDetectorHandler ==="
rg "class \w+\(.*StatefulDetectorHandler" --type py
# Search specifically for MetricAlertDetectorHandler
echo -e "\n=== Searching for MetricAlertDetectorHandler ==="
rg "class MetricAlertDetectorHandler" --type py -A 50
# Search for build_occurrence_and_event_data implementations
echo -e "\n=== Searching for build_occurrence_and_event_data implementations ==="
rg "def build_occurrence_and_event_data" --type py -B 5 -A 10Repository: admin-coderabbit/coderabbit-sentry-mirror Length of output: 4581 Critical: The new abstract method 🤖 Prompt for AI Agents |
||
|
|
||
| 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) | ||
| ) | ||
| 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: 136
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 1347
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 1016
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 6305
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 512
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 5496
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 603
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 155
🏁 Script executed:
Repository: admin-coderabbit/coderabbit-sentry-mirror
Length of output: 4723
Critical: Missing required abstract method implementations.
MetricAlertDetectorHandlerextendsStatefulDetectorHandlerbut does not implement any of the required abstract methods:counter_names(property)get_dedupe_value(data_packet)get_group_key_values(data_packet)build_occurrence_and_event_data(group_key, value, new_status)evaluate(data_packet)(inherited fromDetectorHandler)This will raise a
TypeErrorat instantiation: "Can't instantiate abstract class MetricAlertDetectorHandler with abstract methods..."When
MetricAlertFireis used with aDetector, thedetector.detector_handlerproperty will attempt to instantiateMetricAlertDetectorHandler(self), causing runtime failure. The TODO comment indicates this is placeholder code, but it's currently a latent defect waiting to break once integrated into detector workflows.🤖 Prompt for AI Agents