Skip to content

Commit

Permalink
Activated alert rule apis feature flag (#66361)
Browse files Browse the repository at this point in the history
Includes feature flag and monitor type validator in the alert rule api
serializer

Serializer converts int value into enum
  • Loading branch information
nhsiehgit authored and aliu39 committed Mar 6, 2024
1 parent f8649f6 commit 442f7e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,8 @@ def custom_parameter_sort(parameter: dict) -> tuple[str, int]:
"auth:enterprise-superuser-read-write": False,
# Enables user registration.
"auth:register": True,
# Enables activated alert rules
"organizations:activated-alert-rules": False,
# Enable advanced search features, like negation and wildcard matching.
"organizations:advanced-search": True,
# Enables alert creation on indexed events in UI (use for PoC/testing only)
Expand Down
1 change: 1 addition & 0 deletions src/sentry/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
default_manager.add("relocation:enabled", SystemFeature, FeatureHandlerStrategy.INTERNAL)

# Organization scoped features that are in development or in customer trials.
default_manager.add("organizations:activated-alert-rules", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
default_manager.add("organizations:alert-allow-indexed", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
default_manager.add("organizations:alert-crash-free-metrics", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
default_manager.add("organizations:alert-filters", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
Expand Down
17 changes: 16 additions & 1 deletion src/sentry/incidents/serializers/alert_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
translate_aggregate_field,
update_alert_rule,
)
from sentry.incidents.models import AlertRule, AlertRuleThresholdType, AlertRuleTrigger
from sentry.incidents.models import (
AlertRule,
AlertRuleMonitorType,
AlertRuleThresholdType,
AlertRuleTrigger,
)
from sentry.snuba.dataset import Dataset
from sentry.snuba.entity_subscription import (
ENTITY_TIME_COLUMNS,
Expand Down Expand Up @@ -196,6 +201,16 @@ def validate_threshold_type(self, threshold_type):
% [item.value for item in AlertRuleThresholdType]
)

def validate_monitor_type(self, monitor_type):
if monitor_type > 0 and not features.has(
"organizations:activated-alert-rules",
self.context["organization"],
actor=self.context.get("user", None),
):
raise serializers.ValidationError("Invalid monitor type")

return AlertRuleMonitorType(monitor_type)

def validate(self, data):
"""
Performs validation on an alert rule's data.
Expand Down

0 comments on commit 442f7e4

Please sign in to comment.