Browse Source

feat(spans): Spans abuse quota (#77615)

Send project abuse quota for spans to Relay, if defined.
Joris Bayer 5 months ago
parent
commit
c2d10cbbcf
3 changed files with 21 additions and 0 deletions
  1. 6 0
      src/sentry/options/defaults.py
  2. 6 0
      src/sentry/quotas/base.py
  3. 9 0
      tests/sentry/quotas/test_redis.py

+ 6 - 0
src/sentry/options/defaults.py

@@ -1213,6 +1213,12 @@ register(
     default=0,
     flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
 )
+register(
+    "project-abuse-quota.span-limit",
+    type=Int,
+    default=0,
+    flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
+)
 
 
 register(

+ 6 - 0
src/sentry/quotas/base.py

@@ -461,6 +461,12 @@ class Quota(Service):
                 categories=[DataCategory.SESSION],
                 scope=QuotaScope.PROJECT,
             ),
+            AbuseQuota(
+                id="paspi",
+                option="project-abuse-quota.span-limit",
+                categories=[DataCategory.SPAN_INDEXED],
+                scope=QuotaScope.PROJECT,
+            ),
         ]
 
         abuse_quotas.extend(build_metric_abuse_quotas())

+ 9 - 0
tests/sentry/quotas/test_redis.py

@@ -119,6 +119,7 @@ class RedisQuotaTest(TestCase):
         self.organization.update_option("project-abuse-quota.session-limit", 602)
         self.organization.update_option("organization-abuse-quota.metric-bucket-limit", 603)
         self.organization.update_option("organization-abuse-quota.custom-metric-bucket-limit", 604)
+        self.organization.update_option("project-abuse-quota.span-limit", 605)
 
         metric_abuse_limit_by_id = dict()
         for i, mabq in enumerate(build_metric_abuse_quotas()):
@@ -152,6 +153,14 @@ class RedisQuotaTest(TestCase):
         assert quotas[3].window == 10
         assert quotas[3].reason_code == "project_abuse_limit"
 
+        assert quotas[4].id == "paspi"
+        assert quotas[4].scope == QuotaScope.PROJECT
+        assert quotas[4].scope_id is None
+        assert quotas[4].categories == {DataCategory.SPAN_INDEXED}
+        assert quotas[4].limit == 6050
+        assert quotas[4].window == 10
+        assert quotas[4].reason_code == "project_abuse_limit"
+
         expected_quotas: dict[tuple[QuotaScope, UseCaseID | None], str] = dict()
         for scope, prefix in [
             (QuotaScope.PROJECT, "p"),