Browse Source

ref(notifications): Only notify would-be assignee when alert is triggered (#29767)

Leander Rodrigues 3 years ago
parent
commit
eb700307dc

+ 2 - 0
src/sentry/conf/server.py

@@ -1048,6 +1048,8 @@ SENTRY_FEATURES = {
     "organizations:minute-resolution-sessions": True,
     # Automatically opt IN users to receiving Slack notifications.
     "organizations:notification-slack-automatic": False,
+    # Notify all project members when fallthrough is disabled, instead of just the auto-assignee
+    "organizations:notification-all-recipients": False,
     # Enable the new native stack trace design
     "organizations:native-stack-trace-v2": False,
     # Enable version 2 of reprocessing (completely distinct from v1)

+ 1 - 0
src/sentry/features/__init__.py

@@ -110,6 +110,7 @@ default_manager.add("organizations:metrics-extraction", OrganizationFeature, Tru
 default_manager.add("organizations:minute-resolution-sessions", OrganizationFeature)
 default_manager.add("organizations:mobile-screenshots", OrganizationFeature, True)
 default_manager.add("organizations:monitors", OrganizationFeature)
+default_manager.add("organizations:notification-all-recipients", OrganizationFeature, True)
 default_manager.add("organizations:notification-slack-automatic", OrganizationFeature, True)
 default_manager.add("organizations:native-stack-trace-v2", OrganizationFeature, True)
 default_manager.add("organizations:onboarding", OrganizationFeature)

+ 11 - 1
src/sentry/notifications/utils/participants.py

@@ -171,6 +171,16 @@ def get_owners(project: Project, event: Event | None = None) -> Iterable[Team |
         outcome = "match"
         recipients = ActorTuple.resolve_many(owners)
 
+    if len(recipients) > 1:
+        ownership = ProjectOwnership.get_ownership_cached(project.id)
+        # Used to suppress extra notifications to all project members, only notify the would-be auto-assignee
+        if (
+            ownership
+            and not ownership.fallthrough
+            and not features.has("organizations:notification-all-recipients", project.organization)
+        ):
+            return list(recipients)[-1:]
+
     metrics.incr(
         "features.owners.send_to",
         tags={"organization": project.organization_id, "outcome": outcome},
@@ -216,7 +226,7 @@ def determine_eligible_recipients(
     event: Event | None = None,
 ) -> Iterable[Team | User]:
     """
-    Either get the individual recipient from the target type/id or user the the
+    Either get the individual recipient from the target type/id or the
     owners as determined by rules for this project and event.
     """
     if not (project and project.teams.exists()):