Browse Source

feat(ownership): Add feature to allow some orgs to have a higher max project ownership limit (#31231)

We have this limit in place to protect our infrastructure against problems caused by a large number
of ownership rules.

In some cases, we might want to relax this for specific orgs. This adds in a feature flag to allow
for a higher limit.

Longer term we should figure out how to make processing large number of rules more efficient. We can
probably do prefix matching for a lot of these rules, so that we don't have to scan every rule in
the tree for every path in the stack trace.
Dan Fuller 3 years ago
parent
commit
a0718b1ca7

+ 13 - 3
src/sentry/api/endpoints/project_ownership.py

@@ -3,13 +3,15 @@ from rest_framework import serializers
 from rest_framework.request import Request
 from rest_framework.response import Response
 
+from sentry import features
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.serializers import serialize
 from sentry.models import ProjectOwnership
 from sentry.ownership.grammar import CODEOWNERS, create_schema_from_issue_owners
 from sentry.signals import ownership_rule_created
 
-MAX_RAW_LENGTH = 100000
+MAX_RAW_LENGTH = 100_000
+HIGHER_MAX_RAW_LENGTH = 200_000
 
 
 class ProjectOwnershipSerializer(serializers.Serializer):
@@ -29,6 +31,13 @@ class ProjectOwnershipSerializer(serializers.Serializer):
                     {"raw": "Codeowner type paths can only be added by importing CODEOWNER files"}
                 )
 
+    def get_max_length(self):
+        if features.has(
+            "organizations:higher-ownership-limit", self.context["ownership"].project.organization
+        ):
+            return HIGHER_MAX_RAW_LENGTH
+        return MAX_RAW_LENGTH
+
     def validate(self, attrs):
         if "raw" not in attrs:
             return attrs
@@ -37,9 +46,10 @@ class ProjectOwnershipSerializer(serializers.Serializer):
         # that are several megabytes large. To not break this functionality for existing customers
         # we temporarily allow rows that already exceed this limit to still be updated.
         existing_raw = self.context["ownership"].raw or ""
-        if len(attrs["raw"]) > MAX_RAW_LENGTH and len(existing_raw) <= MAX_RAW_LENGTH:
+        max_length = self.get_max_length()
+        if len(attrs["raw"]) > max_length and len(existing_raw) <= max_length:
             raise serializers.ValidationError(
-                {"raw": f"Raw needs to be <= {MAX_RAW_LENGTH} characters in length"}
+                {"raw": f"Raw needs to be <= {max_length} characters in length"}
             )
 
         schema = create_schema_from_issue_owners(attrs["raw"], self.context["ownership"].project_id)

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

@@ -932,6 +932,8 @@ SENTRY_FEATURES = {
     "organizations:discover-query": True,
     # Enable discover top events queries with other & higher options
     "organizations:discover-top-events": False,
+    # Allows an org to have a larger set of project ownership rules per project
+    "organizations:higher-ownership-limit": False,
     # Enable Performance view
     "organizations:performance-view": True,
     # Enable profiling

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

@@ -84,6 +84,7 @@ default_manager.add("organizations:global-views", OrganizationFeature)
 default_manager.add("organizations:grouping-stacktrace-ui", OrganizationFeature, True)
 default_manager.add("organizations:grouping-title-ui", OrganizationFeature, True)
 default_manager.add("organizations:grouping-tree-ui", OrganizationFeature, True)
+default_manager.add("organizations:higher-ownership-limit", OrganizationFeature)
 default_manager.add("organizations:idp-automatic-migration", OrganizationFeature, True)
 default_manager.add("organizations:images-loaded-v2", OrganizationFeature)
 default_manager.add("organizations:improved-search", OrganizationFeature, True)