@@ -552,38 +552,35 @@ def trigger_alert_threshold(
552
552
"""
553
553
self .trigger_alert_counts [trigger .id ] += 1
554
554
555
- if features .has (
556
- "organizations:metric-alert-rate-limiting" , self .subscription .project .organization
555
+ # If an incident was created for this rule, trigger type, and subscription
556
+ # within the last 10 minutes, don't make another one
557
+ last_it = (
558
+ IncidentTrigger .objects .filter (alert_rule_trigger = trigger )
559
+ .order_by ("-incident_id" )
560
+ .select_related ("incident" )
561
+ .first ()
562
+ )
563
+ last_incident : Incident | None = last_it .incident if last_it else None
564
+ last_incident_projects = (
565
+ [project .id for project in last_incident .projects .all ()] if last_incident else []
566
+ )
567
+ minutes_since_last_incident = (
568
+ (timezone .now () - last_incident .date_added ).seconds / 60 if last_incident else None
569
+ )
570
+ if (
571
+ last_incident
572
+ and self .subscription .project .id in last_incident_projects
573
+ and minutes_since_last_incident <= 10
557
574
):
558
- # If an incident was created for this rule, trigger type, and subscription
559
- # within the last 10 minutes, don't make another one
560
- last_it = (
561
- IncidentTrigger .objects .filter (alert_rule_trigger = trigger )
562
- .order_by ("-incident_id" )
563
- .select_related ("incident" )
564
- .first ()
565
- )
566
- last_incident : Incident | None = last_it .incident if last_it else None
567
- last_incident_projects = (
568
- [project .id for project in last_incident .projects .all ()] if last_incident else []
569
- )
570
- minutes_since_last_incident = (
571
- (timezone .now () - last_incident .date_added ).seconds / 60 if last_incident else None
575
+ metrics .incr (
576
+ "incidents.alert_rules.hit_rate_limit" ,
577
+ tags = {
578
+ "last_incident_id" : last_incident .id ,
579
+ "project_id" : self .subscription .project .id ,
580
+ "trigger_id" : trigger .id ,
581
+ },
572
582
)
573
- if (
574
- last_incident
575
- and self .subscription .project .id in last_incident_projects
576
- and minutes_since_last_incident <= 10
577
- ):
578
- metrics .incr (
579
- "incidents.alert_rules.hit_rate_limit" ,
580
- tags = {
581
- "last_incident_id" : last_incident .id ,
582
- "project_id" : self .subscription .project .id ,
583
- "trigger_id" : trigger .id ,
584
- },
585
- )
586
- return None
583
+ return None
587
584
if self .trigger_alert_counts [trigger .id ] >= self .alert_rule .threshold_period :
588
585
metrics .incr ("incidents.alert_rules.trigger" , tags = {"type" : "fire" })
589
586
0 commit comments