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

fix(eap): fix bug where we pass non str group by mapping to timeseries #6593

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion snuba/web/rpc/v1/endpoint_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _convert_result_timeseries(

for col_name, col_value in row.items():
if col_name in group_by_labels:
group_by_map[col_name] = col_value
group_by_map[col_name] = str(col_value)

group_by_key = "|".join([f"{k},{v}" for k, v in group_by_map.items()])
for col_name in aggregation_labels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,58 @@ def sort_key(t: TimeSeries) -> tuple[str, str]:
key=sort_key,
)

def test_with_non_string_group_by(self) -> None:
store_timeseries(
BASE_TIME,
1,
3600,
metrics=[
DummyMetric("test_metric", get_value=lambda x: 1),
DummyMetric("group_by_metric", get_value=lambda x: 1),
],
)

message = TimeSeriesRequest(
meta=RequestMeta(
project_ids=[1, 2, 3],
organization_id=1,
cogs_category="something",
referrer="something",
start_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp())),
end_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp() + 60 * 30)),
),
aggregations=[
AttributeAggregation(
aggregate=Function.FUNCTION_SUM,
key=AttributeKey(type=AttributeKey.TYPE_FLOAT, name="test_metric"),
label="sum",
extrapolation_mode=ExtrapolationMode.EXTRAPOLATION_MODE_NONE,
),
],
group_by=[
AttributeKey(type=AttributeKey.TYPE_FLOAT, name="group_by_metric"),
],
granularity_secs=300,
)

response = EndpointTimeSeries().execute(message)
expected_buckets = [
Timestamp(seconds=int(BASE_TIME.timestamp()) + secs)
for secs in range(0, 60 * 30, 300)
]

assert response.result_timeseries == [
TimeSeries(
label="sum",
buckets=expected_buckets,
group_by_attributes={"group_by_metric": "1.0"},
data_points=[
DataPoint(data=300, data_present=True)
for _ in range(len(expected_buckets))
],
)
]

def test_with_no_data_present(self) -> None:
granularity_secs = 300
query_duration = 60 * 30
Expand Down
Loading