-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
chore(seer): Use seer quotas endpoints #91937
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
Changes from 2 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 |
---|---|---|
|
@@ -7,12 +7,13 @@ | |
from django.conf import settings | ||
from rest_framework.response import Response | ||
|
||
from sentry import quotas | ||
from sentry.api.api_owners import ApiOwner | ||
from sentry.api.api_publish_status import ApiPublishStatus | ||
from sentry.api.base import region_silo_endpoint | ||
from sentry.api.bases.group import GroupAiEndpoint | ||
from sentry.autofix.utils import get_autofix_repos_from_project_code_mappings | ||
from sentry.constants import ObjectStatus | ||
from sentry.constants import DataCategory, ObjectStatus | ||
from sentry.integrations.services.integration import integration_service | ||
from sentry.models.group import Group | ||
from sentry.models.organization import Organization | ||
|
@@ -123,6 +124,11 @@ def get(self, request: Request, group: Group) -> Response: | |
if not user_acknowledgement: # If the user has acknowledged, the org must have too. | ||
org_acknowledgement = get_seer_org_acknowledgement(org_id=org.id) | ||
|
||
# TODO return BOTH trial status and autofix quota | ||
has_autofix_quota: bool = quotas.backend.has_available_reserved_budget( | ||
org_id=org.id, data_category=DataCategory.SEER_AUTOFIX | ||
) | ||
|
||
return Response( | ||
{ | ||
"integration": { | ||
|
@@ -134,5 +140,8 @@ def get(self, request: Request, group: Group) -> Response: | |
"orgHasAcknowledged": org_acknowledgement, | ||
"userHasAcknowledged": user_acknowledgement, | ||
}, | ||
"billing": { | ||
"hasAutofixQuota": has_autofix_quota, | ||
}, | ||
} | ||
) | ||
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. The plan is to return billing and trial information in the setup check so we can display different things on the UI |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,10 @@ | |
from django.utils import timezone | ||
from rest_framework.response import Response | ||
|
||
from sentry import eventstore, features | ||
from sentry import eventstore, features, quotas | ||
from sentry.api.serializers import EventSerializer, serialize | ||
from sentry.autofix.utils import get_autofix_repos_from_project_code_mappings | ||
from sentry.constants import ObjectStatus | ||
from sentry.constants import DataCategory, ObjectStatus | ||
from sentry.eventstore.models import Event, GroupEvent | ||
from sentry.models.group import Group | ||
from sentry.models.project import Project | ||
|
@@ -747,6 +747,14 @@ def trigger_autofix( | |
403, | ||
) | ||
|
||
# check billing quota for autofix | ||
has_budget: bool = quotas.backend.has_available_reserved_budget( | ||
org_id=group.organization.id, | ||
data_category=DataCategory.SEER_AUTOFIX, | ||
) | ||
if not has_budget: | ||
return _respond_with_error("No budget for Seer Autofix.", 402) | ||
|
||
if event_id is None: | ||
event: Event | GroupEvent | None = group.get_recommended_event_for_environments() | ||
if not event: | ||
|
@@ -808,6 +816,11 @@ def trigger_autofix( | |
|
||
group.update(seer_autofix_last_triggered=timezone.now()) | ||
|
||
# log billing event for seer autofix | ||
quotas.backend.record_seer_run( | ||
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. So, if we set it up like this does it mean that we count a seer run for each time you press start on autofix, including:
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. Yep that's the intention |
||
group.organization.id, group.project.id, DataCategory.SEER_AUTOFIX | ||
) | ||
|
||
return Response( | ||
{ | ||
"run_id": run_id, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switching to an enum for cleanliness