feat(workflow_engine): Add in hook for producing occurrences from the stateful detector#11
Conversation
… stateful detector (#80168) This adds a hook that can be implemented to produce an occurrence specific to the detector that is subclassing the StatefulDetector. Also change the signature of evaluate to return a dict keyed by groupkey instead of a list. This helps avoid the chance of duplicate results for the same group key. <!-- Describe your PR here. -->
There was a problem hiding this comment.
Pull request overview
This PR refactors the metric alert detection system to use group-based result tracking with dictionaries instead of list-based aggregation, and adds support for producing issue occurrences from the stateful detector.
Changes:
- Modified
DetectorEvaluationResulthandling to use dictionaries keyed byDetectorGroupKeyinstead of lists - Implemented
build_occurrence_and_event_dataabstract method in stateful detector handlers to generate issue occurrences - Added test coverage for occurrence production with mocked Kafka calls
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/sentry/workflow_engine/processors/test_detector.py |
Updated tests to work with dict-based results and added occurrence/event data validation |
src/sentry/workflow_engine/processors/detector.py |
Changed return type from list to dict, removed duplicate key checking, added occurrence building logic |
src/sentry/workflow_engine/models/detector.py |
Added group_type property to Detector model |
src/sentry/incidents/grouptype.py |
Changed MetricAlertDetectorHandler to extend StatefulDetectorHandler |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| event_data, | ||
| ) | ||
| occurrence_2, event_data_2 = build_mock_occurrence_and_event( | ||
| detector.detector_handler, "group_2", 6, PriorityLevel.HIGH |
There was a problem hiding this comment.
The value passed to build_mock_occurrence_and_event should be 10, not 6, to match the group_vals for 'group_2' which is set to 10 on line 177.
| detector.detector_handler, "group_2", 6, PriorityLevel.HIGH | |
| detector.detector_handler, "group_2", 10, PriorityLevel.HIGH |
| self, data_packet: DataPacket[T] | ||
| ) -> dict[DetectorGroupKey, DetectorEvaluationResult]: | ||
| """ | ||
| Evaluates a given data packet and returns a list of `DetectorEvaluationResult`. |
There was a problem hiding this comment.
The docstring refers to returning 'a list' but the method now returns a dict[DetectorGroupKey, DetectorEvaluationResult]. Update the documentation to reflect the correct return type.
Test 10
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.
Replicated from ai-code-review-evaluation/sentry-coderabbit#10