Skip to content

Commit 3484af5

Browse files
committed
fix(uptime): fix cron monitor incident timing inconsistency
Ensure we use the same kind of 'time' for timestamps when computing the start and end of crons open periods. We currently use the consumer processing time for the start of an open period, but use the relay time for the close of it. In the event that a cron start is massively delayed due to backlogging, we wind up with the end coming before the start. This corrects that inconsistency by using the relay time for the open period start.
1 parent fa5d13f commit 3484af5

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/sentry/monitors/logic/incident_occurrence.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import uuid
55
from collections import Counter
66
from collections.abc import Mapping, Sequence
7-
from datetime import datetime, timezone
7+
from datetime import datetime
88
from typing import TYPE_CHECKING
99

1010
from arroyo import Topic as ArroyoTopic
@@ -138,8 +138,6 @@ def send_incident_occurrence(
138138
"""
139139
monitor_env = failed_checkin.monitor_environment
140140

141-
current_timestamp = datetime.now(timezone.utc)
142-
143141
# Get last successful check-in to show in evidence display
144142
last_successful_checkin_timestamp = "Never"
145143
last_successful_checkin = monitor_env.get_last_successful_checkin()
@@ -217,9 +215,7 @@ def send_incident_occurrence(
217215
"monitor.slug": str(monitor_env.monitor.slug),
218216
"monitor.incident": str(incident.id),
219217
},
220-
# option 1: timestamp <- received.isoformat(). This seems reasonable, because the cron incident starts not when
221-
# we've processed it, but when relay got the message (which is approximately when the cron failure occurred.)
222-
"timestamp": current_timestamp.isoformat(),
218+
"timestamp": received.isoformat(),
223219
}
224220

225221
if trace_id:
@@ -295,8 +291,6 @@ def resolve_incident_group(incident: MonitorIncident, project_id: int) -> None:
295291
project_id=project_id,
296292
new_status=GroupStatus.RESOLVED,
297293
new_substatus=None,
298-
# option 2: make this current_time. Then, because of monitor ordering guarantees, this will always be ahead of
299-
# the start time
300294
update_date=incident.resolving_timestamp,
301295
)
302296
produce_occurrence_to_kafka(

0 commit comments

Comments
 (0)