Skip to content

feat(rules): Send a notification on create and edit #66285

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

Merged
merged 12 commits into from
Mar 7, 2024

Conversation

ceorourke
Copy link
Member

@ceorourke ceorourke commented Mar 5, 2024

Send a Slack notification when a rule with a Slack action is created or edited that confirms the rule was created or edited. In the future we'll add this for MSTeams and Discord.

I'm keeping the notification simple for now, but in the future we also may expand what's shown (e.g. adding the alert rule details to show the filters, conditions, and actions).

Screenshot 2024-03-06 at 12 00 31 PM

Closes #66237

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 5, 2024
Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 92.59259% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 84.30%. Comparing base (69b3e84) to head (24d0a1b).
Report is 34 commits behind head on master.

❗ Current head 24d0a1b differs from pull request most recent head 76e7f5b. Consider uploading reports for the commit 76e7f5b to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #66285   +/-   ##
=======================================
  Coverage   84.30%   84.30%           
=======================================
  Files        5311     5312    +1     
  Lines      237258   237329   +71     
  Branches    41035    41041    +6     
=======================================
+ Hits       200014   200083   +69     
- Misses      37025    37027    +2     
  Partials      219      219           
Files Coverage Δ
src/sentry/api/endpoints/project_rule_details.py 91.24% <100.00%> (+0.12%) ⬆️
src/sentry/api/endpoints/project_rules.py 95.92% <100.00%> (+0.15%) ⬆️
src/sentry/conf/server.py 90.15% <ø> (ø)
src/sentry/features/__init__.py 100.00% <100.00%> (ø)
...ck/message_builder/notifications/rule_save_edit.py 100.00% <100.00%> (ø)
src/sentry/rules/processor.py 92.98% <100.00%> (+1.50%) ⬆️
.../sentry/integrations/slack/actions/notification.py 86.95% <93.33%> (+1.24%) ⬆️
src/sentry/rules/actions/base.py 80.00% <64.28%> (-20.00%) ⬇️

... and 6 files with indirect coverage changes

Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach looks good to me 👍

else:
rule_text = f"{rule_url} in the *{project}* project was updated."

# TODO add short summary of the trigger & filter conditions
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a "maybe" TODO, discussing in Slack whether we want to add stuff to it or keep it simple. Simple is fine for this PR.

if not isinstance(action_inst, EventAction):
self.logger.warning("Unregistered action %r", action["id"])
continue
action_inst = instantiate_action(rule, action)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I just moved into a shared function so I can use it with my new logic.

@ceorourke ceorourke changed the title feat(rules): Send a notification on save and edit feat(rules): Send a notification on create and edit Mar 6, 2024
@ceorourke ceorourke marked this pull request as ready for review March 6, 2024 20:02
@ceorourke ceorourke requested review from a team as code owners March 6, 2024 20:02
@ceorourke ceorourke requested a review from a team as a code owner March 7, 2024 00:14
Copy link
Contributor

@nhsiehgit nhsiehgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think mostly looks good?
some non-blocking nits

rule: Rule,
new: bool,
) -> None:
super().__init__()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any other kwargs to pass through to super init?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like it

from sentry.rules.base import CallbackFuture, EventState, RuleBase

logger = logging.getLogger("sentry.rules")


def instantiate_action(rule: Rule, action):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we decide we watned this here in the base.py file? Or create a separate helpers/utils file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we were only discussing moving it around because of circular imports and ended up not needing to address that.

from sentry.rules.base import CallbackFuture, EventState, RuleBase

logger = logging.getLogger("sentry.rules")


def instantiate_action(rule: Rule, action):
from sentry.rules import rules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving to separate helper file should avoid circular imports right?

@ceorourke ceorourke merged commit 81530c4 into master Mar 7, 2024
@ceorourke ceorourke deleted the ceorourke/rule-save-edit-notification branch March 7, 2024 19:28
ceorourke added a commit that referenced this pull request Mar 14, 2024
Follow up to #66285 to add
details about what changed happened when a rule was edited to the
notification.

<img width="748" alt="Screenshot 2024-03-12 at 4 40 24 PM"
src="https://github.com/getsentry/sentry/assets/29959063/e0d7c5ca-35e5-4a66-bc67-e53c8d27dcce">


Note that I've made a couple follow up tickets to address poor rendering
of issue type enums and frequency:
getsentry/team-core-product-foundations#158
and
getsentry/team-core-product-foundations#157

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
JonasBa pushed a commit that referenced this pull request Mar 17, 2024
Follow up to #66285 to add
details about what changed happened when a rule was edited to the
notification.

<img width="748" alt="Screenshot 2024-03-12 at 4 40 24 PM"
src="https://github.com/getsentry/sentry/assets/29959063/e0d7c5ca-35e5-4a66-bc67-e53c8d27dcce">


Note that I've made a couple follow up tickets to address poor rendering
of issue type enums and frequency:
getsentry/team-core-product-foundations#158
and
getsentry/team-core-product-foundations#157

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Copy link

sentry-io bot commented Mar 18, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ RpcRemoteException: app.find_alertable_services: Invalid service request sentry.tasks.post_process.post_process_group View Issue

Did you find this useful? React with a 👍 or 👎

@github-actions github-actions bot locked and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post a "new alert rule created for this channel" notification to a new channel
3 participants