Browse Source

feat(alerts): add spike protection notification setting (#40610)

Cathy Teng 2 years ago
parent
commit
9a5f09bb90

+ 2 - 0
src/sentry/models/notificationsetting.py

@@ -81,6 +81,8 @@ class NotificationSetting(Model):
             (NotificationSettingTypes.QUOTA_TRANSACTIONS, "quotaTransactions"),
             (NotificationSettingTypes.QUOTA_ATTACHMENTS, "quotaAttacments"),
             (NotificationSettingTypes.QUOTA_WARNINGS, "quotaWarnings"),
+            (NotificationSettingTypes.QUOTA_SPEND_ALLOCATIONS, "quotaSpendAllocations"),
+            (NotificationSettingTypes.SPIKE_PROTECTION, "spikeProtection"),
         ),
         null=False,
     )

+ 2 - 0
src/sentry/notifications/defaults.py

@@ -20,6 +20,7 @@ NOTIFICATION_SETTINGS_ALL_SOMETIMES = {
     NotificationSettingTypes.QUOTA_ATTACHMENTS: NotificationSettingOptionValues.ALWAYS,
     NotificationSettingTypes.QUOTA_WARNINGS: NotificationSettingOptionValues.ALWAYS,
     NotificationSettingTypes.QUOTA_SPEND_ALLOCATIONS: NotificationSettingOptionValues.ALWAYS,
+    NotificationSettingTypes.SPIKE_PROTECTION: NotificationSettingOptionValues.ALWAYS,
 }
 
 
@@ -35,6 +36,7 @@ NOTIFICATION_SETTINGS_DEFAULT_OFF = {
     NotificationSettingTypes.QUOTA_ATTACHMENTS: NotificationSettingOptionValues.NEVER,
     NotificationSettingTypes.QUOTA_WARNINGS: NotificationSettingOptionValues.NEVER,
     NotificationSettingTypes.QUOTA_SPEND_ALLOCATIONS: NotificationSettingOptionValues.NEVER,
+    NotificationSettingTypes.SPIKE_PROTECTION: NotificationSettingOptionValues.NEVER,
 }
 
 

+ 2 - 1
src/sentry/notifications/helpers.py

@@ -262,11 +262,12 @@ def get_scope_type(type: NotificationSettingTypes) -> NotificationScopeType:
         NotificationSettingTypes.WORKFLOW,
         NotificationSettingTypes.ISSUE_ALERTS,
         NotificationSettingTypes.ACTIVE_RELEASE,
+        NotificationSettingTypes.SPIKE_PROTECTION,
     ]:
         return NotificationScopeType.PROJECT
 
     raise Exception(
-        f"type {type}, must be alerts, deploy, workflow, approval, quota, quotaErrors, quotaTransactions, quotaAttachments, quotaWarnings, quotaSpendAllocations"
+        f"type {type}, must be alerts, deploy, workflow, approval, quota, quotaErrors, quotaTransactions, quotaAttachments, quotaWarnings, quotaSpendAllocations, spikeProtection"
     )
 
 

+ 9 - 0
src/sentry/notifications/types.py

@@ -62,6 +62,9 @@ class NotificationSettingTypes(Enum):
     # Sub category of quotas for spend allocation notifications
     QUOTA_SPEND_ALLOCATIONS = 55
 
+    # Notifications about spikes
+    SPIKE_PROTECTION = 60
+
 
 NOTIFICATION_SETTING_TYPES = {
     NotificationSettingTypes.DEFAULT: "default",
@@ -76,6 +79,7 @@ NOTIFICATION_SETTING_TYPES = {
     NotificationSettingTypes.QUOTA_ATTACHMENTS: "quotaAttachments",
     NotificationSettingTypes.QUOTA_WARNINGS: "quotaWarnings",
     NotificationSettingTypes.QUOTA_SPEND_ALLOCATIONS: "quotaSpendAllocations",
+    NotificationSettingTypes.SPIKE_PROTECTION: "spikeProtection",
 }
 
 
@@ -147,6 +151,7 @@ class UserOptionsSettingsKey(Enum):
     ACTIVE_RELEASE = "activeReleaseNotifications"
     APPROVAL = "approvalNotifications"
     QUOTA = "quotaNotifications"
+    SPIKE_PROTECTION = "spikeProtectionNotifications"
 
 
 VALID_VALUES_FOR_KEY = {
@@ -196,6 +201,10 @@ VALID_VALUES_FOR_KEY = {
         NotificationSettingOptionValues.ALWAYS,
         NotificationSettingOptionValues.NEVER,
     },
+    NotificationSettingTypes.SPIKE_PROTECTION: {
+        NotificationSettingOptionValues.ALWAYS,
+        NotificationSettingOptionValues.NEVER,
+    },
 }