-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix(sentry apps): Self-heal/regenereate broken ServiceHooks #96712
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 2 commits
d0b195f
d1bbd6d
950e8f0
6469652
2dbbc0a
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 |
---|---|---|
|
@@ -751,18 +751,19 @@ def send_webhooks(installation: RpcSentryAppInstallation, event: str, **kwargs: | |
servicehook: ServiceHook | None = _load_service_hook( | ||
installation.organization_id, installation.id | ||
) | ||
lifecycle.add_extra("events", installation.sentry_app.events) | ||
lifecycle.add_extras( | ||
{ | ||
"installation_uuid": installation.uuid, | ||
"installation_id": installation.id, | ||
"organization": installation.organization_id, | ||
"sentry_app": installation.sentry_app.id, | ||
"events": installation.sentry_app.events, | ||
"webhook_url": installation.sentry_app.webhook_url or "", | ||
} | ||
) | ||
|
||
if not servicehook: | ||
lifecycle.add_extra("events", installation.sentry_app.events) | ||
lifecycle.add_extras( | ||
{ | ||
"installation_uuid": installation.uuid, | ||
"installation_id": installation.id, | ||
"organization": installation.organization_id, | ||
"sentry_app": installation.sentry_app.id, | ||
"events": installation.sentry_app.events, | ||
"webhook_url": installation.sentry_app.webhook_url or "", | ||
} | ||
) | ||
raise SentryAppSentryError(message=SentryAppWebhookFailureReason.MISSING_SERVICEHOOK) | ||
if event not in servicehook.events: | ||
raise SentryAppSentryError( | ||
|
@@ -799,6 +800,37 @@ def send_webhooks(installation: RpcSentryAppInstallation, event: str, **kwargs: | |
) | ||
|
||
|
||
@instrumented_task( | ||
"sentry.sentry_apps.tasks.sentry_apps.regenerate_service_hook_for_installation", | ||
taskworker_config=TaskworkerConfig( | ||
namespace=sentryapp_control_tasks, retry=Retry(times=3), processing_deadline_duration=60 | ||
), | ||
**TASK_OPTIONS, | ||
) | ||
Christinarlong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def regenerate_service_hook_for_installation( | ||
Christinarlong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
installation_id: int, servicehook_events: list[str] | None | ||
) -> 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. This function would be used whenever we encounter the In both cases we usually should have an installation with a working This logic was put into another task because I didn't want another logically separate operation to potentially pollute the results/info of another task. And similarly allows us to get better data on when this operation is ran. |
||
installation = app_service.installation_by_id(id=installation_id) | ||
app_events = installation.sentry_app.events | ||
|
||
if servicehook_events is None or set(servicehook_events) != set(app_events): | ||
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. thinking about this more idk if we should even have these checks, like I think we can assume the caller will have done the validation/check that the ServiceHook is in a bad state 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. i agree with your intuition: i think this task should only be called if this if statement is true. |
||
create_or_update_service_hooks_for_installation( | ||
installation=installation, | ||
events=app_events, | ||
webhook_url=installation.sentry_app.webhook_url, | ||
) | ||
|
||
logger.info( | ||
"regenerate_service_hook_for_installation", | ||
extra={ | ||
"installation_id": installation_id, | ||
"servicehook_events": servicehook_events, | ||
"app_events": app_events, | ||
"sentry_app": installation.sentry_app.id, | ||
}, | ||
) | ||
|
||
|
||
@instrumented_task( | ||
"sentry.sentry_apps.tasks.sentry_apps.create_or_update_service_hooks_for_sentry_app", | ||
taskworker_config=TaskworkerConfig( | ||
|
Uh oh!
There was an error while loading. Please reload this page.