|
@@ -13,7 +13,9 @@ from sentry.issues.grouptype import (
|
|
|
MonitorCheckInTimeout,
|
|
|
)
|
|
|
from sentry.monitors.models import (
|
|
|
+ CheckInStatus,
|
|
|
Monitor,
|
|
|
+ MonitorCheckIn,
|
|
|
MonitorEnvironment,
|
|
|
MonitorEnvironmentLimitsExceeded,
|
|
|
MonitorFailure,
|
|
@@ -314,6 +316,13 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
status=monitor.status,
|
|
|
)
|
|
|
|
|
|
+ successful_check_in = MonitorCheckIn.objects.create(
|
|
|
+ monitor=monitor,
|
|
|
+ monitor_environment=monitor_environment,
|
|
|
+ project_id=self.project.id,
|
|
|
+ status=CheckInStatus.OK,
|
|
|
+ )
|
|
|
+
|
|
|
last_checkin = timezone.now()
|
|
|
assert monitor_environment.mark_failed(last_checkin=last_checkin)
|
|
|
|
|
@@ -328,7 +337,7 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
"project_id": self.project.id,
|
|
|
"fingerprint": [hash_from_values(["monitor", str(monitor.guid), "error"])],
|
|
|
"issue_title": f"Monitor failure: {monitor.name}",
|
|
|
- "subtitle": "",
|
|
|
+ "subtitle": "An error occurred during the last check-in.",
|
|
|
"resource_id": None,
|
|
|
"evidence_data": {},
|
|
|
"evidence_display": [
|
|
@@ -339,8 +348,8 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
"important": False,
|
|
|
},
|
|
|
{
|
|
|
- "name": "Last check-in",
|
|
|
- "value": last_checkin.isoformat(),
|
|
|
+ "name": "Last successful check-in",
|
|
|
+ "value": successful_check_in.date_added.isoformat(),
|
|
|
"important": False,
|
|
|
},
|
|
|
],
|
|
@@ -391,9 +400,17 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
environment=self.environment,
|
|
|
status=monitor.status,
|
|
|
)
|
|
|
+ successful_check_in = MonitorCheckIn.objects.create(
|
|
|
+ monitor=monitor,
|
|
|
+ monitor_environment=monitor_environment,
|
|
|
+ project_id=self.project.id,
|
|
|
+ status=CheckInStatus.OK,
|
|
|
+ )
|
|
|
last_checkin = timezone.now()
|
|
|
assert monitor_environment.mark_failed(
|
|
|
- last_checkin=last_checkin, reason=MonitorFailure.DURATION
|
|
|
+ last_checkin=last_checkin,
|
|
|
+ reason=MonitorFailure.DURATION,
|
|
|
+ occurrence_context={"duration": 30},
|
|
|
)
|
|
|
|
|
|
assert len(mock_produce_occurrence_to_kafka.mock_calls) == 1
|
|
@@ -407,7 +424,7 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
"project_id": self.project.id,
|
|
|
"fingerprint": [hash_from_values(["monitor", str(monitor.guid), "duration"])],
|
|
|
"issue_title": f"Monitor failure: {monitor.name}",
|
|
|
- "subtitle": "",
|
|
|
+ "subtitle": "Check-in exceeded maximum duration of 30 minutes.",
|
|
|
"resource_id": None,
|
|
|
"evidence_data": {},
|
|
|
"evidence_display": [
|
|
@@ -418,8 +435,8 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
"important": False,
|
|
|
},
|
|
|
{
|
|
|
- "name": "Last check-in",
|
|
|
- "value": last_checkin.isoformat(),
|
|
|
+ "name": "Last successful check-in",
|
|
|
+ "value": successful_check_in.date_added.isoformat(),
|
|
|
"important": False,
|
|
|
},
|
|
|
],
|
|
@@ -471,8 +488,11 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
status=monitor.status,
|
|
|
)
|
|
|
last_checkin = timezone.now()
|
|
|
+ expected_time = monitor.get_next_scheduled_checkin_without_margin(last_checkin)
|
|
|
assert monitor_environment.mark_failed(
|
|
|
- last_checkin=last_checkin, reason=MonitorFailure.MISSED_CHECKIN
|
|
|
+ last_checkin=last_checkin,
|
|
|
+ reason=MonitorFailure.MISSED_CHECKIN,
|
|
|
+ occurrence_context={"expected_time": expected_time},
|
|
|
)
|
|
|
|
|
|
monitor.refresh_from_db()
|
|
@@ -490,7 +510,7 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
"project_id": self.project.id,
|
|
|
"fingerprint": [hash_from_values(["monitor", str(monitor.guid), "missed_checkin"])],
|
|
|
"issue_title": f"Monitor failure: {monitor.name}",
|
|
|
- "subtitle": "",
|
|
|
+ "subtitle": f"No check-in reported at {expected_time}.",
|
|
|
"resource_id": None,
|
|
|
"evidence_data": {},
|
|
|
"evidence_display": [
|
|
@@ -501,8 +521,8 @@ class MonitorEnvironmentTestCase(TestCase):
|
|
|
"important": False,
|
|
|
},
|
|
|
{
|
|
|
- "name": "Last check-in",
|
|
|
- "value": last_checkin.isoformat(),
|
|
|
+ "name": "Last successful check-in",
|
|
|
+ "value": "None",
|
|
|
"important": False,
|
|
|
},
|
|
|
],
|