Skip to content

Commit 252a381

Browse files
Revert "feat(aci): Write to IncidentGroupOpenPeriod (#97621)"
This reverts commit 433839b. Co-authored-by: ceorourke <[email protected]>
1 parent 519b92c commit 252a381

File tree

5 files changed

+0
-560
lines changed

5 files changed

+0
-560
lines changed

src/sentry/incidents/logic.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
from sentry.utils.not_set import NOT_SET, NotSet
102102
from sentry.utils.snuba import is_measurement
103103
from sentry.workflow_engine.endpoints.validators.utils import toggle_detector
104-
from sentry.workflow_engine.models import IncidentGroupOpenPeriod
105104
from sentry.workflow_engine.models.detector import Detector
106105

107106
# We can return an incident as "windowed" which returns a range of points around the start of the incident
@@ -182,10 +181,6 @@ def create_incident(
182181
incident_type=incident_type.value,
183182
)
184183

185-
# If this is a metric alert incident, check for pending group relationships
186-
if alert_rule and incident_type == IncidentType.ALERT_TRIGGERED:
187-
IncidentGroupOpenPeriod.create_pending_relationships_for_incident(incident, alert_rule)
188-
189184
return incident
190185

191186

src/sentry/issues/ingest.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
save_grouphash_and_group,
2323
)
2424
from sentry.eventstore.models import Event, GroupEvent, augment_message_with_occurrence
25-
from sentry.incidents.grouptype import MetricIssue
2625
from sentry.issues.grouptype import FeedbackGroup, should_create_group
2726
from sentry.issues.issue_occurrence import IssueOccurrence, IssueOccurrenceData
2827
from sentry.issues.priority import PriorityChangeReason, update_priority
@@ -35,7 +34,6 @@
3534
from sentry.utils import json, metrics, redis
3635
from sentry.utils.strings import truncatechars
3736
from sentry.utils.tag_normalization import normalized_sdk_tag_from_event
38-
from sentry.workflow_engine.models import IncidentGroupOpenPeriod
3937
from sentry.workflow_engine.models.detector_group import DetectorGroup
4038

4139
issue_rate_limiter = RedisSlidingWindowRateLimiter(
@@ -72,23 +70,6 @@ def save_issue_occurrence(
7270
group_info.group.project, environment, release, [group_info]
7371
)
7472
_get_or_create_group_release(environment, release, event, [group_info])
75-
76-
# Create IncidentGroupOpenPeriod relationship for metric issues
77-
if occurrence.type == MetricIssue:
78-
open_period = get_latest_open_period(group_info.group)
79-
if open_period:
80-
IncidentGroupOpenPeriod.create_from_occurrence(
81-
occurrence, group_info.group, open_period
82-
)
83-
else:
84-
logger.error(
85-
"save_issue_occurrence.no_open_period",
86-
extra={
87-
"group_id": group_info.group.id,
88-
"occurrence_id": occurrence.id,
89-
},
90-
)
91-
9273
send_issue_occurrence_to_eventstream(event, occurrence, group_info)
9374
return occurrence, group_info
9475

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import logging
2-
31
from django.db import models
42
from django.db.models import Q
53

@@ -10,12 +8,6 @@
108
FlexibleForeignKey,
119
region_silo_model,
1210
)
13-
from sentry.incidents.models.alert_rule import AlertRule
14-
from sentry.incidents.models.incident import Incident
15-
from sentry.models.groupopenperiod import GroupOpenPeriod
16-
from sentry.workflow_engine.models.alertrule_detector import AlertRuleDetector
17-
18-
logger = logging.getLogger(__name__)
1911

2012

