Skip to content

ref(crons): Rename send_{message->checkin} #54191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions tests/sentry/monitors/test_monitor_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _create_monitor(self, **kwargs):
**kwargs,
)

def send_message(
def send_checkin(
self,
monitor_slug: str,
guid: Optional[str] = None,
Expand Down Expand Up @@ -89,7 +89,7 @@ def send_message(
def test_payload(self) -> None:
monitor = self._create_monitor(slug="my-monitor")

self.send_message(monitor.slug)
self.send_checkin(monitor.slug)

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.status == CheckInStatus.OK
Expand All @@ -108,15 +108,15 @@ def test_payload(self) -> None:

# Process another check-in to verify we set an expected time for the next check-in
expected_time = monitor_environment.next_checkin
self.send_message(monitor.slug)
self.send_checkin(monitor.slug)
checkin = MonitorCheckIn.objects.get(guid=self.guid)
# the expected time should not include the margin of 5 minutes
assert checkin.expected_time == expected_time - timedelta(minutes=5)
assert checkin.trace_id.hex == self.trace_id

def test_passing(self) -> None:
monitor = self._create_monitor(slug="my-monitor")
self.send_message(monitor.slug)
self.send_checkin(monitor.slug)

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.status == CheckInStatus.OK
Expand All @@ -135,14 +135,14 @@ def test_passing(self) -> None:

# Process another check-in to verify we set an expected time for the next check-in
expected_time = monitor_environment.next_checkin
self.send_message(monitor.slug)
self.send_checkin(monitor.slug)
checkin = MonitorCheckIn.objects.get(guid=self.guid)
# the expected time should not include the margin of 5 minutes
assert checkin.expected_time == expected_time - timedelta(minutes=5)

def test_failing(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(monitor.slug, status="error")
self.send_checkin(monitor.slug, status="error")

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.status == CheckInStatus.ERROR
Expand All @@ -160,7 +160,7 @@ def test_failing(self):

def test_disabled(self):
monitor = self._create_monitor(status=ObjectStatus.DISABLED)
self.send_message(monitor.slug, status="error")
self.send_checkin(monitor.slug, status="error")

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.status == CheckInStatus.ERROR
Expand All @@ -186,28 +186,28 @@ def test_create_lock(self):
lock = locks.get(f"checkin-creation:{uuid.UUID(guid)}", duration=2, name="checkin_creation")
lock.acquire()

self.send_message(monitor.slug, guid=guid)
self.send_checkin(monitor.slug, guid=guid)

# Lock should prevent creation of new check-in
assert len(MonitorCheckIn.objects.filter(monitor=monitor)) == 0

def test_check_in_timeout_at(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(monitor.slug, status="in_progress")
self.send_checkin(monitor.slug, status="in_progress")

checkin = MonitorCheckIn.objects.get(guid=self.guid)
timeout_at = checkin.date_added.replace(second=0, microsecond=0) + timedelta(
minutes=TIMEOUT
)
assert checkin.timeout_at == timeout_at

self.send_message(monitor.slug, guid=self.guid)
self.send_checkin(monitor.slug, guid=self.guid)
checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.status == CheckInStatus.OK
assert checkin.timeout_at is None

new_guid = uuid.uuid4().hex
self.send_message(
self.send_checkin(
"my-other-monitor",
guid=new_guid,
status="in_progress",
Expand All @@ -224,8 +224,8 @@ def test_check_in_timeout_at(self):

def test_check_in_update(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(monitor.slug, status="in_progress")
self.send_message(monitor.slug, guid=self.guid)
self.send_checkin(monitor.slug, status="in_progress")
self.send_checkin(monitor.slug, guid=self.guid)

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.duration is not None
Expand All @@ -234,33 +234,33 @@ def test_check_in_existing_guid(self):
monitor = self._create_monitor(slug="my-monitor")
other_monitor = self._create_monitor(slug="other-monitor")

self.send_message(monitor.slug, status="in_progress")
self.send_message(
self.send_checkin(monitor.slug, status="in_progress")
self.send_checkin(
monitor.slug, guid=self.guid, status="done", enviroment="other-environment"
)
self.send_message(other_monitor.slug, guid=self.guid, status="done")
self.send_checkin(other_monitor.slug, guid=self.guid, status="done")

# Assert check-in was not modified
checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.status == CheckInStatus.IN_PROGRESS

def test_check_in_update_terminal(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(monitor.slug, duration=10.0)
self.send_message(monitor.slug, guid=self.guid, status="in_progress")
self.send_checkin(monitor.slug, duration=10.0)
self.send_checkin(monitor.slug, guid=self.guid, status="in_progress")

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.duration == int(10.0 * 1000)

self.send_message(monitor.slug, duration=20.0, status="error")
self.send_message(monitor.slug, guid=self.guid, status="in_progress")
self.send_checkin(monitor.slug, duration=20.0, status="error")
self.send_checkin(monitor.slug, guid=self.guid, status="in_progress")

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.duration == int(20.0 * 1000)

def test_monitor_environment(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(monitor.slug, environment="jungle")
self.send_checkin(monitor.slug, environment="jungle")

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.status == CheckInStatus.OK
Expand All @@ -278,7 +278,7 @@ def test_monitor_environment(self):
)

def test_monitor_create(self):
self.send_message(
self.send_checkin(
"my-new-monitor",
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
)
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_monitor_create(self):

def test_monitor_update(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(
self.send_checkin(
"my-monitor",
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
)
Expand Down Expand Up @@ -337,7 +337,7 @@ def test_monitor_update(self):

def test_check_in_empty_id(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(
self.send_checkin(
"my-monitor",
guid=str(uuid.UUID(int=0)),
)
Expand All @@ -348,7 +348,7 @@ def test_check_in_empty_id(self):

def test_check_in_empty_id_update(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(
self.send_checkin(
"my-monitor",
status="in_progress",
guid=str(uuid.UUID(int=0)),
Expand All @@ -361,9 +361,9 @@ def test_check_in_empty_id_update(self):
# Send an event to a different monitor environment, tests that when we
# use the empty UUID "latest" we properly scope to the latest of the
# same monitor environment
self.send_message("my-monitor", status="in_progress", environment="dev")
self.send_checkin("my-monitor", status="in_progress", environment="dev")

self.send_message(
self.send_checkin(
"my-monitor",
status="ok",
guid=str(uuid.UUID(int=0)),
Expand All @@ -378,26 +378,26 @@ def test_rate_limit(self):

with mock.patch("sentry.monitors.consumers.monitor_consumer.CHECKIN_QUOTA_LIMIT", 1):
# Try to ingest two the second will be rate limited
self.send_message("my-monitor")
self.send_message("my-monitor")
self.send_checkin("my-monitor")
self.send_checkin("my-monitor")

checkins = MonitorCheckIn.objects.filter(monitor_id=monitor.id)
assert len(checkins) == 1

# Same monitor, diff environments
self.send_message("my-monitor", environment="dev")
self.send_checkin("my-monitor", environment="dev")

checkins = MonitorCheckIn.objects.filter(monitor_id=monitor.id)
assert len(checkins) == 2

def test_invalid_guid_environment_match(self):
monitor = self._create_monitor(slug="my-monitor")
self.send_message(monitor.slug, status="in_progress")
self.send_checkin(monitor.slug, status="in_progress")

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.monitor_environment.environment.name == "production"

self.send_message(monitor.slug, guid=self.guid, status="ok", environment="test")
self.send_checkin(monitor.slug, guid=self.guid, status="ok", environment="test")

checkin = MonitorCheckIn.objects.get(guid=self.guid)
assert checkin.status == CheckInStatus.IN_PROGRESS
Expand All @@ -407,19 +407,19 @@ def test_invalid_duration(self):
monitor = self._create_monitor(slug="my-monitor")

# Test invalid explicit durations
self.send_message("my-monitor", status="in_progress")
self.send_checkin("my-monitor", status="in_progress")

# Invalid check-in updates
self.send_message("my-monitor", guid=self.guid, duration=-(1.0 / 1000))
self.send_message(
self.send_checkin("my-monitor", guid=self.guid, duration=-(1.0 / 1000))
self.send_checkin(
"my-monitor",
guid=self.guid,
duration=((BoundedPositiveIntegerField.MAX_VALUE + 1.0) / 1000),
)

# Invalid check-in creations
self.send_message("my-monitor", duration=-(1.0 / 1000))
self.send_message(
self.send_checkin("my-monitor", duration=-(1.0 / 1000))
self.send_checkin(
"my-monitor", duration=(BoundedPositiveIntegerField.MAX_VALUE + 1.0) / 1000
)

Expand All @@ -437,14 +437,14 @@ def test_invalid_duration(self):
date_added=monitor.date_added - timedelta(weeks=52),
)

self.send_message("my-monitor", guid=old_checkin.guid)
self.send_checkin("my-monitor", guid=old_checkin.guid)

checkin = MonitorCheckIn.objects.get(guid=old_checkin.guid)
assert checkin.status == CheckInStatus.IN_PROGRESS
assert checkin.duration is None

def test_monitor_upsert(self):
self.send_message(
self.send_checkin(
"my-monitor",
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
environment="my-environment",
Expand All @@ -462,7 +462,7 @@ def test_monitor_upsert(self):
assert monitor_environment is not None

def test_monitor_upsert_invalid_slug(self):
self.send_message(
self.send_checkin(
"some/slug@with-weird|stuff",
monitor_config={"schedule": {"type": "crontab", "value": "0 * * * *"}},
)
Expand All @@ -474,7 +474,7 @@ def test_monitor_upsert_invalid_slug(self):
def test_monitor_upsert_temp_dual_read_invalid_slug(self):
monitor = self._create_monitor(slug="my/monitor/invalid-slug")

self.send_message(
self.send_checkin(
"my/monitor/invalid-slug",
monitor_config={"schedule": {"type": "crontab", "value": "0 * * * *"}},
)
Expand All @@ -484,7 +484,7 @@ def test_monitor_upsert_temp_dual_read_invalid_slug(self):
assert checkin.monitor_id == monitor.id

def test_monitor_invalid_config(self):
self.send_message(
self.send_checkin(
"my-invalid-monitor",
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * * *"}},
environment="my-environment",
Expand All @@ -495,7 +495,7 @@ def test_monitor_invalid_config(self):
@override_settings(MAX_MONITORS_PER_ORG=2)
def test_monitor_limits(self):
for i in range(settings.MAX_MONITORS_PER_ORG + 2):
self.send_message(
self.send_checkin(
f"my-monitor-{i}",
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
)
Expand All @@ -506,7 +506,7 @@ def test_monitor_limits(self):
@override_settings(MAX_ENVIRONMENTS_PER_MONITOR=2)
def test_monitor_environment_limits(self):
for i in range(settings.MAX_ENVIRONMENTS_PER_MONITOR + 2):
self.send_message(
self.send_checkin(
"my-monitor",
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
environment=f"my-environment-{i}",
Expand All @@ -521,7 +521,7 @@ def test_monitor_environment_limits(self):
def test_monitor_environment_validation(self):
invalid_name = "x" * 65

self.send_message(
self.send_checkin(
"my-monitor",
monitor_config={"schedule": {"type": "crontab", "value": "13 * * * *"}},
environment=f"my-environment-{invalid_name}",
Expand All @@ -541,7 +541,7 @@ def test_organization_killswitch(self):
)
options.set("crons.organization.disable-check-in", opt_val)

self.send_message(monitor.slug)
self.send_checkin(monitor.slug)

opt_val = killswitches.validate_user_input("crons.organization.disable-check-in", [])
options.set("crons.organization.disable-check-in", opt_val)
Expand Down