feat(workflow_engine): Add in hook for producing occurrences from the stateful detector#9
Open
everettbu wants to merge 1 commit into
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. -->
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a hook for producing occurrences from the stateful detector by adding a new abstract method to generate issue occurrences and updating the detector evaluation process to handle occurrence creation.
- Adds a new abstract method
build_occurrence_and_event_data()to theStatefulDetectorHandlerclass - Updates the detector evaluation logic to create occurrences when detectors become active (non-OK status)
- Modifies the return type of
evaluate()methods from lists to dictionaries for better group key management
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/sentry/workflow_engine/processors/detector.py | Adds occurrence creation hook and updates evaluation logic to use dictionaries |
| src/sentry/workflow_engine/models/detector.py | Adds group_type property for accessing detector's group type |
| src/sentry/incidents/grouptype.py | Updates MetricAlertDetectorHandler to inherit from StatefulDetectorHandler |
| tests/sentry/workflow_engine/processors/test_detector.py | Updates tests to handle new dictionary return types and adds occurrence verification |
Comments suppressed due to low confidence (2)
src/sentry/workflow_engine/processors/detector.py:289
- The variable name 'result' is ambiguous since it shadows the existing 'result' variable that was assigned None on line 289. Consider using a more specific name like 'occurrence_or_status_change' or 'detector_result'.
result: StatusChangeMessage | IssueOccurrence
src/sentry/incidents/grouptype.py:11
- The MetricAlertDetectorHandler class inherits from StatefulDetectorHandler but doesn't implement the required abstract methods. This will cause runtime errors when instantiated. The class needs to implement 'get_dedupe_value', 'get_group_key_values', and 'build_occurrence_and_event_data' methods.
class MetricAlertDetectorHandler(StatefulDetectorHandler[QuerySubscriptionUpdate]):
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Test 10