Browse Source

chore(issues): Add additional metrics for ownership matching (#79302)

Matt Duncan 4 months ago
parent
commit
283f68e977
1 changed files with 21 additions and 8 deletions
  1. 21 8
      src/sentry/models/projectownership.py

+ 21 - 8
src/sentry/models/projectownership.py

@@ -369,14 +369,27 @@ class ProjectOwnership(Model):
         ownership: ProjectOwnership | ProjectCodeOwners,
         data: Mapping[str, Any],
     ) -> list[Rule]:
-        rules = []
-        if ownership.schema is not None:
-            munged_data = Matcher.munge_if_needed(data)
-            for rule in load_schema(ownership.schema):
-                if rule.test(data, munged_data):
-                    rules.append(rule)
-
-        return rules
+        if ownership.schema is None:
+            return []
+
+        # "projectownership" or "projectcodeowners"
+        ownership_type = type(ownership).__name__.lower()
+
+        munged_data = Matcher.munge_if_needed(data)
+        metrics.distribution(
+            key="projectownership.matching_ownership_rules.frames",
+            value=len(munged_data[0]),
+            tags={"ownership_type": ownership_type},
+        )
+
+        rules = load_schema(ownership.schema)
+        metrics.distribution(
+            key="projectownership.matching_ownership_rules.rules",
+            value=len(rules),
+            tags={"ownership_type": ownership_type},
+        )
+
+        return [rule for rule in rules if rule.test(data, munged_data)]
 
 
 def process_resource_change(instance, change, **kwargs):