Skip to content

Commit

Permalink
chore(rpc-subscriptions): Remove timestamp rounding (#6611)
Browse files Browse the repository at this point in the history
With this change #6609 it's no
longer
required to round the timestamps to get back a single time bucket.
  • Loading branch information
shruthilayaj authored Dec 4, 2024
1 parent 9b049f3 commit 4987f3a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
14 changes: 3 additions & 11 deletions snuba/subscriptions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from abc import ABC, abstractmethod
from concurrent.futures import Future
from dataclasses import dataclass, field
from datetime import UTC, datetime, timedelta
from datetime import datetime, timedelta
from enum import Enum
from functools import partial
from typing import (
Expand Down Expand Up @@ -217,20 +217,12 @@ def build_request(
request_class = EndpointTimeSeries().request_class()()
request_class.ParseFromString(base64.b64decode(self.time_series_request))

# TODO: update it to round to the lowest granularity
# rounded_ts = int(timestamp.replace(tzinfo=UTC).timestamp() / 15) * 15
rounded_ts = (
int(timestamp.replace(tzinfo=UTC).timestamp() / self.time_window_sec)
* self.time_window_sec
)
rounded_start = datetime.utcfromtimestamp(rounded_ts)

start_time_proto = Timestamp()
start_time_proto.FromDatetime(
rounded_start - timedelta(seconds=self.time_window_sec)
timestamp - timedelta(seconds=self.time_window_sec)
)
end_time_proto = Timestamp()
end_time_proto.FromDatetime(rounded_start)
end_time_proto.FromDatetime(timestamp)
request_class.meta.start_timestamp.CopyFrom(start_time_proto)
request_class.meta.end_timestamp.CopyFrom(end_time_proto)

Expand Down
5 changes: 4 additions & 1 deletion tests/subscriptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ def setup_teardown(self, clickhouse_db: None) -> None:
gen_span_message(self.base_time + timedelta(minutes=tick))
for tick in range(self.minutes)
]
write_raw_unprocessed_events(spans_storage, messages)
extra_messages = [
gen_span_message(self.base_time - timedelta(hours=4)) for _ in range(2)
]
write_raw_unprocessed_events(spans_storage, extra_messages + messages)


def __entity_eq__(self: Entity, other: object) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tests/subscriptions/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
),
],
),
time_window_secs=3600,
time_window_secs=10800,
resolution_secs=60,
),
EntityKey.EAP_SPANS,
Expand Down
2 changes: 1 addition & 1 deletion tests/web/rpc/v1/test_create_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
store_timeseries,
)

END_TIME = datetime.utcnow().replace(second=0, microsecond=0, tzinfo=UTC)
END_TIME = datetime.utcnow().replace(tzinfo=UTC)
START_TIME = END_TIME - timedelta(hours=1)


Expand Down

0 comments on commit 4987f3a

Please sign in to comment.