Skip to content

Commit 0315c29

Browse files
committed
debug(crons): Add kwargs to mark_checkin_timeout
1 parent aea1a60 commit 0315c29

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/sentry/monitors/tasks.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,15 @@ def check_timeout(current_datetime: datetime):
338338
metrics.gauge("sentry.monitors.tasks.check_timeout.count", qs.count(), sample_rate=1)
339339
# check for any monitors which are still running and have exceeded their maximum runtime
340340
for checkin in qs:
341-
mark_checkin_timeout.delay(checkin.id, current_datetime)
341+
# used for temporary debugging
342+
kwargs = {
343+
"monitor_id": checkin.monitor.id,
344+
"monitor_environment_id": checkin.monitor_environment.id,
345+
"status": checkin.status,
346+
"date_added": checkin.date_added,
347+
"timeout_at": checkin.timeout_at,
348+
}
349+
mark_checkin_timeout.delay(checkin.id, current_datetime, **kwargs)
342350

343351

344352
@instrumented_task(

tests/sentry/monitors/test_tasks.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ def make_ref_time(**kwargs):
6262
return task_run_ts, sub_task_run_ts, trimmed_ts
6363

6464

65+
def get_checkin_timeout_kwargs(checkin: MonitorCheckIn):
66+
return {
67+
"monitor_id": checkin.monitor.id,
68+
"monitor_environment_id": checkin.monitor_environment.id,
69+
"status": checkin.status,
70+
"date_added": checkin.date_added,
71+
"timeout_at": checkin.timeout_at,
72+
}
73+
74+
6575
class MonitorTaskCheckMissingTest(TestCase):
6676
@mock.patch("sentry.monitors.tasks.mark_environment_missing")
6777
def test_missing_checkin(self, mark_environment_missing_mock):
@@ -652,15 +662,18 @@ def test_timeout(self, mark_checkin_timeout_mock):
652662
assert mark_checkin_timeout_mock.delay.call_count == 0
653663

654664
# Timout at 12:30
665+
checkin_kwargs = get_checkin_timeout_kwargs(checkin)
655666
check_timeout(task_run_ts + timedelta(minutes=30))
656667
assert mark_checkin_timeout_mock.delay.call_count == 1
657668
assert mark_checkin_timeout_mock.delay.mock_calls[0] == mock.call(
658669
checkin.id,
659670
sub_task_run_ts + timedelta(minutes=30),
671+
**checkin_kwargs,
660672
)
661673
mark_checkin_timeout(
662674
checkin.id,
663675
sub_task_run_ts + timedelta(minutes=30),
676+
**checkin_kwargs,
664677
)
665678

666679
# Check in is marked as timed out
@@ -744,16 +757,19 @@ def test_timeout_with_overlapping_concurrent_checkins(self, mark_checkin_timeout
744757
assert mark_checkin_timeout_mock.delay.call_count == 0
745758

746759
# First checkin timed out
760+
checkin_kwargs = get_checkin_timeout_kwargs(checkin1)
747761
check_timeout(task_run_ts + timedelta(minutes=30))
748762
assert mark_checkin_timeout_mock.delay.call_count == 1
749763
assert mark_checkin_timeout_mock.delay.mock_calls[0] == mock.call(
750764
checkin1.id,
751765
sub_task_run_ts + timedelta(minutes=30),
766+
**checkin_kwargs,
752767
)
753768

754769
mark_checkin_timeout(
755770
checkin1.id,
756771
sub_task_run_ts + timedelta(minutes=30),
772+
**checkin_kwargs,
757773
)
758774

759775
# First checkin is marked as timed out
@@ -819,13 +835,15 @@ def test_timeout_at_next_checkin_time(self, mark_checkin_timeout_mock):
819835
)
820836

821837
# Check in was marked as timed out
838+
checkin_kwargs = get_checkin_timeout_kwargs(checkin)
822839
check_timeout(task_run_ts)
823840
assert mark_checkin_timeout_mock.delay.call_count == 1
824841
assert mark_checkin_timeout_mock.delay.mock_calls[0] == mock.call(
825842
checkin.id,
826843
sub_task_run_ts,
844+
**checkin_kwargs,
827845
)
828-
mark_checkin_timeout(checkin.id, sub_task_run_ts)
846+
mark_checkin_timeout(checkin.id, sub_task_run_ts, **checkin_kwargs)
829847

830848
# First checkin is marked as timed out
831849
assert MonitorCheckIn.objects.filter(id=checkin.id, status=CheckInStatus.TIMEOUT).exists()
@@ -879,15 +897,18 @@ def test_timeout_using_interval(self, mark_checkin_timeout_mock):
879897
)
880898

881899
# Timout at 12:05
900+
checkin_kwargs = get_checkin_timeout_kwargs(checkin)
882901
check_timeout(task_run_ts + timedelta(minutes=5))
883902
assert mark_checkin_timeout_mock.delay.call_count == 1
884903
assert mark_checkin_timeout_mock.delay.mock_calls[0] == mock.call(
885904
checkin.id,
886905
sub_task_run_ts + timedelta(minutes=5),
906+
**checkin_kwargs,
887907
)
888908
mark_checkin_timeout(
889909
checkin.id,
890910
sub_task_run_ts + timedelta(minutes=5),
911+
**checkin_kwargs,
891912
)
892913

893914
# Check in is marked as timed out
@@ -958,16 +979,18 @@ def test_timeout_with_future_complete_checkin(self, mark_checkin_timeout_mock):
958979

959980
# Running check monitor will mark the first checkin as timed out. The
960981
# second checkin was already marked as OK.
982+
checkin_kwargs = get_checkin_timeout_kwargs(checkin1)
961983
check_timeout(task_run_ts)
962984

963985
# assert that task is called for the specific checkin
964986
assert mark_checkin_timeout_mock.delay.call_count == 1
965987
assert mark_checkin_timeout_mock.delay.mock_calls[0] == mock.call(
966988
checkin1.id,
967989
sub_task_run_ts,
990+
**checkin_kwargs,
968991
)
969992

970-
mark_checkin_timeout(checkin1.id, sub_task_run_ts)
993+
mark_checkin_timeout(checkin1.id, sub_task_run_ts, **checkin_kwargs)
971994

972995
# The first checkin is marked as timed out
973996
assert MonitorCheckIn.objects.filter(id=checkin1.id, status=CheckInStatus.TIMEOUT).exists()

0 commit comments

Comments
 (0)