-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(workflows): Restrict APIs based on metrics alert features #112600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,43 @@ | ||
| from django.db.models import Model, Q, QuerySet | ||
| from django.db.models import BigIntegerField, Model, Q, QuerySet | ||
| from django.db.models.functions import Cast | ||
|
|
||
| from sentry.api.event_search import SearchFilter | ||
| from sentry.db.models.query import in_iexact | ||
| from sentry.incidents.grouptype import MetricIssue | ||
| from sentry.incidents.utils.subscription_limits import get_disallowed_metric_datasets | ||
| from sentry.incidents.utils.types import DATA_SOURCE_SNUBA_QUERY_SUBSCRIPTION | ||
| from sentry.models.organization import Organization | ||
| from sentry.snuba.models import QuerySubscription | ||
| from sentry.workflow_engine.models import Detector | ||
|
|
||
|
|
||
| def exclude_disallowed_metric_detectors( | ||
| queryset: QuerySet[Detector], organization: Organization | ||
| ) -> QuerySet[Detector]: | ||
| """ | ||
| Exclude metric detectors whose dataset subscription is not allowed | ||
| for the given organization (e.g. after a plan downgrade). | ||
| """ | ||
| disallowed_datasets = get_disallowed_metric_datasets(organization) | ||
| if not disallowed_datasets: | ||
| return queryset | ||
|
|
||
| # Cast DataSource.source_id (string) to int so the subquery can use | ||
| # the index on QuerySubscription.id. | ||
|
Comment on lines
+25
to
+26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this true? I think the subquery will use the index on
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not true. Fixed, but trying to rework this query to be more efficient. Updating coming soon(tm). |
||
| return ( | ||
| queryset.annotate( | ||
| _ds_source_int=Cast("data_sources__source_id", output_field=BigIntegerField()) | ||
| ) | ||
| .exclude( | ||
| type=MetricIssue.slug, | ||
| data_sources__type=DATA_SOURCE_SNUBA_QUERY_SUBSCRIPTION, | ||
| _ds_source_int__in=QuerySubscription.objects.filter( | ||
| snuba_query__dataset__in=disallowed_datasets, | ||
| project__organization=organization, | ||
| ).values_list("id", flat=True), | ||
| ) | ||
| .distinct() | ||
| ) | ||
|
kcons marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def apply_filter[T: Model]( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.