Skip to content

Conversation

@akshayutture-augment
Copy link

Test [new PR number opened]


Replicated from ai-code-review-evaluation/sentry-greptile#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. -->
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@akshayutture-augment
Copy link
Author

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Nov 14, 2025

Greptile Overview

Confidence Score: 1/5

  • This PR has a critical implementation issue that will cause runtime errors
  • MetricAlertDetectorHandler is now an incomplete abstract class missing all required method implementations - any attempt to instantiate it will fail
  • src/sentry/incidents/grouptype.py requires immediate attention - MetricAlertDetectorHandler must implement all abstract methods before this PR can be merged

Important Files Changed

File Analysis

Filename Score Overview
src/sentry/incidents/grouptype.py 0/5 Changed MetricAlertDetectorHandler to inherit from StatefulDetectorHandler but left it as empty pass class - missing all required abstract method implementations
src/sentry/workflow_engine/processors/detector.py 4/5 Added build_occurrence_and_event_data abstract method and implemented occurrence generation logic when detector status changes from OK

Sequence Diagram

sequenceDiagram
    participant DP as DataPacket
    participant PD as process_detectors
    participant DH as StatefulDetectorHandler
    participant EV as evaluate_group_key_value
    participant KF as produce_occurrence_to_kafka
    
    DP->>PD: process data packet
    PD->>DH: handler.evaluate(data_packet)
    DH->>DH: get_dedupe_value(data_packet)
    DH->>DH: get_group_key_values(data_packet)
    DH->>DH: get_state_data(group_keys)
    
    loop For each group_key
        DH->>EV: evaluate_group_key_value(group_key, value, state_data, dedupe)
        EV->>EV: Check if status changed
        
        alt Status changed to OK
            EV->>EV: Create StatusChangeMessage (RESOLVED)
        else Status changed to active
            EV->>DH: build_occurrence_and_event_data(group_key, value, new_status)
            DH-->>EV: Return IssueOccurrence + event_data
        end
        
        EV-->>DH: Return DetectorEvaluationResult
    end
    
    DH-->>PD: Return dict[group_key, result]
    
    loop For each result with result.result != None
        PD->>KF: create_issue_occurrence_from_result(result)
        KF->>KF: produce_occurrence_to_kafka
    end
    
    PD->>DH: handler.commit_state_updates()
    DH->>DH: Update Redis and DB state
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +11 to +12
class MetricAlertDetectorHandler(StatefulDetectorHandler[QuerySubscriptionUpdate]):
pass
Copy link

Choose a reason for hiding this comment

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

logic: MetricAlertDetectorHandler doesn't implement required abstract methods from StatefulDetectorHandler including build_occurrence_and_event_data, counter_names, get_dedupe_value, and get_group_key_values - will cause runtime errors when instantiated

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/sentry/incidents/grouptype.py
Line: 11:12

Comment:
**logic:** `MetricAlertDetectorHandler` doesn't implement required abstract methods from `StatefulDetectorHandler` including `build_occurrence_and_event_data`, `counter_names`, `get_dedupe_value`, and `get_group_key_values` - will cause runtime errors when instantiated

How can I resolve this? If you propose a fix, please make it concise.

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