Skip to content

Commit e26681e

Browse files
authored
ref(grouping): Move grouping config to top level of grouping info (#101281)
This changes the format of the grouping info API response, so that instead of the full serialized grouping config being included in every variant, only the grouping config id is included at the top level of the JSON, and the variants in turn are included under a new `variants` key. In other words, it changes from a response that looks like this: { app_exception_stacktrace: { ..., config: { id: "newstyle:whatever", // the only part of `config` we actually care about ... } }, system_exception_stacktrace: { ..., config: { id: "newstyle:whatever", // we don't need this twice ... } } } to one which looks like this: { grouping_config: "newstyle:whatever", variants: { app_exception_stacktrace: {...}, system_exception_stacktrace: {...} } } This not only removes redundancy (along with a bunch of information about the config we don't need), it also sets us up to be able to send other grouping-info-wide information in the response. Note: Before this can be merged, the front end needs to be adjusted to [work with both the old and new formats](#102820). Once that's deployed, and this is merged and deployed, we can [remove old-format handling from the front end](#101223).
1 parent 67f7ba5 commit e26681e

File tree

376 files changed

+288547
-300538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

376 files changed

+288547
-300538
lines changed

src/sentry/grouping/grouping_info.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def get_grouping_info(
1414
grouping_config: StrategyConfiguration, project: Project, event: Event | GroupEvent
15-
) -> dict[str, dict[str, Any]]:
15+
) -> dict[str, Any]:
1616
# We always fetch the stored hashes here. The reason for this is
1717
# that we want to show in the UI if the forced grouping algorithm
1818
# produced hashes that would normally also appear in the event.
@@ -43,7 +43,7 @@ def _check_for_mismatched_hashes(
4343
The result is stored with each variant and recorded as a metric.
4444
"""
4545

46-
for variant_dict in grouping_info.values():
46+
for variant_dict in grouping_info["variants"].values():
4747
hash_value = variant_dict["hash"]
4848

4949
# Since the hashes are generated on the fly and might no
@@ -125,18 +125,29 @@ def get_grouping_info_from_variants_legacy(
125125

126126
def get_grouping_info_from_variants(
127127
variants: dict[str, BaseVariant],
128-
) -> dict[str, dict[str, Any]]:
128+
) -> dict[str, Any]:
129129
"""
130130
Given a dictionary of variant objects, create and return a copy of the dictionary in which each
131131
variant object value has been transformed into an equivalent dictionary value, which knows the
132132
key under which it lives.
133133
"""
134134

135-
return {
135+
grouping_config_id = None
136+
for variant in variants.values():
137+
grouping_config_id = variant.config.id if hasattr(variant, "config") else None
138+
if grouping_config_id:
139+
break
140+
141+
variants_json = {
136142
# Overwrite the description with a new, improved version
137143
variant.key: {
138144
**variant.as_dict(),
139145
"description": _get_new_description(variant),
140146
}
141147
for variant in variants.values()
142148
}
149+
150+
return {
151+
"grouping_config": grouping_config_id,
152+
"variants": variants_json,
153+
}

src/sentry/grouping/variants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def get_hash(self) -> str | None:
154154
return self.root_component.get_hash()
155155

156156
def _get_metadata_as_dict(self) -> Mapping[str, Any]:
157-
return {"component": self.root_component.as_dict(), "config": self.config.as_dict()}
157+
return {"component": self.root_component.as_dict()}
158158

159159
def __repr__(self) -> str:
160160
return super().__repr__() + f" contributes={self.contributes} ({self.description})"

0 commit comments

Comments
 (0)