Skip to content

Commit efb8a85

Browse files
armenzglobsterkatiegetsantry[bot]
authored
feat(grouping): Method to upgrade deprecated configs (#74203)
This will allow upgrading projects with a grouping configuration marked as deprecated. The project will also get the auto updates config set to `True` to prevent them from falling behind. This [PR](getsentry/getsentry#14616) is to run the upgrades. --------- Co-authored-by: Katie Byers <[email protected]> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent 328f162 commit efb8a85

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/sentry/grouping/ingest/config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
Job = MutableMapping[str, Any]
1919

20+
# We are moving all projects off these configuration without waiting for events
21+
CONFIGS_TO_DEPRECATE: list[str] = []
22+
2023

2124
def update_grouping_config_if_needed(project: Project) -> None:
2225
if _project_should_update_grouping(project):
@@ -27,7 +30,9 @@ def _project_should_update_grouping(project: Project) -> bool:
2730
should_update_org = (
2831
project.organization_id % 1000 < float(settings.SENTRY_GROUPING_AUTO_UPDATE_ENABLED) * 1000
2932
)
30-
return bool(project.get_option("sentry:grouping_auto_update")) and should_update_org
33+
is_deprecated_config = project.get_option("sentry:grouping_config") in CONFIGS_TO_DEPRECATE
34+
auto_update = bool(project.get_option("sentry:grouping_auto_update"))
35+
return is_deprecated_config or (auto_update and should_update_org)
3136

3237

3338
def _config_update_happened_recently(project: Project, tolerance: int) -> bool:
@@ -79,6 +84,12 @@ def _auto_update_grouping(project: Project) -> None:
7984
"sentry:secondary_grouping_expiry": expiry,
8085
"sentry:grouping_config": new_config,
8186
}
87+
# Any project on deprecated configs may be there only because auto updates are
88+
# disabled (not because they want to use that specific config). This will reduce the
89+
# chance of that happening unintentionally.
90+
if current_config in CONFIGS_TO_DEPRECATE:
91+
changes["sentry:grouping_auto_update"] = True
92+
8293
for key, value in changes.items():
8394
project.update_option(key, value)
8495

tests/sentry/event_manager/test_event_manager_grouping.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from sentry.conf.server import SENTRY_GROUPING_UPDATE_MIGRATION_PHASE
1313
from sentry.event_manager import _get_updated_group_title
1414
from sentry.eventtypes.base import DefaultEvent
15+
from sentry.grouping.ingest.config import update_grouping_config_if_needed
1516
from sentry.grouping.result import CalculatedHashes
1617
from sentry.models.auditlogentry import AuditLogEntry
1718
from sentry.models.group import Group
@@ -171,6 +172,37 @@ def test_auto_updates_grouping_config(self):
171172
)
172173
assert actual_expiry == expected_expiry or actual_expiry == expected_expiry - 1
173174

175+
def test_disabled_auto_update_does_not_update(self):
176+
self.project.update_option("sentry:grouping_config", LEGACY_CONFIG)
177+
178+
with override_settings(SENTRY_GROUPING_AUTO_UPDATE_ENABLED=True):
179+
self.project.update_option("sentry:grouping_auto_update", False)
180+
save_new_event({"message": "foo"}, self.project)
181+
# It does not update the config because it is False
182+
assert self.project.get_option("sentry:grouping_config") == LEGACY_CONFIG
183+
184+
def test_deprecated_configs_upgrade_automatically(self):
185+
# This is not yet a deprecated config but we will simulate it
186+
self.project.update_option("sentry:grouping_config", "mobile:2021-02-12")
187+
self.project.update_option("sentry:grouping_auto_update", False)
188+
189+
with override_settings(SENTRY_GROUPING_AUTO_UPDATE_ENABLED=True):
190+
update_grouping_config_if_needed(self.project)
191+
# Nothing changes
192+
assert self.project.get_option("sentry:grouping_config") == "mobile:2021-02-12"
193+
assert self.project.get_option("sentry:grouping_auto_update") is False
194+
195+
# XXX: In the future, once the mobile grouping is added to the list, we will remove this line
196+
with mock.patch(
197+
"sentry.grouping.ingest.config.CONFIGS_TO_DEPRECATE",
198+
new=["mobile:2021-02-12"],
199+
):
200+
update_grouping_config_if_needed(self.project)
201+
# Even though auto update is disabled we have upgraded the project
202+
assert self.project.get_option("sentry:grouping_config") == DEFAULT_GROUPING_CONFIG
203+
# We have also updated the auto_update option
204+
assert self.project.get_option("sentry:grouping_auto_update") is True
205+
174206

175207
class PlaceholderTitleTest(TestCase):
176208
"""

0 commit comments

Comments
 (0)