Skip to content

Commit bfdd072

Browse files
committed
s/GroupingComponent/BaseGroupingComponent
1 parent 6c58c83 commit bfdd072

File tree

13 files changed

+91
-91
lines changed

13 files changed

+91
-91
lines changed

src/sentry/grouping/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
Here an example of how components can be used::
8888
8989
function_name = 'lambda$1234'
90-
threads = GroupingComponent(
90+
threads = BaseGroupingComponent(
9191
id="function",
9292
values=[function_name],
9393
contributes=False,

src/sentry/grouping/api.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sentry_sdk
99

1010
from sentry import options
11-
from sentry.grouping.component import GroupingComponent
11+
from sentry.grouping.component import BaseGroupingComponent
1212
from sentry.grouping.enhancer import LATEST_VERSION, Enhancements
1313
from sentry.grouping.enhancer.exceptions import InvalidEnhancerConfig
1414
from sentry.grouping.strategies.base import DEFAULT_GROUPING_ENHANCEMENTS_BASE, GroupingContext
@@ -264,10 +264,10 @@ def apply_server_fingerprinting(event, config, allow_custom_title=True):
264264

265265
def _get_calculated_grouping_variants_for_event(
266266
event: Event, context: GroupingContext
267-
) -> dict[str, GroupingComponent]:
267+
) -> dict[str, BaseGroupingComponent]:
268268
winning_strategy: str | None = None
269269
precedence_hint: str | None = None
270-
per_variant_components: dict[str, list[GroupingComponent]] = {}
270+
per_variant_components: dict[str, list[BaseGroupingComponent]] = {}
271271

272272
for strategy in context.config.iter_strategies():
273273
# Defined in src/sentry/grouping/strategies/base.py
@@ -292,7 +292,7 @@ def _get_calculated_grouping_variants_for_event(
292292

293293
rv = {}
294294
for variant, components in per_variant_components.items():
295-
component = GroupingComponent(id=variant, values=components)
295+
component = BaseGroupingComponent(id=variant, values=components)
296296
if not component.contributes and precedence_hint:
297297
component.update(hint=precedence_hint)
298298
rv[variant] = component

src/sentry/grouping/component.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,29 @@
2323
}
2424

2525

26-
def _calculate_contributes(values: Sequence[str | int | GroupingComponent]) -> bool:
26+
def _calculate_contributes(values: Sequence[str | int | BaseGroupingComponent]) -> bool:
2727
for value in values or ():
28-
if not isinstance(value, GroupingComponent) or value.contributes:
28+
if not isinstance(value, BaseGroupingComponent) or value.contributes:
2929
return True
3030
return False
3131

3232

33-
class GroupingComponent:
33+
class BaseGroupingComponent:
3434
"""A grouping component is a recursive structure that is flattened
3535
into components to make a hash for grouping purposes.
3636
"""
3737

3838
id: str = "default"
3939
hint: str | None
4040
contributes: bool
41-
values: Sequence[str | int | GroupingComponent]
41+
values: Sequence[str | int | BaseGroupingComponent]
4242

4343
def __init__(
4444
self,
4545
id: str | None = None,
4646
hint: str | None = None,
4747
contributes: bool | None = None,
48-
values: Sequence[str | int | GroupingComponent] | None = None,
48+
values: Sequence[str | int | BaseGroupingComponent] | None = None,
4949
variant_provider: bool = False,
5050
):
5151
self.id = id or self.id
@@ -54,7 +54,7 @@ def __init__(
5454
self.hint = DEFAULT_HINTS.get(self.id)
5555
self.contributes = contributes
5656
self.variant_provider = variant_provider
57-
self.values: Sequence[str | int | GroupingComponent] = []
57+
self.values: Sequence[str | int | BaseGroupingComponent] = []
5858

5959
self.update(
6060
hint=hint,
@@ -70,10 +70,10 @@ def name(self) -> str | None:
7070
def description(self) -> str:
7171
items = []
7272

73-
def _walk_components(c: GroupingComponent, stack: list[str | None]) -> None:
73+
def _walk_components(c: BaseGroupingComponent, stack: list[str | None]) -> None:
7474
stack.append(c.name)
7575
for value in c.values:
76-
if isinstance(value, GroupingComponent) and value.contributes:
76+
if isinstance(value, BaseGroupingComponent) and value.contributes:
7777
_walk_components(value, stack)
7878
parts = [_f for _f in stack if _f]
7979
items.append(parts)
@@ -89,16 +89,16 @@ def _walk_components(c: GroupingComponent, stack: list[str | None]) -> None:
8989

9090
def get_subcomponent(
9191
self, id: str, only_contributing: bool = False
92-
) -> str | int | GroupingComponent | None:
92+
) -> str | int | BaseGroupingComponent | None:
9393
"""Looks up a subcomponent by the id and returns the first or `None`."""
9494
return next(self.iter_subcomponents(id=id, only_contributing=only_contributing), None)
9595

9696
def iter_subcomponents(
9797
self, id: str, recursive: bool = False, only_contributing: bool = False
98-
) -> Iterator[str | int | GroupingComponent | None]:
98+
) -> Iterator[str | int | BaseGroupingComponent | None]:
9999
"""Finds all subcomponents matching an id, optionally recursively."""
100100
for value in self.values:
101-
if isinstance(value, GroupingComponent):
101+
if isinstance(value, BaseGroupingComponent):
102102
if only_contributing and not value.contributes:
103103
continue
104104
if value.id == id:
@@ -113,7 +113,7 @@ def update(
113113
self,
114114
hint: str | None = None,
115115
contributes: bool | None = None,
116-
values: Sequence[str | int | GroupingComponent] | None = None,
116+
values: Sequence[str | int | BaseGroupingComponent] | None = None,
117117
) -> None:
118118
"""Updates an already existing component with new values."""
119119
if hint is not None:
@@ -125,20 +125,20 @@ def update(
125125
if contributes is not None:
126126
self.contributes = contributes
127127

128-
def shallow_copy(self) -> GroupingComponent:
128+
def shallow_copy(self) -> BaseGroupingComponent:
129129
"""Creates a shallow copy."""
130130
rv = object.__new__(self.__class__)
131131
rv.__dict__.update(self.__dict__)
132132
rv.values = list(self.values)
133133
return rv
134134

135-
def iter_values(self) -> Generator[str | int | GroupingComponent]:
135+
def iter_values(self) -> Generator[str | int | BaseGroupingComponent]:
136136
"""Recursively walks the component and flattens it into a list of
137137
values.
138138
"""
139139
if self.contributes:
140140
for value in self.values:
141-
if isinstance(value, GroupingComponent):
141+
if isinstance(value, BaseGroupingComponent):
142142
yield from value.iter_values()
143143
else:
144144
yield value
@@ -160,7 +160,7 @@ def as_dict(self) -> dict[str, Any]:
160160
"values": [],
161161
}
162162
for value in self.values:
163-
if isinstance(value, GroupingComponent):
163+
if isinstance(value, BaseGroupingComponent):
164164
rv["values"].append(value.as_dict())
165165
else:
166166
# This basically assumes that a value is only a primitive

src/sentry/grouping/enhancer/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from sentry_ophio.enhancers import Enhancements as RustEnhancements
1616

1717
from sentry import projectoptions
18-
from sentry.grouping.component import GroupingComponent
18+
from sentry.grouping.component import BaseGroupingComponent
1919
from sentry.stacktraces.functions import set_in_app
2020
from sentry.utils.safe import get_path, set_path
2121

@@ -179,7 +179,7 @@ def assemble_stacktrace_component(self, components, frames, platform, exception_
179179
for py_component, rust_component in zip(components, rust_components):
180180
py_component.update(contributes=rust_component.contributes, hint=rust_component.hint)
181181

182-
component = GroupingComponent(
182+
component = BaseGroupingComponent(
183183
id="stacktrace",
184184
values=components,
185185
hint=rust_results.hint,

src/sentry/grouping/strategies/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from sentry import projectoptions
66
from sentry.eventstore.models import Event
7-
from sentry.grouping.component import GroupingComponent
7+
from sentry.grouping.component import BaseGroupingComponent, GroupingComponent
88
from sentry.grouping.enhancer import Enhancements
99
from sentry.interfaces.base import Interface
1010

@@ -117,7 +117,7 @@ def get_grouping_component(
117117

118118
def get_single_grouping_component(
119119
self, interface: Interface, *, event: Event, **kwargs: Any
120-
) -> GroupingComponent:
120+
) -> BaseGroupingComponent:
121121
"""Invokes a delegate grouping strategy. If no such delegate is
122122
configured a fallback grouping component is returned.
123123
"""
@@ -193,7 +193,7 @@ def variant_processor(self, func: VariantProcessor) -> VariantProcessor:
193193

194194
def get_grouping_component(
195195
self, event: Event, context: GroupingContext, variant: str | None = None
196-
) -> None | GroupingComponent | ReturnedVariants:
196+
) -> None | BaseGroupingComponent | ReturnedVariants:
197197
"""Given a specific variant this calculates the grouping component."""
198198
args = []
199199
iface = event.interfaces.get(self.interface)

src/sentry/grouping/strategies/legacy.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44

55
from sentry.eventstore.models import Event
6-
from sentry.grouping.component import GroupingComponent
6+
from sentry.grouping.component import BaseGroupingComponent
77
from sentry.grouping.strategies.base import (
88
GroupingContext,
99
ReturnedVariants,
@@ -164,17 +164,17 @@ def single_exception_legacy(
164164
interface: SingleException, event: Event, context: GroupingContext, **meta: Any
165165
) -> ReturnedVariants:
166166

167-
type_component = GroupingComponent(
167+
type_component = BaseGroupingComponent(
168168
id="type",
169169
values=[interface.type] if interface.type else [],
170170
contributes=False,
171171
)
172-
value_component = GroupingComponent(
172+
value_component = BaseGroupingComponent(
173173
id="value",
174174
values=[interface.value] if interface.value else [],
175175
contributes=False,
176176
)
177-
stacktrace_component = GroupingComponent(id="stacktrace")
177+
stacktrace_component = BaseGroupingComponent(id="stacktrace")
178178

179179
if interface.stacktrace is not None:
180180
stacktrace_component = context.get_single_grouping_component(
@@ -195,7 +195,7 @@ def single_exception_legacy(
195195
value_component.update(contributes=True)
196196

197197
return {
198-
context["variant"]: GroupingComponent(
198+
context["variant"]: BaseGroupingComponent(
199199
id="exception", values=[stacktrace_component, type_component, value_component]
200200
)
201201
}
@@ -231,7 +231,7 @@ def chained_exception_legacy(
231231
if stacktrace_component is None or not stacktrace_component.contributes:
232232
value.update(contributes=False, hint="exception has no stacktrace")
233233

234-
return {context["variant"]: GroupingComponent(id="chained-exception", values=values)}
234+
return {context["variant"]: BaseGroupingComponent(id="chained-exception", values=values)}
235235

236236

237237
@chained_exception_legacy.variant_processor
@@ -262,7 +262,7 @@ def frame_legacy(
262262
# Safari throws [native code] frames in for calls like ``forEach``
263263
# whereas Chrome ignores these. Let's remove it from the hashing algo
264264
# so that they're more likely to group together
265-
filename_component = GroupingComponent(id="filename")
265+
filename_component = BaseGroupingComponent(id="filename")
266266
if interface.filename == "<anonymous>":
267267
filename_component.update(
268268
contributes=False, values=[interface.filename], hint="anonymous filename discarded"
@@ -293,12 +293,12 @@ def frame_legacy(
293293
# if we have a module we use that for grouping. This will always
294294
# take precedence over the filename, even if the module is
295295
# considered unhashable.
296-
module_component = GroupingComponent(id="module")
296+
module_component = BaseGroupingComponent(id="module")
297297
if interface.module:
298298
if is_unhashable_module_legacy(interface, platform):
299299
module_component.update(
300300
values=[
301-
GroupingComponent(
301+
BaseGroupingComponent(
302302
id="salt", values=["<module>"], hint="normalized generated module name"
303303
)
304304
],
@@ -313,7 +313,7 @@ def frame_legacy(
313313
)
314314

315315
# Context line when available is the primary contributor
316-
context_line_component = GroupingComponent(id="context-line")
316+
context_line_component = BaseGroupingComponent(id="context-line")
317317
if interface.context_line is not None:
318318
if len(interface.context_line) > 120:
319319
context_line_component.update(hint="discarded because line too long")
@@ -322,9 +322,9 @@ def frame_legacy(
322322
else:
323323
context_line_component.update(values=[interface.context_line])
324324

325-
symbol_component = GroupingComponent(id="symbol")
326-
function_component = GroupingComponent(id="function")
327-
lineno_component = GroupingComponent(id="lineno")
325+
symbol_component = BaseGroupingComponent(id="symbol")
326+
function_component = BaseGroupingComponent(id="function")
327+
lineno_component = BaseGroupingComponent(id="lineno")
328328

329329
# The context line grouping information is the most reliable one.
330330
# If we did not manage to find some information there, we want to
@@ -347,7 +347,7 @@ def frame_legacy(
347347
if is_unhashable_function_legacy(func):
348348
function_component.update(
349349
values=[
350-
GroupingComponent(
350+
BaseGroupingComponent(
351351
id="salt", values=["<function>"], hint="normalized lambda function name"
352352
)
353353
]
@@ -380,7 +380,7 @@ def frame_legacy(
380380
)
381381

382382
return {
383-
context["variant"]: GroupingComponent(
383+
context["variant"]: BaseGroupingComponent(
384384
id="frame",
385385
values=[
386386
module_component,
@@ -461,7 +461,7 @@ def threads_legacy(
461461
thread_count = len(interface.values)
462462
if thread_count != 1:
463463
return {
464-
context["variant"]: GroupingComponent(
464+
context["variant"]: BaseGroupingComponent(
465465
id="threads",
466466
contributes=False,
467467
hint="ignored because contains %d threads" % thread_count,
@@ -471,13 +471,13 @@ def threads_legacy(
471471
stacktrace = interface.values[0].get("stacktrace")
472472
if not stacktrace:
473473
return {
474-
context["variant"]: GroupingComponent(
474+
context["variant"]: BaseGroupingComponent(
475475
id="threads", contributes=False, hint="thread has no stacktrace"
476476
)
477477
}
478478

479479
return {
480-
context["variant"]: GroupingComponent(
480+
context["variant"]: BaseGroupingComponent(
481481
id="threads",
482482
values=[context.get_single_grouping_component(stacktrace, event=event, **meta)],
483483
)

src/sentry/grouping/strategies/message.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sentry import analytics
55
from sentry.eventstore.models import Event
66
from sentry.features.rollout import in_rollout_group
7-
from sentry.grouping.component import GroupingComponent
7+
from sentry.grouping.component import BaseGroupingComponent
88
from sentry.grouping.parameterization import Parameterizer, UniqueIdExperiment
99
from sentry.grouping.strategies.base import (
1010
GroupingContext,
@@ -109,15 +109,15 @@ def message_v1(
109109
normalized = normalize_message_for_grouping(raw, event)
110110
hint = "stripped event-specific values" if raw != normalized else None
111111
return {
112-
context["variant"]: GroupingComponent(
112+
context["variant"]: BaseGroupingComponent(
113113
id="message",
114114
values=[normalized],
115115
hint=hint,
116116
)
117117
}
118118
else:
119119
return {
120-
context["variant"]: GroupingComponent(
120+
context["variant"]: BaseGroupingComponent(
121121
id="message",
122122
values=[interface.message or interface.formatted or ""],
123123
)

0 commit comments

Comments
 (0)