-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ref(sentry apps): Improve Errors for Alert Rule Creation for Sentry Apps #82067
base: master
Are you sure you want to change the base?
Changes from all commits
aeb7176
3002ef5
afd18d8
67bc16f
2f0c14f
223ff0e
a0b764a
b8331a9
9e41d24
72a683c
2c946f4
b84d813
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 |
---|---|---|
|
@@ -33,8 +33,8 @@ | |
from sentry.integrations.slack.utils.rule_status import RedisRuleStatus | ||
from sentry.models.rule import NeglectedRule, RuleActivity, RuleActivityType | ||
from sentry.projects.project_rules.updater import ProjectRuleUpdater | ||
from sentry.rules.actions import trigger_sentry_app_action_creators_for_issues | ||
from sentry.rules.actions.utils import get_changed_data, get_updated_rule_data | ||
from sentry.sentry_apps.utils.alert_rule_action import create_sentry_app_alert_rule_issues_component | ||
from sentry.signals import alert_rule_edited | ||
from sentry.types.actor import Actor | ||
from sentry.utils import metrics | ||
|
@@ -285,7 +285,9 @@ def put(self, request: Request, project, rule) -> Response: | |
context = {"uuid": client.uuid} | ||
return Response(context, status=202) | ||
|
||
trigger_sentry_app_action_creators_for_issues(actions=kwargs["actions"]) | ||
result = create_sentry_app_alert_rule_issues_component(actions=kwargs["actions"]) | ||
if isinstance(result, Response): | ||
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. It's not good practice to have different typed returned from a method and then decide what to do with it based on type. I have a suggestion below on how to improve this. Please read the comments annotated with [n] in the order on n. |
||
return result | ||
|
||
updated_rule = ProjectRuleUpdater( | ||
rule=rule, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,15 @@ | |
get_slack_actions_with_async_lookups, | ||
) | ||
from sentry.incidents.serializers import AlertRuleSerializer as DrfAlertRuleSerializer | ||
from sentry.incidents.utils.sentry_apps import trigger_sentry_app_action_creators_for_incidents | ||
from sentry.integrations.slack.tasks.find_channel_id_for_alert_rule import ( | ||
find_channel_id_for_alert_rule, | ||
) | ||
from sentry.integrations.slack.utils.rule_status import RedisRuleStatus | ||
from sentry.models.rulesnooze import RuleSnooze | ||
from sentry.sentry_apps.services.app import app_service | ||
from sentry.sentry_apps.utils.alert_rule_action import ( | ||
create_sentry_app_alert_rule_component_for_incidents, | ||
) | ||
from sentry.users.services.user.service import user_service | ||
|
||
|
||
|
@@ -82,7 +84,12 @@ def update_alert_rule(request: Request, organization, alert_rule): | |
partial=True, | ||
) | ||
if serializer.is_valid(): | ||
trigger_sentry_app_action_creators_for_incidents(serializer.validated_data) | ||
raised_error = create_sentry_app_alert_rule_component_for_incidents( | ||
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. All comments applies to this method as well. |
||
serializer.validated_data | ||
) | ||
if raised_error: | ||
return raised_error | ||
|
||
if get_slack_actions_with_async_lookups(organization, request.user, data): | ||
# need to kick off an async job for Slack | ||
client = RedisRuleStatus() | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
from .base import SentryAppEventAction | ||
from .notify_event import NotifyEventSentryAppAction | ||
from .utils import trigger_sentry_app_action_creators_for_issues | ||
|
||
__all__ = ( | ||
"NotifyEventSentryAppAction", | ||
"SentryAppEventAction", | ||
"trigger_sentry_app_action_creators_for_issues", | ||
) |
This file was deleted.
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.
[2] Then wrap this in try catch and then in the catch, catch the exception and call a method like
return IntegrationResponse.from_exception()
where this method is a util that does all the work you're doing to turn exceptions into response.If from_exception() needs to know the caller for some reason to parse the errors better you can pass that as a param.