-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
fix(notification platform): Send issue owner team Slack notifications #29495
Conversation
tests/sentry/integrations/slack/notifications/test_issue_alert.py
Outdated
Show resolved
Hide resolved
return get_send_to( | ||
project=self.project, | ||
target_type=self.target_type, | ||
target_identifier=self.target_identifier, | ||
event=group.get_latest_event(), |
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.
I'm digging around in this area too, and I think you should actually have access to the event from inside the digest.
We fetch it out of the record here, when we have a single record and decide to not send as a digest:
sentry/src/sentry/notifications/utils/digest.py
Lines 38 to 53 in 31feae1
def send_as_alert_notification( | |
context: Mapping[str, Any], | |
target_type: ActionTargetType, | |
target_identifier: Optional[int] = None, | |
) -> None: | |
"""If there is more than one record for a group, just choose the most recent one.""" | |
from sentry.mail import mail_adapter | |
record = max( | |
itertools.chain.from_iterable( | |
groups.get(context["group"], []) for groups in context["digest"].values() | |
), | |
key=get_timestamp, | |
) | |
notification = Notification(record.value.event, rules=record.value.rules) | |
mail_adapter.notify(notification, target_type, target_identifier) |
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.
I guess one question here is whether we should be retrieving the affected participants from all groups in the digest, since there could be multiple owners involved?
Tbh I'm not sure how this worked before the most recent changes...
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.
If there are multiple groups in the digest then we drop the Slack notification altogether.
https://github.com/getsentry/sentry/blob/master/src/sentry/notifications/utils/digest.py#L23-L29
def should_send_as_alert_notification(context: Mapping[str, Any]) -> bool:
...
return len(context["counts"]) == 1
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.
At some point I'd like to build out a digest notification for Slack similar to the emails we send out, it just hasn't been prioritized 🤔
Can you also update this # Get every user ID for every provider as a set.
user_ids = {user.id for users in participants_by_provider.values() for user in users} to filter to only users? user_ids = {
participant.id
for participants in participants_by_provider.values()
for participant in participants
if instanceof(participant, User)
} Teams can't receive digests. |
201f00e
to
6a3e79d
Compare
Why can't a team receive digests? |
Actually wait yeah, shouldn't we send a Slack notification to the team's channel if there is one group so it passes |
|
@@ -40,10 +40,12 @@ def __init__( | |||
self.target_identifier = target_identifier | |||
|
|||
def get_participants(self) -> Mapping[ExternalProviders, Iterable[Union["Team", "User"]]]: | |||
event = [v for value in self.digest.values() for v in value.values()][0][0].value.event |
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.
I think it will help with debugging later if we pick better names here like:
event = [
records
for records_by_group in self.digest.values()
for records in records_by_group.values()
][0][0].value.event
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.
In fact this might be even clearer:
event = [
record
for records_by_group in self.digest.values()
for records in records_by_group.values()
for record in records
][0].value.event
|
||
if not mail_adapter.should_notify(target_type, group=group): |
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.
You should probably delete should_notify()
now to avoid confusion later.
|
I guess maybe I'm confused as to how a team would get here at all? If we have a digest, and we have a team, shouldn't the team be converted to members so that they can receive the digests instead? |
@wedamija When an alert rule is triggered where the action is "Send a Notification to Issue Owners", the recipients can be a set of users and teams. Before we can send any Alert Rule notifications we have to buffer them into digests (to prevent fire-hosing the user,) where the digest key is just a concatenation of @ceorourke We might want to only fetch participants after the |
I'm sort of wondering how worthwhile this PR is at this point given we now have a ticket to investigate sending Slack digests, which would be a much better solution to this problem. This PR only solves a tiny problem and my guess is a lot of this will be rewritten or moot once we build out Slack digests. @mgaeta what do you think? I just updated it based on the feedback in case we still want to merge - I suppose this at least unblocks Phillip's demos and we can still go ahead and redo stuff soon. |
24dc751
to
82d7903
Compare
If a team has Slack notifications enabled and an alert rule has a rule to notify issue owners and the owner resolves to said team AND the notification gets digested AND the team's users' issue alert notification settings were turned off, the alert wouldn't fire. This PR passes the event to
get_send_to
because without it, it'd never return the team as the recipient.See #28617 for initial implementation.