Skip to content

Commit 45dcf3b

Browse files
committed
dont cache value when using sampling
1 parent ec40de9 commit 45dcf3b

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/sentry/tasks/post_process.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,36 @@ def _should_send_error_created_hooks(project):
4949
from sentry import options
5050
import random
5151

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+
5273
cache_key = u'servicehooks-error-created:1:{}'.format(project.id)
5374
result = cache.get(cache_key)
5475

5576
if result is None:
5677

57-
use_sampling = options.get('post-process.use-error-hook-sampling')
5878
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
7382

7483
result = ServiceHook.objects.filter(
7584
organization_id=org.id,

0 commit comments

Comments
 (0)