|
10 | 10 | MonitorCheckInMissed, |
11 | 11 | MonitorCheckInTimeout, |
12 | 12 | ) |
| 13 | +from sentry.issues.ingest import process_occurrence_data |
| 14 | +from sentry.models.groupassignee import GroupAssignee |
| 15 | +from sentry.models.grouphash import GroupHash |
13 | 16 | from sentry.monitors.constants import SUBTITLE_DATETIME_FORMAT |
14 | 17 | from sentry.monitors.logic.mark_failed import mark_failed |
15 | 18 | from sentry.monitors.models import ( |
@@ -898,3 +901,59 @@ def test_mark_failed_issue_threshold_disabled(self, mock_produce_occurrence_to_k |
898 | 901 |
|
899 | 902 | assert len(mock_produce_occurrence_to_kafka.mock_calls) == 0 |
900 | 903 | 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