2113
@region_silo_model
@@ -40,157 +32,3 @@ class Meta:
4032
name="inc_id_inc_identifier_together",
4133
)
4234
]
43-
44-
@classmethod
45-
def create_from_occurrence(self, occurrence, group, open_period):
46-
"""
47-
Creates an IncidentGroupOpenPeriod relationship from an issue occurrence.
48-
This method handles the case where the incident might not exist yet.
49-
50-
Args:
51-
occurrence: The IssueOccurrence that triggered the group creation
52-
group: The Group that was created
53-
open_period: The GroupOpenPeriod for the group
54-
"""
55-
try:
56-
# Extract alert_id from evidence_data using the detector_id
57-
detector_id = occurrence.evidence_data.get("detector_id")
58-
if detector_id:
59-
alert_id = AlertRuleDetector.objects.get(detector_id=detector_id).alert_rule_id
60-
else:
61-
raise Exception("No detector_id found in evidence_data for metric issue")
62-
63-
# Try to find the active incident for this alert rule and project
64-
try:
65-
alert_rule = AlertRule.objects.get(id=alert_id)
66-
incident = Incident.objects.get_active_incident(
67-
alert_rule=alert_rule,
68-
project=group.project,
69-
)
70-
except AlertRule.DoesNotExist:
71-
logger.warning(
72-
"AlertRule not found for alert_id",
73-
extra={
74-
"alert_id": alert_id,
75-
"group_id": group.id,
76-
},
77-
)
78-
incident = None
79-
80-
if incident:
81-
# Incident exists, create the relationship immediately
82-
return self.create_relationship(incident, open_period)
83-
else:
84-
# Incident doesn't exist yet, create a placeholder relationship
85-
# that will be updated when the incident is created
86-
return self.create_placeholder_relationship(detector_id, open_period, group.project)
87-
88-
except Exception as e:
89-
logger.exception(
90-
"Failed to create IncidentGroupOpenPeriod relationship",
91-
extra={
92-
"group_id": group.id,
93-
"occurrence_id": occurrence.id,
94-
"error": str(e),
95-
},
96-
)
97-
return None
98-
99-
@classmethod
100-
def create_relationship(self, incident, open_period):
101-
"""
102-
Creates IncidentGroupOpenPeriod relationship.
103-
104-
Args:
105-
incident: The Incident to link
106-
open_period: The GroupOpenPeriod to link
107-
"""
108-
try:
109-
incident_group_open_period, _ = self.objects.get_or_create(
110-
group_open_period=open_period,
111-
defaults={
112-
"incident_id": incident.id,
113-
"incident_identifier": incident.identifier,
114-
},
115-
)
116-
117-
return incident_group_open_period
118-
119-
except Exception as e:
120-
logger.exception(
121-
"Failed to create/update IncidentGroupOpenPeriod relationship",
122-
extra={
123-
"incident_id": incident.id,
124-
"open_period_id": open_period.id,
125-
"error": str(e),
126-
},
127-
)
128-
return None
129-
130-
@classmethod
131-
def create_placeholder_relationship(self, detector_id, open_period, project):
132-
"""
133-
Creates a placeholder relationship when the incident doesn't exist yet.
134-
This will be updated when the incident is created.
135-
136-
Args:
137-
detector_id: The detector ID
138-
open_period: The GroupOpenPeriod to link
139-
project: The project for the group
140-
"""
141-
try:
142-
# Store the alert_id in the open_period data for later lookup
143-
data = open_period.data or {}
144-
data["pending_incident_detector_id"] = detector_id
145-
open_period.update(data=data)
146-
147-
return None
148-
149-
except Exception as e:
150-
logger.exception(
151-
"Failed to create placeholder IncidentGroupOpenPeriod relationship",
152-
extra={
153-
"detector_id": detector_id,
154-
"open_period_id": open_period.id,
155-
"error": str(e),
156-
},
157-
)
158-
return None
159-
160-
@classmethod
161-
def create_pending_relationships_for_incident(self, incident, alert_rule):
162-
"""
163-
Creates IncidentGroupOpenPeriod relationships for any groups that were created
164-
before the incident. This handles the timing issue where groups might be created
165-
before incidents.
166-
167-
Args:
168-
incident: The Incident that was just created
169-
alert_rule: The AlertRule that triggered the incident
170-
"""
171-
try:
172-
# Find all open periods that have a pending incident detector_id for this alert rule
173-
detector_id = AlertRuleDetector.objects.get(alert_rule_id=alert_rule.id).detector_id
174-
pending_open_periods = GroupOpenPeriod.objects.filter(
175-
data__pending_incident_detector_id=detector_id,
176-
group__project__in=incident.projects.all(),
177-
)
178-
179-
for open_period in pending_open_periods:
180-
# Create the relationship
181-
relationship = self.create_relationship(incident, open_period)
182-
if relationship:
183-
# Remove the pending flag from the open_period data
184-
data = open_period.data or {}
185-
data.pop("pending_incident_detector_id", None)
186-
open_period.update(data=data)
187-
188-
except Exception as e:
189-
logger.exception(
190-
"Failed to create pending IncidentGroupOpenPeriod relationships",
191-
extra={
192-
"incident_id": incident.id,
193-
"alert_rule_id": alert_rule.id,
194-
"error": str(e),
195-
},
196-
)

tests/sentry/issues/test_ingest_incident_integration.py

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)