Skip to content

Commit d2511eb

Browse files
wmakandrewshie-sentry
authored andcommitted
fix(timeseries): groupby format was wrong (#87593)
- This updates the groupby format to match the spec - groupby should be a list of dicts instead of just a dict so that the fields are ordered
1 parent 57338ce commit d2511eb

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/sentry/snuba/discover.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ def create_result_key(
398398
) -> str:
399399
"""Create the string key to be used in the top events result dictionary"""
400400
groupby = create_groupby_dict(result_row, fields, issues)
401-
result = ",".join(groupby.values())
401+
groupby_values: list[str] = []
402+
for value in groupby:
403+
groupby_values.extend(value.values())
404+
result = ",".join(groupby_values)
402405
# If the result would be identical to the other key, include the field name
403406
# only need the first field since this would only happen with a single field
404407
if result == OTHER_KEY:
@@ -408,24 +411,24 @@ def create_result_key(
408411

409412
def create_groupby_dict(
410413
result_row: SnubaRow, fields: list[str], issues: Mapping[int, str | None]
411-
) -> dict[str, str]:
412-
values = {}
414+
) -> list[dict[str, str]]:
415+
values = []
413416
for field in fields:
414417
if field == "issue.id":
415418
issue_id = issues.get(result_row["issue.id"], "unknown")
416419
if issue_id is None:
417420
issue_id = "unknown"
418-
values[field] = issue_id
421+
values.append({field: issue_id})
419422
elif field == "transaction.status":
420-
values[field] = SPAN_STATUS_CODE_TO_NAME.get(result_row[field], "unknown")
423+
values.append({field: SPAN_STATUS_CODE_TO_NAME.get(result_row[field], "unknown")})
421424
else:
422425
value = result_row.get(field)
423426
if isinstance(value, list):
424427
if len(value) > 0:
425428
value = value[-1]
426429
else:
427430
value = ""
428-
values[field] = str(value)
431+
values.append({field: str(value)})
429432
return values
430433

431434

tests/snuba/api/endpoints/test_organization_events_timeseries.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_simple_top_events(self):
212212
timeseries = response.data["timeseries"][0]
213213
assert len(timeseries["values"]) == 3
214214
assert timeseries["axis"] == "count()"
215-
assert timeseries["groupBy"] == {"message": "very bad"}
215+
assert timeseries["groupBy"] == [{"message": "very bad"}]
216216
assert timeseries["meta"] == {
217217
"order": 0,
218218
"isOther": False,
@@ -238,7 +238,7 @@ def test_simple_top_events(self):
238238
timeseries = response.data["timeseries"][1]
239239
assert len(timeseries["values"]) == 3
240240
assert timeseries["axis"] == "p95()"
241-
assert timeseries["groupBy"] == {"message": "very bad"}
241+
assert timeseries["groupBy"] == [{"message": "very bad"}]
242242
assert timeseries["meta"] == {
243243
"order": 0,
244244
"isOther": False,
@@ -264,7 +264,7 @@ def test_simple_top_events(self):
264264
timeseries = response.data["timeseries"][2]
265265
assert len(timeseries["values"]) == 3
266266
assert timeseries["axis"] == "count()"
267-
assert timeseries["groupBy"] == {"message": "oh my"}
267+
assert timeseries["groupBy"] == [{"message": "oh my"}]
268268
assert timeseries["meta"] == {
269269
"order": 1,
270270
"isOther": False,
@@ -290,7 +290,7 @@ def test_simple_top_events(self):
290290
timeseries = response.data["timeseries"][3]
291291
assert len(timeseries["values"]) == 3
292292
assert timeseries["axis"] == "p95()"
293-
assert timeseries["groupBy"] == {"message": "oh my"}
293+
assert timeseries["groupBy"] == [{"message": "oh my"}]
294294
assert timeseries["meta"] == {
295295
"order": 1,
296296
"isOther": False,

0 commit comments

Comments
 (0)