Skip to content

ref(alerts): Pull code out into smaller functions #94654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ceorourke
Copy link
Member

@ceorourke ceorourke commented Jun 30, 2025

We're using a lot of flags and processing regular metric alerts, dynamic metric alerts, and workflow engine - the code in process_update was getting difficult to read. This PR pulls out some code into their own functions to make it more readable.

@ceorourke ceorourke requested a review from a team as a code owner June 30, 2025 20:49
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 30, 2025
@ceorourke ceorourke requested a review from a team June 30, 2025 20:50
cursor[bot]

This comment was marked as outdated.

Copy link

codecov bot commented Jun 30, 2025

Codecov Report

Attention: Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/incidents/subscription_processor.py 96.07% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #94654    +/-   ##
========================================
  Coverage   87.92%   87.93%            
========================================
  Files       10418    10422     +4     
  Lines      602751   603144   +393     
  Branches    23451    23451            
========================================
+ Hits       529993   530363   +370     
- Misses      72252    72275    +23     
  Partials      506      506            

@ceorourke ceorourke marked this pull request as draft June 30, 2025 21:27
@ceorourke ceorourke marked this pull request as ready for review June 30, 2025 22:20
cursor[bot]

This comment was marked as outdated.

@ceorourke
Copy link
Member Author

ceorourke commented Jun 30, 2025

cursor might be right but I didn't change anything - can address if it's a bug later

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Metric Recording Inconsistency

In handle_trigger_anomalies, the metrics.incr call for resolve events was reordered to occur after trigger_resolve_threshold. This prevents the resolve metric from being recorded if trigger_resolve_threshold raises an exception. This behavior is inconsistent with handle_trigger_alerts, where metrics are incremented before the trigger call.

src/sentry/incidents/subscription_processor.py#L288-L293

if not has_anomaly and self.active_incident and trigger_matches_status:
incident_trigger = self.trigger_resolve_threshold(trigger, aggregation_value)
metrics.incr(
"incidents.alert_rules.threshold.resolve",
tags={"detection_type": self.alert_rule.detection_type},
)

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant