@@ -49,27 +49,36 @@ def _should_send_error_created_hooks(project):
49
49
from sentry import options
50
50
import random
51
51
52
+ use_sampling = options .get ('post-process.use-error-hook-sampling' )
53
+
54
+ # XXX(Meredith): Sampling is used to test the process_resource_change task.
55
+ # We have an option to explicity say we want to use sampling, and the other
56
+ # to determine what that rate should be.
57
+ # Going forward the sampling will be removed and the task will only be
58
+ # gated using the integrations-event-hooks (i.e. gated by plan)
59
+ #
60
+ # We also don't want to cache the result in case we need to manually lower the
61
+ # sample rate immediately, or turn it down completely.
62
+ if use_sampling :
63
+ if random .random () >= options .get ('post-process.error-hook-sample-rate' ):
64
+ return False
65
+
66
+ org = Organization .objects .get_from_cache (id = project .organization_id )
67
+ result = ServiceHook .objects .filter (
68
+ organization_id = org .id ,
69
+ ).extra (where = ["events @> '{error.created}'" ]).exists ()
70
+
71
+ return result
72
+
52
73
cache_key = u'servicehooks-error-created:1:{}' .format (project .id )
53
74
result = cache .get (cache_key )
54
75
55
76
if result is None :
56
77
57
- use_sampling = options .get ('post-process.use-error-hook-sampling' )
58
78
org = Organization .objects .get_from_cache (id = project .organization_id )
59
-
60
- # XXX(Meredith): Sampling is used to test the process_resource_change task.
61
- # We have an option to explicity say we want to use sampling, and the other
62
- # to determine what that rate should be.
63
- # Going forward the sampling will be removed and the task will only be
64
- # gated using the integrations-event-hooks (i.e. gated by plan)
65
- if use_sampling :
66
- if random .random () >= options .get ('post-process.error-hook-sample-rate' ):
67
- cache .set (cache_key , 0 , 60 )
68
- return False
69
- else :
70
- if not features .has ('organizations:integrations-event-hooks' , organization = org ):
71
- cache .set (cache_key , 0 , 60 )
72
- return False
79
+ if not features .has ('organizations:integrations-event-hooks' , organization = org ):
80
+ cache .set (cache_key , 0 , 60 )
81
+ return False
73
82
74
83
result = ServiceHook .objects .filter (
75
84
organization_id = org .id ,
0 commit comments