Skip to content

Commit 5b5390f

Browse files
authored
feat(crons): Send assignee to issue platform (#69160)
Issue platform now supports sending assignee, so we can start sending it when we create an occurrence.
1 parent a008f84 commit 5b5390f

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/sentry/monitors/logic/mark_failed.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ def create_issue_platform_occurrence(
251251
if last_successful_checkin:
252252
last_successful_checkin_timestamp = last_successful_checkin.date_added.isoformat()
253253

254+
assignee = None
255+
# TODO: Remove org fetch after we remove feature flag
256+
organization = Organization.objects.get_from_cache(id=monitor_env.monitor.organization_id)
257+
if features.has("organizations:crons-ownership", organization):
258+
assignee = monitor_env.monitor.owner_actor
259+
254260
occurrence = IssueOccurrence(
255261
id=uuid.uuid4().hex,
256262
resource_id=None,
@@ -275,6 +281,7 @@ def create_issue_platform_occurrence(
275281
culprit=occurrence_data["reason"],
276282
detection_time=current_timestamp,
277283
level=occurrence_data["level"],
284+
assignee=assignee,
278285
)
279286

280287
if failed_checkin.trace_id:

tests/sentry/monitors/logic/test_mark_failed.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
MonitorCheckInMissed,
1111
MonitorCheckInTimeout,
1212
)
13+
from sentry.issues.ingest import process_occurrence_data
14+
from sentry.models.groupassignee import GroupAssignee
15+
from sentry.models.grouphash import GroupHash
1316
from sentry.monitors.constants import SUBTITLE_DATETIME_FORMAT
1417
from sentry.monitors.logic.mark_failed import mark_failed
1518
from sentry.monitors.models import (
@@ -898,3 +901,59 @@ def test_mark_failed_issue_threshold_disabled(self, mock_produce_occurrence_to_k
898901

899902
assert len(mock_produce_occurrence_to_kafka.mock_calls) == 0
900903
assert monitor_environment.active_incident is not None
904+
905+
@with_feature("organizations:issue-platform")
906+
@with_feature("organizations:crons-ownership")
907+
def test_mark_failed_issue_assignment(self):
908+
monitor = Monitor.objects.create(
909+
name="test monitor",
910+
organization_id=self.organization.id,
911+
project_id=self.project.id,
912+
type=MonitorType.CRON_JOB,
913+
config={
914+
"schedule": [1, "month"],
915+
"schedule_type": ScheduleType.INTERVAL,
916+
"max_runtime": None,
917+
"checkin_margin": None,
918+
},
919+
owner_user_id=self.user.id,
920+
)
921+
monitor_environment = MonitorEnvironment.objects.create(
922+
monitor=monitor,
923+
environment_id=self.environment.id,
924+
status=MonitorStatus.OK,
925+
)
926+
927+
MonitorCheckIn.objects.create(
928+
monitor=monitor,
929+
monitor_environment=monitor_environment,
930+
project_id=self.project.id,
931+
status=CheckInStatus.OK,
932+
)
933+
934+
checkin = MonitorCheckIn.objects.create(
935+
monitor=monitor,
936+
monitor_environment=monitor_environment,
937+
project_id=self.project.id,
938+
status=CheckInStatus.IN_PROGRESS,
939+
)
940+
mark_failed(checkin, ts=checkin.date_added)
941+
942+
# failure has hit threshold, monitor should be in a failed state
943+
monitor_environment = MonitorEnvironment.objects.get(id=monitor_environment.id)
944+
assert monitor_environment.status == MonitorStatus.ERROR
945+
946+
# check that an incident has been created correctly
947+
monitor_incidents = MonitorIncident.objects.filter(monitor_environment=monitor_environment)
948+
assert len(monitor_incidents) == 1
949+
monitor_incident = monitor_incidents.first()
950+
assert monitor_incident.starting_checkin == checkin
951+
assert monitor_incident.starting_timestamp == checkin.date_added
952+
assert monitor_incident.grouphash == monitor_environment.active_incident.grouphash
953+
occurrence_data = {"fingerprint": [monitor_environment.active_incident.grouphash]}
954+
process_occurrence_data(occurrence_data)
955+
issue_platform_hash = occurrence_data["fingerprint"][0]
956+
957+
grouphash = GroupHash.objects.get(hash=issue_platform_hash)
958+
group_assignee = GroupAssignee.objects.get(group_id=grouphash.group_id)
959+
assert group_assignee.user_id == monitor.owner_user_id

0 commit comments

Comments
 (0)