Просмотр исходного кода

fix(crons): Only detect active and non-muted crons for brokenness (#66843)

An oversight on my end, we should only be running these detections on
non-muted and non-disabled monitors
David Wang 1 год назад
Родитель
Сommit
e7d900400e
2 измененных файлов с 36 добавлено и 0 удалено
  1. 3 0
      src/sentry/monitors/tasks.py
  2. 33 0
      tests/sentry/monitors/test_tasks.py

+ 3 - 0
src/sentry/monitors/tasks.py

@@ -425,6 +425,9 @@ def detect_broken_monitor_envs():
     open_incidents_qs = MonitorIncident.objects.select_related("monitor").filter(
         resolving_checkin=None,
         starting_timestamp__lte=(current_time - timedelta(days=NUM_DAYS_BROKEN_PERIOD)),
+        monitor__status=ObjectStatus.ACTIVE,
+        monitor__is_muted=False,
+        monitor_environment__is_muted=False,
         # TODO(davidenwang): When we want to email users, remove this filter
         monitorenvbrokendetection__isnull=True,
     )

+ 33 - 0
tests/sentry/monitors/test_tasks.py

@@ -1313,3 +1313,36 @@ class MonitorDetectBrokenMonitorEnvTaskTest(TestCase):
 
         detect_broken_monitor_envs()
         assert len(MonitorEnvBrokenDetection.objects.filter(monitor_incident=incident)) == 0
+
+    @with_feature("organizations:crons-broken-monitor-detection")
+    def test_does_not_create_for_disabled_monitor(self):
+        monitor, monitor_environment = self.create_monitor_and_env()
+        monitor.status = ObjectStatus.DISABLED
+        monitor.save()
+
+        first_checkin = MonitorCheckIn.objects.create(
+            monitor=monitor,
+            monitor_environment=monitor_environment,
+            project_id=self.project.id,
+            status=CheckInStatus.ERROR,
+            date_added=django_timezone.now() - timedelta(days=14),
+        )
+        incident = MonitorIncident.objects.create(
+            monitor=monitor,
+            monitor_environment=monitor_environment,
+            starting_checkin=first_checkin,
+            starting_timestamp=first_checkin.date_added,
+            grouphash=hash_from_values([uuid.uuid4()]),
+        )
+
+        for i in range(4, -1, -1):
+            MonitorCheckIn.objects.create(
+                monitor=monitor,
+                monitor_environment=monitor_environment,
+                project_id=self.project.id,
+                status=CheckInStatus.ERROR,
+                date_added=django_timezone.now() - timedelta(days=i),
+            )
+
+        detect_broken_monitor_envs()
+        assert len(MonitorEnvBrokenDetection.objects.filter(monitor_incident=incident)) == 0