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

chore(rpc-subscriptions): Remove timestamp rounding #6611

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
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
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BaseSubscriptionTest class that the test inherits from adds events to the previous hour. This test worked before because we were rounding timestamp to the nearest granularity.

The larger time window will catch the events I expect to catch.

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
Loading