@@ -190,7 +190,7 @@ def passes(self, event: GroupEvent, state: EventState) -> bool:
190
190
return current_value > value
191
191
192
192
def passes_activity_frequency (
193
- self , activity : ConditionActivity , buckets : dict [datetime , int ]
193
+ self , activity : ConditionActivity , buckets : dict [datetime , int | float ]
194
194
) -> bool :
195
195
interval , value = self ._get_options ()
196
196
if not (interval and value is not None ):
@@ -221,15 +221,17 @@ def passes_activity_frequency(
221
221
def get_preview_aggregate (self ) -> tuple [str , str ]:
222
222
raise NotImplementedError
223
223
224
- def query (self , event : GroupEvent , start : datetime , end : datetime , environment_id : int ) -> int :
224
+ def query (
225
+ self , event : GroupEvent , start : datetime , end : datetime , environment_id : int
226
+ ) -> int | float :
225
227
"""
226
228
Queries Snuba for a unique condition for a single group.
227
229
"""
228
230
return self .query_hook (event , start , end , environment_id )
229
231
230
232
def query_hook (
231
233
self , event : GroupEvent , start : datetime , end : datetime , environment_id : int
232
- ) -> int :
234
+ ) -> int | float :
233
235
"""
234
236
Abstract method that specifies how to query Snuba for a single group
235
237
depending on the condition. Must be implemented by subclasses.
@@ -238,15 +240,15 @@ def query_hook(
238
240
239
241
def batch_query (
240
242
self , group_ids : set [int ], start : datetime , end : datetime , environment_id : int
241
- ) -> dict [int , int ]:
243
+ ) -> dict [int , int | float ]:
242
244
"""
243
245
Queries Snuba for a unique condition for multiple groups.
244
246
"""
245
247
return self .batch_query_hook (group_ids , start , end , environment_id )
246
248
247
249
def batch_query_hook (
248
250
self , group_ids : set [int ], start : datetime , end : datetime , environment_id : int
249
- ) -> dict [int , int ]:
251
+ ) -> dict [int , int | float ]:
250
252
"""
251
253
Abstract method that specifies how to query Snuba for multiple groups
252
254
depending on the condition. Must be implemented by subclasses.
@@ -279,7 +281,7 @@ def get_rate(
279
281
event : GroupEvent ,
280
282
environment_id : int ,
281
283
comparison_type : str ,
282
- ) -> int :
284
+ ) -> int | float :
283
285
current_time = timezone .now ()
284
286
start , end = self .get_query_window (end = current_time , duration = duration )
285
287
with self .disable_consistent_snuba_mode (duration ):
@@ -302,7 +304,7 @@ def get_rate_bulk(
302
304
environment_id : int ,
303
305
current_time : datetime ,
304
306
comparison_interval : timedelta | None ,
305
- ) -> dict [int , int ]:
307
+ ) -> dict [int , int | float ]:
306
308
"""
307
309
Make a batch query for multiple groups. The return value is a dictionary
308
310
of group_id to the result for that group.
@@ -434,8 +436,8 @@ def query_hook(
434
436
435
437
def batch_query_hook (
436
438
self , group_ids : set [int ], start : datetime , end : datetime , environment_id : int
437
- ) -> dict [int , int ]:
438
- batch_sums : dict [int , int ] = defaultdict (int )
439
+ ) -> dict [int , int | float ]:
440
+ batch_sums : dict [int , int | float ] = defaultdict (int )
439
441
groups = Group .objects .filter (id__in = group_ids ).values (
440
442
"id" , "type" , "project_id" , "project__organization_id"
441
443
)
@@ -497,8 +499,8 @@ def query_hook(
497
499
498
500
def batch_query_hook (
499
501
self , group_ids : set [int ], start : datetime , end : datetime , environment_id : int
500
- ) -> dict [int , int ]:
501
- batch_totals : dict [int , int ] = defaultdict (int )
502
+ ) -> dict [int , int | float ]:
503
+ batch_totals : dict [int , int | float ] = defaultdict (int )
502
504
groups = Group .objects .filter (id__in = group_ids ).values (
503
505
"id" , "type" , "project_id" , "project__organization_id"
504
506
)
@@ -583,7 +585,7 @@ def query_hook(
583
585
584
586
def batch_query_hook (
585
587
self , group_ids : set [int ], start : datetime , end : datetime , environment_id : int
586
- ) -> dict [int , int ]:
588
+ ) -> dict [int , int | float ]:
587
589
logger = logging .getLogger (
588
590
"sentry.rules.event_frequency.EventUniqueUserFrequencyConditionWithConditions"
589
591
)
@@ -609,7 +611,7 @@ def batch_query_hook(
609
611
raise NotImplementedError (
610
612
"EventUniqueUserFrequencyConditionWithConditions does not support filter_match == any"
611
613
)
612
- batch_totals : dict [int , int ] = defaultdict (int )
614
+ batch_totals : dict [int , int | float ] = defaultdict (int )
613
615
groups = Group .objects .filter (id__in = group_ids ).values (
614
616
"id" , "type" , "project_id" , "project__organization_id"
615
617
)
@@ -723,7 +725,7 @@ def get_chunked_result(
723
725
724
726
@staticmethod
725
727
def convert_rule_condition_to_snuba_condition (
726
- condition : dict [str , Any ]
728
+ condition : dict [str , Any ],
727
729
) -> tuple [str , str , str | list [str ]] | None :
728
730
if condition ["id" ] != "sentry.rules.filters.tagged_event.TaggedEventFilter" :
729
731
return None
@@ -863,7 +865,7 @@ def get_session_interval(self, session_count: int, interval: str) -> int | None:
863
865
864
866
def query_hook (
865
867
self , event : GroupEvent , start : datetime , end : datetime , environment_id : int
866
- ) -> int :
868
+ ) -> float :
867
869
project_id = event .project_id
868
870
session_count_last_hour = self .get_session_count (project_id , environment_id , start , end )
869
871
avg_sessions_in_interval = self .get_session_interval (
@@ -892,14 +894,14 @@ def query_hook(
892
894
"avg_sessions_in_interval" : avg_sessions_in_interval ,
893
895
},
894
896
)
895
- percent : int = int ( 100 * round (issue_count / avg_sessions_in_interval , 4 ) )
897
+ percent : float = 100 * round (issue_count / avg_sessions_in_interval , 4 )
896
898
return percent
897
899
898
900
return 0
899
901
900
902
def batch_query_hook (
901
903
self , group_ids : set [int ], start : datetime , end : datetime , environment_id : int
902
- ) -> dict [int , int ]:
904
+ ) -> dict [int , int | float ]:
903
905
groups = Group .objects .filter (id__in = group_ids ).values (
904
906
"id" , "type" , "project_id" , "project__organization_id"
905
907
)
@@ -933,34 +935,35 @@ def batch_query_hook(
933
935
referrer_suffix = "batch_alert_event_frequency_percent" ,
934
936
)
935
937
936
- batch_percents : dict [int , int ] = {}
938
+ batch_percents : dict [int , int | float ] = {}
937
939
for group_id , count in error_issue_count .items ():
938
- percent : int = int ( 100 * round (count / avg_sessions_in_interval , 4 ) )
940
+ percent : float = 100 * round (count / avg_sessions_in_interval , 4 )
939
941
batch_percents [group_id ] = percent
940
942
941
943
# We do not have sessions for non-error issue types
942
944
for group in generic_issue_ids :
943
945
batch_percents [group ] = 0
944
-
945
946
return batch_percents
946
947
947
948
def passes_activity_frequency (
948
- self , activity : ConditionActivity , buckets : dict [datetime , int ]
949
+ self , activity : ConditionActivity , buckets : dict [datetime , int | float ]
949
950
) -> bool :
950
951
raise NotImplementedError
951
952
952
953
def get_form_instance (self ) -> EventFrequencyPercentForm :
953
954
return EventFrequencyPercentForm (self .data )
954
955
955
956
956
- def bucket_count (start : datetime , end : datetime , buckets : dict [datetime , int ]) -> int :
957
+ def bucket_count (
958
+ start : datetime , end : datetime , buckets : dict [datetime , int | float ]
959
+ ) -> int | float :
957
960
rounded_end = round_to_five_minute (end )
958
961
rounded_start = round_to_five_minute (start )
959
962
count = buckets .get (rounded_end , 0 ) - buckets .get (rounded_start , 0 )
960
963
return count
961
964
962
965
963
- def percent_increase (result : int , comparison_result : int ) -> int :
966
+ def percent_increase (result : int | float , comparison_result : int | float ) -> int :
964
967
return (
965
968
int (max (0 , ((result - comparison_result ) / comparison_result * 100 )))
966
969
if comparison_result > 0
0 commit comments