|
@@ -1,10 +1,9 @@
|
|
|
-from datetime import timedelta
|
|
|
+from datetime import datetime, timedelta
|
|
|
from typing import MutableMapping
|
|
|
from unittest import mock
|
|
|
|
|
|
import msgpack
|
|
|
import pytest
|
|
|
-import pytz
|
|
|
from arroyo import Partition, Topic
|
|
|
from arroyo.backends.kafka import KafkaPayload
|
|
|
from confluent_kafka.admin import PartitionMetadata
|
|
@@ -37,10 +36,7 @@ def make_ref_time(**kwargs):
|
|
|
To accurately reflect the real usage of this task, we want the ref time
|
|
|
to be truncated down to a minute for our tests.
|
|
|
"""
|
|
|
- tz_name = kwargs.pop("timezone", "UTC")
|
|
|
-
|
|
|
- ts = timezone.now().replace(**kwargs, tzinfo=None)
|
|
|
- ts = pytz.timezone(tz_name).localize(ts)
|
|
|
+ ts = timezone.now().replace(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
@@ -49,8 +45,10 @@ def make_ref_time(**kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
- task_run_ts = ts.astimezone(timezone.utc).replace(second=12, microsecond=0)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ task_run_ts = ts.replace(second=12, microsecond=0, tzinfo=None)
|
|
|
|
|
|
|
|
|
sub_task_run_ts = task_run_ts.replace(second=0)
|
|
@@ -126,67 +124,6 @@ class MonitorTaskCheckMissingTest(TestCase):
|
|
|
assert missed_checkin.expected_time == next_checkin
|
|
|
assert missed_checkin.monitor_config == monitor.config
|
|
|
|
|
|
- @mock.patch("sentry.monitors.tasks.mark_environment_missing")
|
|
|
- def test_missing_checkin_with_timezone(self, mark_environment_missing_mock):
|
|
|
- org = self.create_organization()
|
|
|
- project = self.create_project(organization=org)
|
|
|
-
|
|
|
-
|
|
|
- task_run_ts, sub_task_run_ts, ts = make_ref_time(
|
|
|
- month=2, day=1, hour=0, minute=0, timezone="US/Arizona"
|
|
|
- )
|
|
|
-
|
|
|
- monitor = Monitor.objects.create(
|
|
|
- organization_id=org.id,
|
|
|
- project_id=project.id,
|
|
|
- type=MonitorType.CRON_JOB,
|
|
|
- config={
|
|
|
- "schedule": "0 0 * * *",
|
|
|
- "schedule_type": ScheduleType.CRONTAB,
|
|
|
- "timezone": "US/Arizona",
|
|
|
- "max_runtime": None,
|
|
|
- "checkin_margin": None,
|
|
|
- },
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
- monitor_environment = MonitorEnvironment.objects.create(
|
|
|
- monitor=monitor,
|
|
|
- environment=self.environment,
|
|
|
- last_checkin=ts - timedelta(days=1),
|
|
|
- next_checkin=ts,
|
|
|
- next_checkin_latest=ts + timedelta(minutes=1),
|
|
|
- status=MonitorStatus.OK,
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- for hour in range(24):
|
|
|
- check_missing(task_run_ts - timedelta(days=1) + timedelta(hours=hour + 1))
|
|
|
-
|
|
|
- assert mark_environment_missing_mock.delay.call_count == 0
|
|
|
-
|
|
|
-
|
|
|
- check_missing(task_run_ts + timedelta(minutes=1))
|
|
|
- assert mark_environment_missing_mock.delay.call_count == 1
|
|
|
-
|
|
|
-
|
|
|
- mark_environment_missing(monitor_environment.id, sub_task_run_ts + timedelta(minutes=1))
|
|
|
- monitor_environment.refresh_from_db()
|
|
|
-
|
|
|
- assert MonitorCheckIn.objects.filter(
|
|
|
- monitor_environment=monitor_environment.id,
|
|
|
- status=CheckInStatus.MISSED,
|
|
|
- ).exists()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- utc_ts = ts.astimezone(timezone.utc)
|
|
|
-
|
|
|
- assert monitor_environment.next_checkin == utc_ts + timedelta(days=1)
|
|
|
- assert monitor_environment.next_checkin_latest == utc_ts + timedelta(days=1, minutes=1)
|
|
|
-
|
|
|
@mock.patch("sentry.monitors.tasks.mark_environment_missing")
|
|
|
def test_missing_checkin_with_margin(self, mark_environment_missing_mock):
|
|
|
org = self.create_organization()
|
|
@@ -1010,7 +947,7 @@ def test_clock_pulse(checkin_producer_mock):
|
|
|
|
|
|
@mock.patch("sentry.monitors.tasks._dispatch_tasks")
|
|
|
def test_monitor_task_trigger(dispatch_tasks):
|
|
|
- now = timezone.now().replace(second=0, microsecond=0)
|
|
|
+ now = datetime.now().replace(second=0, microsecond=0)
|
|
|
|
|
|
|
|
|
|
|
@@ -1046,7 +983,7 @@ def test_monitor_task_trigger_partition_desync(dispatch_tasks):
|
|
|
timestamps in a non-monotonic order. In this scenario we want to make
|
|
|
sure we still only trigger once
|
|
|
"""
|
|
|
- now = timezone.now().replace(second=0, microsecond=0)
|
|
|
+ now = datetime.now().replace(second=0, microsecond=0)
|
|
|
|
|
|
|
|
|
|
|
@@ -1076,7 +1013,7 @@ def test_monitor_task_trigger_partition_sync(dispatch_tasks):
|
|
|
When the kafka topic has multiple partitions we want to only tick our clock
|
|
|
forward once all partitions have caught up. This test simulates that
|
|
|
"""
|
|
|
- now = timezone.now().replace(second=0, microsecond=0)
|
|
|
+ now = datetime.now().replace(second=0, microsecond=0)
|
|
|
|
|
|
|
|
|
try_monitor_tasks_trigger(ts=now, partition=0)
|
|
@@ -1104,7 +1041,7 @@ def test_monitor_task_trigger_partition_tick_skip(dispatch_tasks):
|
|
|
In a scenario where all partitions move multiple ticks past the slowest
|
|
|
partition we may end up skipping a tick.
|
|
|
"""
|
|
|
- now = timezone.now().replace(second=0, microsecond=0)
|
|
|
+ now = datetime.now().replace(second=0, microsecond=0)
|
|
|
|
|
|
|
|
|
try_monitor_tasks_trigger(ts=now, partition=0)
|