-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(app-platform): Add error.created hook event #13462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
67f97e9
523b570
0d75537
9f3dbc9
927938c
490a47a
8d43188
ec40de9
45dcf3b
63f397b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,52 @@ def _get_service_hooks(project_id): | |
return result | ||
|
||
|
||
def _should_send_error_created_hooks(project): | ||
from sentry.models import ServiceHook, Organization | ||
from sentry import options | ||
import random | ||
|
||
use_sampling = options.get('post-process.use-error-hook-sampling') | ||
|
||
# XXX(Meredith): Sampling is used to test the process_resource_change task. | ||
# We have an option to explicity say we want to use sampling, and the other | ||
# to determine what that rate should be. | ||
# Going forward the sampling will be removed and the task will only be | ||
# gated using the integrations-event-hooks (i.e. gated by plan) | ||
# | ||
# We also don't want to cache the result in case we need to manually lower the | ||
# sample rate immediately, or turn it down completely. | ||
if use_sampling: | ||
if random.random() >= options.get('post-process.error-hook-sample-rate'): | ||
return False | ||
|
||
org = Organization.objects.get_from_cache(id=project.organization_id) | ||
result = ServiceHook.objects.filter( | ||
organization_id=org.id, | ||
).extra(where=["events @> '{error.created}'"]).exists() | ||
|
||
return result | ||
|
||
cache_key = u'servicehooks-error-created:1:{}'.format(project.id) | ||
result = cache.get(cache_key) | ||
|
||
if result is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you plan to use the sampling rate to keep the load under control (and possibly constant), then you may want to apply the sampling rate on the cached value, instead of filling the cache with a sampled value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, this is for us to manually test the load and slowing increase the %, so yeah makes sense to not cache this value |
||
|
||
org = Organization.objects.get_from_cache(id=project.organization_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are using sampling you are not using this. You may avoid fetching the organization in that case. Unless you also want to check the feature when the sampling is on, then the check is missing below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
will move that into the else
I don't think we would need both |
||
if not features.has('organizations:integrations-event-hooks', organization=org): | ||
cache.set(cache_key, 0, 60) | ||
return False | ||
|
||
result = ServiceHook.objects.filter( | ||
organization_id=org.id, | ||
).extra(where=["events @> '{error.created}'"]).exists() | ||
|
||
cache_value = 1 if result else 0 | ||
cache.set(cache_key, cache_value, 60) | ||
|
||
return result | ||
|
||
|
||
def _capture_stats(event, is_new): | ||
# TODO(dcramer): limit platforms to... something? | ||
group = event.group | ||
|
@@ -161,6 +207,14 @@ def post_process_group(event, is_new, is_regression, is_sample, is_new_group_env | |
event=event, | ||
) | ||
|
||
if event.get_event_type() == 'error' and _should_send_error_created_hooks(event.project): | ||
process_resource_change_bound.delay( | ||
action='created', | ||
sender='Error', | ||
instance_id=event.event_id, | ||
project_id=event.project_id, | ||
group_id=event.group_id, | ||
) | ||
if is_new: | ||
process_resource_change_bound.delay( | ||
action='created', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JTCunning / @tkaemming couldn't think of better names so open to others if this could be improved upon