|
@@ -43,22 +43,52 @@ def mark_ok(checkin: MonitorCheckIn, ts: datetime):
|
|
|
previous_checkin["status"] == CheckInStatus.OK
|
|
|
for previous_checkin in previous_checkins
|
|
|
)
|
|
|
+ else:
|
|
|
+ # Mark any open incidents as recovering by default
|
|
|
+ incident_recovering = True
|
|
|
|
|
|
- # Resolve the incident
|
|
|
- if incident_recovering:
|
|
|
- MonitorIncident.objects.filter(
|
|
|
- monitor_environment=monitor_env,
|
|
|
- grouphash=monitor_env.incident_grouphash,
|
|
|
- ).update(
|
|
|
- resolving_checkin=checkin,
|
|
|
- resolving_timestamp=checkin.date_added,
|
|
|
- )
|
|
|
+ # Resolve any open incidents
|
|
|
+ if incident_recovering:
|
|
|
+ # TODO(rjo100): Check for multiple open incidents where we only
|
|
|
+ # resolved if recovery_threshold was set and not faiure_issue_threshold
|
|
|
+ active_incidents = MonitorIncident.objects.filter(
|
|
|
+ monitor_environment=monitor_env,
|
|
|
+ resolving_checkin__isnull=True,
|
|
|
+ )
|
|
|
|
|
|
+ # Only send an occurrence if we have an active incident
|
|
|
+ for grouphash in active_incidents.values_list("grouphash", flat=True):
|
|
|
+ resolve_incident_group(grouphash, checkin.monitor.project_id)
|
|
|
+ if active_incidents.update(
|
|
|
+ resolving_checkin=checkin,
|
|
|
+ resolving_timestamp=checkin.date_added,
|
|
|
+ ):
|
|
|
params["last_state_change"] = ts
|
|
|
- else:
|
|
|
- # Don't update status if incident isn't recovered
|
|
|
- params.pop("status", None)
|
|
|
+ else:
|
|
|
+ # Don't update status if incident isn't recovered
|
|
|
+ params.pop("status", None)
|
|
|
|
|
|
MonitorEnvironment.objects.filter(id=monitor_env.id).exclude(last_checkin__gt=ts).update(
|
|
|
**params
|
|
|
)
|
|
|
+
|
|
|
+
|
|
|
+def resolve_incident_group(
|
|
|
+ fingerprint: str,
|
|
|
+ project_id: int,
|
|
|
+):
|
|
|
+ from sentry.issues.producer import PayloadType, produce_occurrence_to_kafka
|
|
|
+ from sentry.issues.status_change_message import StatusChangeMessage
|
|
|
+ from sentry.models.group import GroupStatus
|
|
|
+
|
|
|
+ status_change = StatusChangeMessage(
|
|
|
+ fingerprint=[fingerprint],
|
|
|
+ project_id=project_id,
|
|
|
+ new_status=GroupStatus.RESOLVED,
|
|
|
+ new_substatus=None,
|
|
|
+ )
|
|
|
+
|
|
|
+ produce_occurrence_to_kafka(
|
|
|
+ payload_type=PayloadType.STATUS_CHANGE,
|
|
|
+ status_change=status_change,
|
|
|
+ )
|