Skip to content

Commit 8738f0d

Browse files
vgrozdanicc298lee
authored andcommitted
chore(metrics): clean up of the custom alert filtering (#77229)
Clean up of custom filtering logic needed for span based attribute metrics. Now it is no longer needed, since this logic isn't used anywhere Signed-off-by: Vjeran Grozdanic <[email protected]>
1 parent ee914d9 commit 8738f0d

File tree

2 files changed

+1
-44
lines changed

2 files changed

+1
-44
lines changed

src/sentry/incidents/models/alert_rule.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from django.conf import settings
1111
from django.core.cache import cache
1212
from django.db import models
13-
from django.db.models import Q, QuerySet
13+
from django.db.models import QuerySet
1414
from django.db.models.signals import post_delete, post_save
1515
from django.utils import timezone
1616
from django.utils.translation import gettext_lazy
@@ -224,20 +224,6 @@ def conditionally_subscribe_project_to_alert_rules(
224224
)
225225
return []
226226

227-
def get_for_metrics(
228-
self, organization: Organization, metric_mris: list[str]
229-
) -> BaseQuerySet[AlertRule]:
230-
"""
231-
Fetches AlertRules associated with the metric MRIs
232-
"""
233-
234-
alert_query = Q()
235-
for metric_mri in metric_mris:
236-
alert_query |= Q(snuba_query__aggregate__contains=metric_mri)
237-
238-
queryset = self.filter(organization=organization).filter(alert_query)
239-
return queryset
240-
241227

242228
@region_silo_model
243229
class AlertRuleExcludedProjects(Model):

tests/sentry/incidents/models/test_alert_rule.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -212,35 +212,6 @@ def test_conditionally_subscribing_project_initializes_activation(self):
212212
assert current_activation.query_subscription == sub
213213
assert current_activation.is_complete() is False
214214

215-
def test_get_for_metrics(self):
216-
self.create_alert_rule(organization=self.organization, aggregate="count(c:foo/1)")
217-
self.create_alert_rule(organization=self.organization, aggregate="count(c:bar/2)")
218-
self.create_alert_rule(organization=self.organization, aggregate="count(c:baz/2)")
219-
new_org = self.create_organization()
220-
self.create_alert_rule(organization=new_org, aggregate="count(c:foo/1)")
221-
222-
assert (
223-
AlertRule.objects.get_for_metrics(self.organization, ["c:foo/1", "c:bar/2"]).count()
224-
== 2
225-
)
226-
assert set(
227-
AlertRule.objects.get_for_metrics(
228-
self.organization, ["c:foo/1", "c:bar/2"]
229-
).values_list("snuba_query__aggregate", flat=True)
230-
) == {"count(c:foo/1)", "count(c:bar/2)"}
231-
232-
# Test that it works with a new organization
233-
assert set(
234-
AlertRule.objects.get_for_metrics(new_org, ["c:foo/1", "c:bar/2"]).values_list(
235-
"snuba_query__aggregate", flat=True
236-
)
237-
) == {"count(c:foo/1)"}
238-
assert set(
239-
AlertRule.objects.get_for_metrics(new_org, ["c:foo/1", "c:bar/2"]).values_list(
240-
"organization_id", flat=True
241-
)
242-
) == {new_org.id}
243-
244215

245216
class AlertRuleFetchForOrganizationTest(TestCase):
246217
def test_empty(self):

0 commit comments

Comments
 (0)