Skip to content

Conversation

@everettbu
Copy link
Contributor

@everettbu everettbu commented Jul 26, 2025

Test 10

… 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. -->
Copilot AI review requested due to automatic review settings July 26, 2025 19:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the StatefulDetectorHandler class
  • 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]):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants