@@ -46,7 +46,7 @@ def _create_monitor(self, **kwargs):
46
46
** kwargs ,
47
47
)
48
48
49
- def send_message (
49
+ def send_checkin (
50
50
self ,
51
51
monitor_slug : str ,
52
52
guid : Optional [str ] = None ,
@@ -89,7 +89,7 @@ def send_message(
89
89
def test_payload (self ) -> None :
90
90
monitor = self ._create_monitor (slug = "my-monitor" )
91
91
92
- self .send_message (monitor .slug )
92
+ self .send_checkin (monitor .slug )
93
93
94
94
checkin = MonitorCheckIn .objects .get (guid = self .guid )
95
95
assert checkin .status == CheckInStatus .OK
@@ -108,15 +108,15 @@ def test_payload(self) -> None:
108
108
109
109
# Process another check-in to verify we set an expected time for the next check-in
110
110
expected_time = monitor_environment .next_checkin
111
- self .send_message (monitor .slug )
111
+ self .send_checkin (monitor .slug )
112
112
checkin = MonitorCheckIn .objects .get (guid = self .guid )
113
113
# the expected time should not include the margin of 5 minutes
114
114
assert checkin .expected_time == expected_time - timedelta (minutes = 5 )
115
115
assert checkin .trace_id .hex == self .trace_id
116
116
117
117
def test_passing (self ) -> None :
118
118
monitor = self ._create_monitor (slug = "my-monitor" )
119
- self .send_message (monitor .slug )
119
+ self .send_checkin (monitor .slug )
120
120
121
121
checkin = MonitorCheckIn .objects .get (guid = self .guid )
122
122
assert checkin .status == CheckInStatus .OK
@@ -135,14 +135,14 @@ def test_passing(self) -> None:
135
135
136
136
# Process another check-in to verify we set an expected time for the next check-in
137
137
expected_time = monitor_environment .next_checkin
138
- self .send_message (monitor .slug )
138
+ self .send_checkin (monitor .slug )
139
139
checkin = MonitorCheckIn .objects .get (guid = self .guid )
140
140
# the expected time should not include the margin of 5 minutes
141
141
assert checkin .expected_time == expected_time - timedelta (minutes = 5 )
142
142
143
143
def test_failing (self ):
144
144
monitor = self ._create_monitor (slug = "my-monitor" )
145
- self .send_message (monitor .slug , status = "error" )
145
+ self .send_checkin (monitor .slug , status = "error" )
146
146
147
147
checkin = MonitorCheckIn .objects .get (guid = self .guid )
148
148
assert checkin .status == CheckInStatus .ERROR
@@ -160,7 +160,7 @@ def test_failing(self):
160
160
161
161
def test_disabled (self ):
162
162
monitor = self ._create_monitor (status = ObjectStatus .DISABLED )
163
- self .send_message (monitor .slug , status = "error" )
163
+ self .send_checkin (monitor .slug , status = "error" )
164
164
165
165
checkin = MonitorCheckIn .objects .get (guid = self .guid )
166
166
assert checkin .status == CheckInStatus .ERROR
@@ -186,28 +186,28 @@ def test_create_lock(self):
186
186
lock = locks .get (f"checkin-creation:{ uuid .UUID (guid )} " , duration = 2 , name = "checkin_creation" )
187
187
lock .acquire ()
188
188
189
- self .send_message (monitor .slug , guid = guid )
189
+ self .send_checkin (monitor .slug , guid = guid )
190
190
191
191
# Lock should prevent creation of new check-in
192
192
assert len (MonitorCheckIn .objects .filter (monitor = monitor )) == 0
193
193
194
194
def test_check_in_timeout_at (self ):
195
195
monitor = self ._create_monitor (slug = "my-monitor" )
196
- self .send_message (monitor .slug , status = "in_progress" )
196
+ self .send_checkin (monitor .slug , status = "in_progress" )
197
197
198
198
checkin = MonitorCheckIn .objects .get (guid = self .guid )
199
199
timeout_at = checkin .date_added .replace (second = 0 , microsecond = 0 ) + timedelta (
200
200
minutes = TIMEOUT
201
201
)
202
202
assert checkin .timeout_at == timeout_at
203
203
204
- self .send_message (monitor .slug , guid = self .guid )
204
+ self .send_checkin (monitor .slug , guid = self .guid )
205
205
checkin = MonitorCheckIn .objects .get (guid = self .guid )
206
206
assert checkin .status == CheckInStatus .OK
207
207
assert checkin .timeout_at is None
208
208
209
209
new_guid = uuid .uuid4 ().hex
210
- self .send_message (
210
+ self .send_checkin (
211
211
"my-other-monitor" ,
212
212
guid = new_guid ,
213
213
status = "in_progress" ,
@@ -224,8 +224,8 @@ def test_check_in_timeout_at(self):
224
224
225
225
def test_check_in_update (self ):
226
226
monitor = self ._create_monitor (slug = "my-monitor" )
227
- self .send_message (monitor .slug , status = "in_progress" )
228
- self .send_message (monitor .slug , guid = self .guid )
227
+ self .send_checkin (monitor .slug , status = "in_progress" )
228
+ self .send_checkin (monitor .slug , guid = self .guid )
229
229
230
230
checkin = MonitorCheckIn .objects .get (guid = self .guid )
231
231
assert checkin .duration is not None
@@ -234,33 +234,33 @@ def test_check_in_existing_guid(self):
234
234
monitor = self ._create_monitor (slug = "my-monitor" )
235
235
other_monitor = self ._create_monitor (slug = "other-monitor" )
236
236
237
- self .send_message (monitor .slug , status = "in_progress" )
238
- self .send_message (
237
+ self .send_checkin (monitor .slug , status = "in_progress" )
238
+ self .send_checkin (
239
239
monitor .slug , guid = self .guid , status = "done" , enviroment = "other-environment"
240
240
)
241
- self .send_message (other_monitor .slug , guid = self .guid , status = "done" )
241
+ self .send_checkin (other_monitor .slug , guid = self .guid , status = "done" )
242
242
243
243
# Assert check-in was not modified
244
244
checkin = MonitorCheckIn .objects .get (guid = self .guid )
245
245
assert checkin .status == CheckInStatus .IN_PROGRESS
246
246
247
247
def test_check_in_update_terminal (self ):
248
248
monitor = self ._create_monitor (slug = "my-monitor" )
249
- self .send_message (monitor .slug , duration = 10.0 )
250
- self .send_message (monitor .slug , guid = self .guid , status = "in_progress" )
249
+ self .send_checkin (monitor .slug , duration = 10.0 )
250
+ self .send_checkin (monitor .slug , guid = self .guid , status = "in_progress" )
251
251
252
252
checkin = MonitorCheckIn .objects .get (guid = self .guid )
253
253
assert checkin .duration == int (10.0 * 1000 )
254
254
255
- self .send_message (monitor .slug , duration = 20.0 , status = "error" )
256
- self .send_message (monitor .slug , guid = self .guid , status = "in_progress" )
255
+ self .send_checkin (monitor .slug , duration = 20.0 , status = "error" )
256
+ self .send_checkin (monitor .slug , guid = self .guid , status = "in_progress" )
257
257
258
258
checkin = MonitorCheckIn .objects .get (guid = self .guid )
259
259
assert checkin .duration == int (20.0 * 1000 )
260
260
261
261
def test_monitor_environment (self ):
262
262
monitor = self ._create_monitor (slug = "my-monitor" )
263
- self .send_message (monitor .slug , environment = "jungle" )
263
+ self .send_checkin (monitor .slug , environment = "jungle" )
264
264
265
265
checkin = MonitorCheckIn .objects .get (guid = self .guid )
266
266
assert checkin .status == CheckInStatus .OK
@@ -278,7 +278,7 @@ def test_monitor_environment(self):
278
278
)
279
279
280
280
def test_monitor_create (self ):
281
- self .send_message (
281
+ self .send_checkin (
282
282
"my-new-monitor" ,
283
283
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "13 * * * *" }},
284
284
)
@@ -306,7 +306,7 @@ def test_monitor_create(self):
306
306
307
307
def test_monitor_update (self ):
308
308
monitor = self ._create_monitor (slug = "my-monitor" )
309
- self .send_message (
309
+ self .send_checkin (
310
310
"my-monitor" ,
311
311
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "13 * * * *" }},
312
312
)
@@ -337,7 +337,7 @@ def test_monitor_update(self):
337
337
338
338
def test_check_in_empty_id (self ):
339
339
monitor = self ._create_monitor (slug = "my-monitor" )
340
- self .send_message (
340
+ self .send_checkin (
341
341
"my-monitor" ,
342
342
guid = str (uuid .UUID (int = 0 )),
343
343
)
@@ -348,7 +348,7 @@ def test_check_in_empty_id(self):
348
348
349
349
def test_check_in_empty_id_update (self ):
350
350
monitor = self ._create_monitor (slug = "my-monitor" )
351
- self .send_message (
351
+ self .send_checkin (
352
352
"my-monitor" ,
353
353
status = "in_progress" ,
354
354
guid = str (uuid .UUID (int = 0 )),
@@ -361,9 +361,9 @@ def test_check_in_empty_id_update(self):
361
361
# Send an event to a different monitor environment, tests that when we
362
362
# use the empty UUID "latest" we properly scope to the latest of the
363
363
# same monitor environment
364
- self .send_message ("my-monitor" , status = "in_progress" , environment = "dev" )
364
+ self .send_checkin ("my-monitor" , status = "in_progress" , environment = "dev" )
365
365
366
- self .send_message (
366
+ self .send_checkin (
367
367
"my-monitor" ,
368
368
status = "ok" ,
369
369
guid = str (uuid .UUID (int = 0 )),
@@ -378,26 +378,26 @@ def test_rate_limit(self):
378
378
379
379
with mock .patch ("sentry.monitors.consumers.monitor_consumer.CHECKIN_QUOTA_LIMIT" , 1 ):
380
380
# Try to ingest two the second will be rate limited
381
- self .send_message ("my-monitor" )
382
- self .send_message ("my-monitor" )
381
+ self .send_checkin ("my-monitor" )
382
+ self .send_checkin ("my-monitor" )
383
383
384
384
checkins = MonitorCheckIn .objects .filter (monitor_id = monitor .id )
385
385
assert len (checkins ) == 1
386
386
387
387
# Same monitor, diff environments
388
- self .send_message ("my-monitor" , environment = "dev" )
388
+ self .send_checkin ("my-monitor" , environment = "dev" )
389
389
390
390
checkins = MonitorCheckIn .objects .filter (monitor_id = monitor .id )
391
391
assert len (checkins ) == 2
392
392
393
393
def test_invalid_guid_environment_match (self ):
394
394
monitor = self ._create_monitor (slug = "my-monitor" )
395
- self .send_message (monitor .slug , status = "in_progress" )
395
+ self .send_checkin (monitor .slug , status = "in_progress" )
396
396
397
397
checkin = MonitorCheckIn .objects .get (guid = self .guid )
398
398
assert checkin .monitor_environment .environment .name == "production"
399
399
400
- self .send_message (monitor .slug , guid = self .guid , status = "ok" , environment = "test" )
400
+ self .send_checkin (monitor .slug , guid = self .guid , status = "ok" , environment = "test" )
401
401
402
402
checkin = MonitorCheckIn .objects .get (guid = self .guid )
403
403
assert checkin .status == CheckInStatus .IN_PROGRESS
@@ -407,19 +407,19 @@ def test_invalid_duration(self):
407
407
monitor = self ._create_monitor (slug = "my-monitor" )
408
408
409
409
# Test invalid explicit durations
410
- self .send_message ("my-monitor" , status = "in_progress" )
410
+ self .send_checkin ("my-monitor" , status = "in_progress" )
411
411
412
412
# Invalid check-in updates
413
- self .send_message ("my-monitor" , guid = self .guid , duration = - (1.0 / 1000 ))
414
- self .send_message (
413
+ self .send_checkin ("my-monitor" , guid = self .guid , duration = - (1.0 / 1000 ))
414
+ self .send_checkin (
415
415
"my-monitor" ,
416
416
guid = self .guid ,
417
417
duration = ((BoundedPositiveIntegerField .MAX_VALUE + 1.0 ) / 1000 ),
418
418
)
419
419
420
420
# Invalid check-in creations
421
- self .send_message ("my-monitor" , duration = - (1.0 / 1000 ))
422
- self .send_message (
421
+ self .send_checkin ("my-monitor" , duration = - (1.0 / 1000 ))
422
+ self .send_checkin (
423
423
"my-monitor" , duration = (BoundedPositiveIntegerField .MAX_VALUE + 1.0 ) / 1000
424
424
)
425
425
@@ -437,14 +437,14 @@ def test_invalid_duration(self):
437
437
date_added = monitor .date_added - timedelta (weeks = 52 ),
438
438
)
439
439
440
- self .send_message ("my-monitor" , guid = old_checkin .guid )
440
+ self .send_checkin ("my-monitor" , guid = old_checkin .guid )
441
441
442
442
checkin = MonitorCheckIn .objects .get (guid = old_checkin .guid )
443
443
assert checkin .status == CheckInStatus .IN_PROGRESS
444
444
assert checkin .duration is None
445
445
446
446
def test_monitor_upsert (self ):
447
- self .send_message (
447
+ self .send_checkin (
448
448
"my-monitor" ,
449
449
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "13 * * * *" }},
450
450
environment = "my-environment" ,
@@ -462,7 +462,7 @@ def test_monitor_upsert(self):
462
462
assert monitor_environment is not None
463
463
464
464
def test_monitor_upsert_invalid_slug (self ):
465
- self .send_message (
465
+ self .send_checkin (
466
466
"some/slug@with-weird|stuff" ,
467
467
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "0 * * * *" }},
468
468
)
@@ -474,7 +474,7 @@ def test_monitor_upsert_invalid_slug(self):
474
474
def test_monitor_upsert_temp_dual_read_invalid_slug (self ):
475
475
monitor = self ._create_monitor (slug = "my/monitor/invalid-slug" )
476
476
477
- self .send_message (
477
+ self .send_checkin (
478
478
"my/monitor/invalid-slug" ,
479
479
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "0 * * * *" }},
480
480
)
@@ -484,7 +484,7 @@ def test_monitor_upsert_temp_dual_read_invalid_slug(self):
484
484
assert checkin .monitor_id == monitor .id
485
485
486
486
def test_monitor_invalid_config (self ):
487
- self .send_message (
487
+ self .send_checkin (
488
488
"my-invalid-monitor" ,
489
489
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "13 * * * * *" }},
490
490
environment = "my-environment" ,
@@ -495,7 +495,7 @@ def test_monitor_invalid_config(self):
495
495
@override_settings (MAX_MONITORS_PER_ORG = 2 )
496
496
def test_monitor_limits (self ):
497
497
for i in range (settings .MAX_MONITORS_PER_ORG + 2 ):
498
- self .send_message (
498
+ self .send_checkin (
499
499
f"my-monitor-{ i } " ,
500
500
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "13 * * * *" }},
501
501
)
@@ -506,7 +506,7 @@ def test_monitor_limits(self):
506
506
@override_settings (MAX_ENVIRONMENTS_PER_MONITOR = 2 )
507
507
def test_monitor_environment_limits (self ):
508
508
for i in range (settings .MAX_ENVIRONMENTS_PER_MONITOR + 2 ):
509
- self .send_message (
509
+ self .send_checkin (
510
510
"my-monitor" ,
511
511
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "13 * * * *" }},
512
512
environment = f"my-environment-{ i } " ,
@@ -521,7 +521,7 @@ def test_monitor_environment_limits(self):
521
521
def test_monitor_environment_validation (self ):
522
522
invalid_name = "x" * 65
523
523
524
- self .send_message (
524
+ self .send_checkin (
525
525
"my-monitor" ,
526
526
monitor_config = {"schedule" : {"type" : "crontab" , "value" : "13 * * * *" }},
527
527
environment = f"my-environment-{ invalid_name } " ,
@@ -541,7 +541,7 @@ def test_organization_killswitch(self):
541
541
)
542
542
options .set ("crons.organization.disable-check-in" , opt_val )
543
543
544
- self .send_message (monitor .slug )
544
+ self .send_checkin (monitor .slug )
545
545
546
546
opt_val = killswitches .validate_user_input ("crons.organization.disable-check-in" , [])
547
547
options .set ("crons.organization.disable-check-in" , opt_val )
0 commit comments