Skip to content

Commit 33e5127

Browse files
cvxluoclaude
andauthored
ref(grouping): remove dead background grouping code (#112594)
The `store.background-grouping-sample-rate` option has been 0 for a long time, making all background grouping code dead. Remove the functions, config loader, option registrations, call site in `event_manager`, and associated tests. Co-authored-by: Claude <noreply@anthropic.com>
1 parent c8d30a3 commit 33e5127

File tree

5 files changed

+0
-91
lines changed

5 files changed

+0
-91
lines changed

src/sentry/event_manager.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
from sentry.grouping.ingest.hashing import (
6666
find_grouphash_with_group,
6767
get_or_create_grouphashes,
68-
maybe_run_background_grouping,
6968
maybe_run_secondary_grouping,
7069
run_primary_grouping,
7170
)
@@ -1358,11 +1357,6 @@ def assign_event_to_group(
13581357

13591358
# From here on out, we're just doing housekeeping
13601359

1361-
# Background grouping is a way for us to get performance metrics for a new
1362-
# config without having it actually affect on how events are grouped. It runs
1363-
# either before or after the main grouping logic, depending on the option value.
1364-
maybe_run_background_grouping(project, job)
1365-
13661360
record_hash_calculation_metrics(
13671361
project, primary.config, primary.hashes, secondary.config, secondary.hashes, result
13681362
)

src/sentry/grouping/api.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import sentry_sdk
99

10-
from sentry import options
1110
from sentry.conf.server import DEFAULT_GROUPING_CONFIG
1211
from sentry.grouping.component import ContributingComponent, RootGroupingComponent
1312
from sentry.grouping.context import GroupingContext
@@ -149,15 +148,6 @@ class SecondaryGroupingConfigLoader(ProjectGroupingConfigLoader):
149148
cache_prefix = "secondary-grouping-enhancements:"
150149

151150

152-
class BackgroundGroupingConfigLoader(GroupingConfigLoader):
153-
"""Does not affect grouping, runs in addition to measure performance impact"""
154-
155-
cache_prefix = "background-grouping-enhancements:"
156-
157-
def _get_config_id(self, _project: Project) -> str:
158-
return options.get("store.background-grouping-config-id")
159-
160-
161151
@sentry_sdk.tracing.trace
162152
def get_grouping_config_dict_for_project(project: Project) -> GroupingConfig:
163153
"""Fetches all the information necessary for grouping from the project

src/sentry/grouping/ingest/hashing.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from sentry.exceptions import HashDiscarded
1313
from sentry.grouping.api import (
1414
NULL_GROUPING_CONFIG,
15-
BackgroundGroupingConfigLoader,
1615
GroupingConfig,
1716
SecondaryGroupingConfigLoader,
1817
apply_server_side_fingerprinting,
@@ -32,7 +31,6 @@
3231
from sentry.grouping.variants import BaseVariant
3332
from sentry.models.grouphash import GroupHash
3433
from sentry.models.project import Project
35-
from sentry.options.rollout import in_random_rollout
3634
from sentry.utils import metrics
3735
from sentry.utils.metrics import MutableTags
3836
from sentry.utils.tag_normalization import normalized_sdk_tag_from_event
@@ -80,35 +78,6 @@ def _calculate_event_grouping(
8078
return (hashes, variants)
8179

8280

83-
def maybe_run_background_grouping(project: Project, job: Job) -> None:
84-
"""
85-
Optionally run a fraction of events with an experimental grouping config.
86-
87-
This does not affect actual grouping, but can be helpful to measure the new config's performance
88-
impact.
89-
"""
90-
try:
91-
if in_random_rollout("store.background-grouping-sample-rate"):
92-
config = BackgroundGroupingConfigLoader().get_config_dict(project)
93-
if config["id"]:
94-
copied_event = copy.deepcopy(job["event"])
95-
_calculate_background_grouping(project, copied_event, config)
96-
except Exception as err:
97-
sentry_sdk.capture_exception(err)
98-
99-
100-
def _calculate_background_grouping(
101-
project: Project, event: Event, config: GroupingConfig
102-
) -> list[str]:
103-
metric_tags: MutableTags = {
104-
"grouping_config": config["id"],
105-
"platform": event.platform or "unknown",
106-
"sdk": normalized_sdk_tag_from_event(event.data),
107-
}
108-
with metrics.timer("event_manager.background_grouping", tags=metric_tags):
109-
return _calculate_event_grouping(project, event, config)[0]
110-
111-
11281
def maybe_run_secondary_grouping(
11382
project: Project, job: Job, metric_tags: MutableTags
11483
) -> tuple[GroupingConfig, list[str], dict[str, BaseVariant]]:

src/sentry/options/defaults.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,16 +1460,6 @@
14601460
flags=FLAG_MODIFIABLE_BOOL | FLAG_AUTOMATOR_MODIFIABLE,
14611461
)
14621462

1463-
# Run an experimental grouping config in background for performance analysis
1464-
register("store.background-grouping-config-id", default=None, flags=FLAG_AUTOMATOR_MODIFIABLE)
1465-
1466-
# Fraction of events that will pass through background grouping
1467-
register(
1468-
"store.background-grouping-sample-rate",
1469-
default=0.0,
1470-
flags=FLAG_AUTOMATOR_MODIFIABLE,
1471-
)
1472-
14731463
# Minimum number of files in an archive. Archives with fewer files are extracted and have their
14741464
# contents stored as separate release files.
14751465
register("processing.release-archive-min-files", default=10, flags=FLAG_AUTOMATOR_MODIFIABLE)

tests/sentry/grouping/test_hashing.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,12 @@
1818
from sentry.services.eventstore.models import Event
1919
from sentry.testutils.cases import TestCase
2020
from sentry.testutils.helpers.eventprocessing import save_new_event
21-
from sentry.testutils.helpers.options import override_options
2221
from sentry.testutils.skips import requires_snuba
2322
from tests.sentry.grouping import NO_MSG_PARAM_CONFIG
2423

2524
pytestmark = [requires_snuba]
2625

2726

28-
class BackgroundGroupingTest(TestCase):
29-
@override_options({"store.background-grouping-config-id": NO_MSG_PARAM_CONFIG})
30-
@patch("sentry.grouping.ingest.hashing._calculate_background_grouping")
31-
def test_background_grouping_sample_rate(
32-
self, mock_calc_background_grouping: MagicMock
33-
) -> None:
34-
with override_options({"store.background-grouping-sample-rate": 0.0}):
35-
save_new_event({"message": "Dogs are great! 1231"}, self.project)
36-
assert mock_calc_background_grouping.call_count == 0
37-
38-
with override_options({"store.background-grouping-sample-rate": 1.0}):
39-
save_new_event({"message": "Dogs are great! 1121"}, self.project)
40-
assert mock_calc_background_grouping.call_count == 1
41-
42-
@override_options({"store.background-grouping-config-id": NO_MSG_PARAM_CONFIG})
43-
@override_options({"store.background-grouping-sample-rate": 1.0})
44-
@patch("sentry_sdk.capture_exception")
45-
def test_handles_errors_with_background_grouping(
46-
self, mock_capture_exception: MagicMock
47-
) -> None:
48-
background_grouping_error = Exception("nope")
49-
50-
with patch(
51-
"sentry.grouping.ingest.hashing._calculate_background_grouping",
52-
side_effect=background_grouping_error,
53-
):
54-
event = save_new_event({"message": "Dogs are great! 1231"}, self.project)
55-
56-
mock_capture_exception.assert_called_with(background_grouping_error)
57-
# This proves the background grouping crash didn't crash the overall grouping process
58-
assert event.group
59-
60-
6127
class SecondaryGroupingTest(TestCase):
6228
def test_applies_secondary_grouping(self) -> None:
6329
project = self.project

0 commit comments

Comments
 (0)