Browse Source

feat(severity): Set the high priority rule as the default for project creation (#61212)

Set the high priority rule as the default for project creation. This is
gated by a new feature flag here scoped to the organization.

https://github.com/getsentry/sentry/issues/59957
Snigdha Sharma 1 year ago
parent
commit
dcfe6974b5
3 changed files with 28 additions and 2 deletions
  1. 2 0
      src/sentry/conf/server.py
  2. 1 0
      src/sentry/features/__init__.py
  3. 25 2
      src/sentry/receivers/rules.py

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

@@ -1909,6 +1909,8 @@ SENTRY_FEATURES: dict[str, bool | None] = {
     "organizations:suspect-commits-all-frames": False,
     # Enables region provisioning for individual users
     "organizations:multi-region-selector": False,
+    # Enable the default alert at project creation to be the high priority alert
+    "organizations:default-high-priority-alerts": False,
     # Enable data forwarding functionality for projects.
     "projects:data-forwarding": True,
     # Enable functionality to discard groups.

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

@@ -277,6 +277,7 @@ default_manager.add("organizations:source-maps-debugger-blue-thunder-edition", O
 default_manager.add("organizations:suspect-commits-all-frames", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add("organizations:metrics-api-new-metrics-layer", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:metric-meta", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
+default_manager.add("organizations:default-high-priority-alerts", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 # NOTE: Don't add features down here! Add them to their specific group and sort
 #       them alphabetically! The order features are registered is not important.
 

+ 25 - 2
src/sentry/receivers/rules.py

@@ -1,3 +1,4 @@
+from sentry import features
 from sentry.models.rule import Rule
 from sentry.notifications.types import FallthroughChoiceType
 from sentry.signals import project_created
@@ -17,13 +18,35 @@ DEFAULT_RULE_DATA = {
     "actions": DEFAULT_RULE_ACTIONS,
 }
 
+DEFAULT_RULE_LABEL_NEW = "Send a notification for high priority issues"
+DEFAULT_RULE_ACTIONS_NEW = [
+    {
+        "id": "sentry.mail.actions.NotifyEmailAction",
+        "targetType": "IssueOwners",
+        "targetIdentifier": None,
+        "fallthroughType": FallthroughChoiceType.ACTIVE_MEMBERS.value,
+    }
+]
+DEFAULT_RULE_DATA_NEW = {
+    "match": "all",
+    "conditions": [
+        {"id": "sentry.rules.conditions.high_priority_issue.HighPriorityIssueCondition"}
+    ],
+    "actions": DEFAULT_RULE_ACTIONS_NEW,
+}
+
 
 def create_default_rules(project, default_rules=True, RuleModel=Rule, **kwargs):
     if not default_rules:
         return
 
-    rule_data = DEFAULT_RULE_DATA
-    RuleModel.objects.create(project=project, label=DEFAULT_RULE_LABEL, data=rule_data)
+    if features.has("organizations:default-high-priority-alerts", project.organization):
+        rule_data = DEFAULT_RULE_DATA_NEW
+        RuleModel.objects.create(project=project, label=DEFAULT_RULE_LABEL_NEW, data=rule_data)
+
+    else:
+        rule_data = DEFAULT_RULE_DATA
+        RuleModel.objects.create(project=project, label=DEFAULT_RULE_LABEL, data=rule_data)
 
 
 project_created.connect(create_default_rules, dispatch_uid="create_default_rules", weak=False)