7
7
from django .db .models .signals import post_delete , post_save
8
8
from django .utils import timezone
9
9
10
- from sentry import features , tsdb
10
+ from sentry import tsdb
11
11
from sentry .backup .scopes import RelocationScope
12
12
from sentry .db .models import (
13
13
BaseManager ,
@@ -97,28 +97,20 @@ def is_valid(
97
97
return True
98
98
99
99
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 :
108
100
cache_key = f"groupsnooze:v1:{ self .id } :test_frequency_rate:events_seen_counter"
109
101
110
102
cache_ttl = self .window * 60 # Redis TTL in seconds (window is in minutes)
111
103
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
113
105
114
106
try :
115
- value = cache .incr (cache_key )
107
+ cached_event_count = cache .incr (cache_key )
116
108
cache .touch (cache_key , cache_ttl )
117
109
except ValueError :
118
110
# key doesn't exist, fall back on sentinel value
119
111
pass
120
112
121
- if value < self .count :
113
+ if cached_event_count < self .count :
122
114
metrics .incr ("groupsnooze.test_frequency_rates" , tags = {"cached" : "true" , "hit" : "true" })
123
115
return True
124
116
@@ -145,27 +137,6 @@ def test_frequency_rates_w_cache(self) -> bool:
145
137
146
138
return True
147
139
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
-
169
140
def test_user_rates_or_counts (self , group : Group ) -> bool :
170
141
"""
171
142
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:
178
149
to query Snuba. This functionality relies on the fact that this is called in
179
150
post-processing for every event, so we can assume that the call-count == event count.
180
151
"""
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 ():
195
154
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 ):
215
156
return False
216
-
217
157
return True
218
158
219
- def test_user_rates_w_cache (self ) -> bool :
159
+ def test_user_rates (self ) -> bool :
220
160
cache_key = f"groupsnooze:v1:{ self .id } :test_user_rate:events_seen_counter"
221
161
222
162
cache_ttl = self .user_window * 60 # Redis TTL in seconds (window is in minutes)
223
163
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
225
165
226
166
try :
227
- value = cache .incr (cache_key )
167
+ cached_event_count = cache .incr (cache_key )
228
168
cache .touch (cache_key , cache_ttl )
229
169
except ValueError :
230
170
# key doesn't exist, fall back on sentinel value
231
171
pass
232
172
233
- if value < self .user_count :
173
+ if cached_event_count < self .user_count :
234
174
# if number of hits within the window is less than the threshold, we can't have reached enough users
235
175
metrics .incr ("groupsnooze.test_user_rates" , tags = {"cached" : "true" , "hit" : "true" })
236
176
return True
@@ -258,17 +198,7 @@ def test_user_rates_w_cache(self) -> bool:
258
198
259
199
return True
260
200
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 :
272
202
cache_key = f"groupsnooze:v1:{ self .id } :test_user_counts:events_seen_counter"
273
203
try :
274
204
users_seen = self .state ["users_seen" ]
@@ -279,14 +209,14 @@ def test_user_counts_w_cache(self, group: Group) -> bool:
279
209
280
210
CACHE_TTL = 3600 # Redis TTL in seconds
281
211
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
283
213
try :
284
- value = cache .incr (cache_key )
214
+ cached_event_count = cache .incr (cache_key )
285
215
except ValueError :
286
216
# key doesn't exist, fall back on sentinel value
287
217
pass
288
218
289
- if value < threshold :
219
+ if cached_event_count < threshold :
290
220
# if we've seen less than that many events, we can't possibly have seen enough users
291
221
metrics .incr ("groupsnooze.test_user_counts" , tags = {"cached" : "true" , "hit" : "true" })
292
222
return True
0 commit comments