Skip to content

Commit 0381882

Browse files
author
Bartek Ogryczak
authored
chore(issues): post GA cleanup for GroupSnooze caches (#69975)
Cleaning up #69556 and #69939 Also changing cached `value` to more meaningful names.
1 parent 062e5df commit 0381882

File tree

4 files changed

+15
-102
lines changed

4 files changed

+15
-102
lines changed

src/sentry/conf/server.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,10 +1577,6 @@ def custom_parameter_sort(parameter: dict) -> tuple[str, int]:
15771577
"organizations:grouping-title-ui": False,
15781578
# Enable experimental new version of Merged Issues where sub-hashes are shown
15791579
"organizations:grouping-tree-ui": False,
1580-
# Enable caching group counts in GroupSnooze
1581-
"organizations:groupsnooze-cached-counts": False,
1582-
# Enable caching group frequency rates in GroupSnooze
1583-
"organizations:groupsnooze-cached-rates": False,
15841580
# Allows an org to have a larger set of project ownership rules per project
15851581
"organizations:higher-ownership-limit": False,
15861582
# Enable incidents feature

src/sentry/features/temporary.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ def register_temporary_features(manager: FeatureManager):
7777
manager.add("organizations:grouping-suppress-unnecessary-secondary-hash", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
7878
manager.add("organizations:grouping-title-ui", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
7979
manager.add("organizations:grouping-tree-ui", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
80-
manager.add("organizations:groupsnooze-cached-counts", OrganizationFeature, FeatureHandlerStrategy.OPTIONS)
81-
manager.add("organizations:groupsnooze-cached-rates", OrganizationFeature, FeatureHandlerStrategy.OPTIONS)
8280
manager.add("organizations:higher-ownership-limit", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
8381
manager.add("organizations:increased-issue-owners-rate-limit", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
8482
manager.add("organizations:integrations-custom-alert-priorities", OrganizationFeature, FeatureHandlerStrategy.REMOTE)

src/sentry/models/groupsnooze.py

Lines changed: 15 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.db.models.signals import post_delete, post_save
88
from django.utils import timezone
99

10-
from sentry import features, tsdb
10+
from sentry import tsdb
1111
from sentry.backup.scopes import RelocationScope
1212
from sentry.db.models import (
1313
BaseManager,
@@ -97,28 +97,20 @@ def is_valid(
9797
return True
9898

9999
def test_frequency_rates(self) -> bool:
100-
if features.has(
101-
"organizations:groupsnooze-cached-rates", organization=self.group.project.organization
102-
):
103-
return self.test_frequency_rates_w_cache()
104-
else:
105-
return self.test_frequency_rates_no_cache()
106-
107-
def test_frequency_rates_w_cache(self) -> bool:
108100
cache_key = f"groupsnooze:v1:{self.id}:test_frequency_rate:events_seen_counter"
109101

110102
cache_ttl = self.window * 60 # Redis TTL in seconds (window is in minutes)
111103

112-
value: int | float = float("inf") # using +inf as a sentinel value
104+
cached_event_count: int | float = float("inf") # using +inf as a sentinel value
113105

114106
try:
115-
value = cache.incr(cache_key)
107+
cached_event_count = cache.incr(cache_key)
116108
cache.touch(cache_key, cache_ttl)
117109
except ValueError:
118110
# key doesn't exist, fall back on sentinel value
119111
pass
120112

121-
if value < self.count:
113+
if cached_event_count < self.count:
122114
metrics.incr("groupsnooze.test_frequency_rates", tags={"cached": "true", "hit": "true"})
123115
return True
124116

@@ -145,27 +137,6 @@ def test_frequency_rates_w_cache(self) -> bool:
145137

146138
return True
147139

148-
def test_frequency_rates_no_cache(self) -> bool:
149-
metrics.incr("groupsnooze.test_frequency_rates", tags={"cached": "false"})
150-
metrics.incr("groupsnooze.test_frequency_rates.snuba_call")
151-
152-
end = timezone.now()
153-
start = end - timedelta(minutes=self.window)
154-
155-
rate = tsdb.backend.get_sums(
156-
model=get_issue_tsdb_group_model(self.group.issue_category),
157-
keys=[self.group_id],
158-
start=start,
159-
end=end,
160-
tenant_ids={"organization_id": self.group.project.organization_id},
161-
referrer_suffix="frequency_snoozes",
162-
)[self.group_id]
163-
164-
if rate >= self.count:
165-
return False
166-
167-
return True
168-
169140
def test_user_rates_or_counts(self, group: Group) -> bool:
170141
"""
171142
Test if the number of unique users or rate of users seen by the group is below the snooze threshold.
@@ -178,59 +149,28 @@ def test_user_rates_or_counts(self, group: Group) -> bool:
178149
to query Snuba. This functionality relies on the fact that this is called in
179150
post-processing for every event, so we can assume that the call-count == event count.
180151
"""
181-
if features.has(
182-
"organizations:groupsnooze-cached-counts", organization=self.group.project.organization
183-
):
184-
if self.user_window:
185-
if not self.test_user_rates_w_cache():
186-
return False
187-
elif not self.test_user_counts_w_cache(group):
188-
return False
189-
return True
190-
else:
191-
if self.user_window:
192-
if not self.test_user_rates_no_cache():
193-
return False
194-
elif not self.test_user_counts_no_cache(group):
152+
if self.user_window:
153+
if not self.test_user_rates():
195154
return False
196-
return True
197-
198-
def test_user_rates_no_cache(self) -> bool:
199-
metrics.incr("groupsnooze.test_user_rates", tags={"cached": "false"})
200-
metrics.incr("groupsnooze.test_user_rates.snuba_call")
201-
202-
end = timezone.now()
203-
start = end - timedelta(minutes=self.user_window)
204-
205-
rate = tsdb.backend.get_distinct_counts_totals(
206-
model=get_issue_tsdb_user_group_model(self.group.issue_category),
207-
keys=[self.group_id],
208-
start=start,
209-
end=end,
210-
tenant_ids={"organization_id": self.group.project.organization_id},
211-
referrer_suffix="user_count_snoozes",
212-
)[self.group_id]
213-
214-
if rate >= self.user_count:
155+
elif not self.test_user_counts(group):
215156
return False
216-
217157
return True
218158

219-
def test_user_rates_w_cache(self) -> bool:
159+
def test_user_rates(self) -> bool:
220160
cache_key = f"groupsnooze:v1:{self.id}:test_user_rate:events_seen_counter"
221161

222162
cache_ttl = self.user_window * 60 # Redis TTL in seconds (window is in minutes)
223163

224-
value: int | float = float("inf") # using +inf as a sentinel value
164+
cached_event_count: int | float = float("inf") # using +inf as a sentinel value
225165

226166
try:
227-
value = cache.incr(cache_key)
167+
cached_event_count = cache.incr(cache_key)
228168
cache.touch(cache_key, cache_ttl)
229169
except ValueError:
230170
# key doesn't exist, fall back on sentinel value
231171
pass
232172

233-
if value < self.user_count:
173+
if cached_event_count < self.user_count:
234174
# if number of hits within the window is less than the threshold, we can't have reached enough users
235175
metrics.incr("groupsnooze.test_user_rates", tags={"cached": "true", "hit": "true"})
236176
return True
@@ -258,17 +198,7 @@ def test_user_rates_w_cache(self) -> bool:
258198

259199
return True
260200

261-
def test_user_counts_no_cache(self, group: Group) -> bool:
262-
metrics.incr("groupsnooze.test_user_counts", tags={"cached": "false"})
263-
metrics.incr("groupsnooze.test_user_counts.snuba_call")
264-
265-
threshold = self.user_count + self.state["users_seen"]
266-
real_count = group.count_users_seen(
267-
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_GROUP_SNOOZE.value
268-
)
269-
return real_count < threshold
270-
271-
def test_user_counts_w_cache(self, group: Group) -> bool:
201+
def test_user_counts(self, group: Group) -> bool:
272202
cache_key = f"groupsnooze:v1:{self.id}:test_user_counts:events_seen_counter"
273203
try:
274204
users_seen = self.state["users_seen"]
@@ -279,14 +209,14 @@ def test_user_counts_w_cache(self, group: Group) -> bool:
279209

280210
CACHE_TTL = 3600 # Redis TTL in seconds
281211

282-
value: int | float = float("inf") # using +inf as a sentinel value
212+
cached_event_count: int | float = float("inf") # using +inf as a sentinel value
283213
try:
284-
value = cache.incr(cache_key)
214+
cached_event_count = cache.incr(cache_key)
285215
except ValueError:
286216
# key doesn't exist, fall back on sentinel value
287217
pass
288218

289-
if value < threshold:
219+
if cached_event_count < threshold:
290220
# if we've seen less than that many events, we can't possibly have seen enough users
291221
metrics.incr("groupsnooze.test_user_counts", tags={"cached": "true", "hit": "true"})
292222
return True

tests/sentry/models/test_groupsnooze.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from sentry.models.groupsnooze import GroupSnooze
1111
from sentry.testutils.cases import PerformanceIssueTestCase, SnubaTestCase, TestCase
1212
from sentry.testutils.helpers.datetime import before_now, freeze_time, iso_format
13-
from sentry.testutils.helpers.features import apply_feature_flag_on_cls
1413
from sentry.utils.samples import load_data
1514
from tests.sentry.issues.test_utils import SearchIssueTestMixin
1615

@@ -188,16 +187,6 @@ def test_rate_reached_generic_issue(self):
188187
snooze = GroupSnooze.objects.create(group=generic_group, count=10, window=24 * 60)
189188
assert not snooze.is_valid(test_rates=True)
190189

191-
192-
@apply_feature_flag_on_cls("organizations:groupsnooze-cached-counts")
193-
@apply_feature_flag_on_cls("organizations:groupsnooze-cached-rates")
194-
class GroupSnoozeWCacheTest(GroupSnoozeTest):
195-
"""
196-
Test the cached version of the snooze.
197-
Runs all the test defined in GroupSnoozeTest with the cached version of the snooze.
198-
Plus the tests defined below.
199-
"""
200-
201190
def test_test_user_rates_w_cache(self):
202191
snooze = GroupSnooze.objects.create(group=self.group, user_count=100, user_window=60)
203192

0 commit comments

Comments
 (0)