Skip to content
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

Revert "Specify UTC timezone argument in datetime.now() and fix unit … #6312

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions snuba/clickhouse/optimize/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from collections import deque
from concurrent.futures import Future, ThreadPoolExecutor
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from typing import Any, Mapping, Optional, Sequence

import structlog
Expand Down Expand Up @@ -347,7 +347,7 @@ def optimize_partitions(
"""

for partition in partitions:
if cutoff_time is not None and datetime.now(timezone.utc) > cutoff_time:
if cutoff_time is not None and datetime.now() > cutoff_time:
logger.info(
f"Optimize job is running past provided cutoff time"
f" {cutoff_time}. Cancelling.",
Expand Down
10 changes: 5 additions & 5 deletions snuba/clickhouse/optimize/optimize_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from typing import MutableSequence, Sequence

from snuba import settings
Expand Down Expand Up @@ -42,9 +42,9 @@ class OptimizeScheduler:

def __init__(self, default_parallel_threads: int) -> None:
self.__default_parallel_threads = default_parallel_threads
self.__last_midnight = (
datetime.now(timezone.utc) + timedelta(minutes=10)
).replace(hour=0, minute=0, second=0, microsecond=0)
self.__last_midnight = (datetime.now() + timedelta(minutes=10)).replace(
hour=0, minute=0, second=0, microsecond=0
)
self.__parallel_start_time = self.__last_midnight + timedelta(
hours=settings.PARALLEL_OPTIMIZE_JOB_START_TIME
)
Expand Down Expand Up @@ -95,7 +95,7 @@ def get_next_schedule(self, partitions: Sequence[str]) -> OptimizationSchedule:
reached.
"""
num_threads = get_num_threads(self.__default_parallel_threads)
current_time = datetime.now(timezone.utc)
current_time = datetime.now()
if current_time >= self.__full_job_end_time:
raise OptimizedSchedulerTimeout(
f"Optimize job cutoff time exceeded "
Expand Down
2 changes: 1 addition & 1 deletion snuba/settings/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
ENFORCE_RETENTION = True

# Ignore optimize job cut off time for tests
OPTIMIZE_JOB_CUTOFF_TIME = 23
OPTIMIZE_JOB_CUTOFF_TIME = 24

OPTIMIZE_PARALLEL_MAX_JITTER_MINUTES = 0

Expand Down
4 changes: 2 additions & 2 deletions tests/clickhouse/optimize/test_optimize_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from typing import Sequence

import pytest
Expand Down Expand Up @@ -132,7 +132,7 @@ def test_subdivide_partitions(
)


last_midnight = (datetime.now(timezone.utc) + timedelta(minutes=10)).replace(
last_midnight = (datetime.now() + timedelta(minutes=10)).replace(
hour=0, minute=0, second=0, microsecond=0
)

Expand Down
10 changes: 5 additions & 5 deletions tests/clickhouse/optimize/test_optimize_tracker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
import uuid
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from typing import Optional, Set
from unittest.mock import call, patch

Expand Down Expand Up @@ -136,11 +136,11 @@ def write_error_message(writable_storage: WritableTableStorage, time: int) -> No
for week in range(0, 4):
write_error_message(
writable_storage=storage,
time=int((datetime.now(timezone.utc) - timedelta(weeks=week)).timestamp()),
time=int((datetime.now() - timedelta(weeks=week)).timestamp()),
)
write_error_message(
writable_storage=storage,
time=int((datetime.now(timezone.utc) - timedelta(weeks=week)).timestamp()),
time=int((datetime.now() - timedelta(weeks=week)).timestamp()),
)

partitions = optimize.get_partitions_to_optimize(
Expand Down Expand Up @@ -227,11 +227,11 @@ def write_error_message(writable_storage: WritableTableStorage, time: int) -> No
for week in range(0, 4):
write_error_message(
writable_storage=storage,
time=int((datetime.now(timezone.utc) - timedelta(weeks=week)).timestamp()),
time=int((datetime.now() - timedelta(weeks=week)).timestamp()),
)
write_error_message(
writable_storage=storage,
time=int((datetime.now(timezone.utc) - timedelta(weeks=week)).timestamp()),
time=int((datetime.now() - timedelta(weeks=week)).timestamp()),
)

partitions = optimize.get_partitions_to_optimize(
Expand Down
9 changes: 3 additions & 6 deletions tests/subscriptions/test_scheduler_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import time
import uuid
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from typing import Any, Mapping, Optional
from unittest import mock

Expand Down Expand Up @@ -148,10 +148,7 @@ def test_tick_time_shift() -> None:
assert tick.time_shift(timedelta(hours=24).total_seconds()) == Tick(
partition,
offsets,
Interval(
datetime(1970, 1, 2, tzinfo=timezone.utc).timestamp(),
datetime(1970, 1, 3, tzinfo=timezone.utc).timestamp(),
),
Interval(datetime(1970, 1, 2).timestamp(), datetime(1970, 1, 3).timestamp()),
)


Expand Down Expand Up @@ -440,7 +437,7 @@ def test_invalid_commit_log_message(caplog: Any) -> None:
"orig_message_ts",
)

now = datetime.now(timezone.utc)
now = datetime.now()

def _assignment_callback(offsets: Mapping[Partition, int]) -> None:
assert inner_consumer.tell() == {partition: 0}
Expand Down
Loading