Skip to content

Commit 3ea8973

Browse files
getsentry-botroaga
andcommitted
Revert "chore(seer): Use seer quotas endpoints (#91937)"
This reverts commit e135c10. Co-authored-by: roaga <47861399+roaga@users.noreply.github.com>
1 parent 7f11b73 commit 3ea8973

File tree

11 files changed

+21
-102
lines changed

11 files changed

+21
-102
lines changed

src/sentry/api/endpoints/group_ai_summary.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from sentry.api.api_publish_status import ApiPublishStatus
1111
from sentry.api.base import region_silo_endpoint
1212
from sentry.api.bases.group import GroupAiEndpoint
13-
from sentry.autofix.utils import SeerAutomationSource
1413
from sentry.models.group import Group
1514
from sentry.seer.issue_summary import get_issue_summary
1615
from sentry.types.ratelimit import RateLimit, RateLimitCategory
@@ -38,10 +37,7 @@ def post(self, request: Request, group: Group) -> Response:
3837
force_event_id = data.get("event_id", None)
3938

4039
summary_data, status_code = get_issue_summary(
41-
group=group,
42-
user=request.user,
43-
force_event_id=force_event_id,
44-
source=SeerAutomationSource.ISSUE_DETAILS,
40+
group=group, user=request.user, force_event_id=force_event_id, source="issue_details"
4541
)
4642

4743
return Response(summary_data, status=status_code)

src/sentry/api/endpoints/group_autofix_setup_check.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
from django.conf import settings
88
from rest_framework.response import Response
99

10-
from sentry import quotas
1110
from sentry.api.api_owners import ApiOwner
1211
from sentry.api.api_publish_status import ApiPublishStatus
1312
from sentry.api.base import region_silo_endpoint
1413
from sentry.api.bases.group import GroupAiEndpoint
1514
from sentry.autofix.utils import get_autofix_repos_from_project_code_mappings
16-
from sentry.constants import DataCategory, ObjectStatus
15+
from sentry.constants import ObjectStatus
1716
from sentry.integrations.services.integration import integration_service
1817
from sentry.models.group import Group
1918
from sentry.models.organization import Organization
@@ -127,11 +126,6 @@ def get(self, request: Request, group: Group) -> Response:
127126
if not user_acknowledgement: # If the user has acknowledged, the org must have too.
128127
org_acknowledgement = get_seer_org_acknowledgement(org_id=org.id)
129128

130-
# TODO return BOTH trial status and autofix quota
131-
has_autofix_quota: bool = quotas.backend.has_available_reserved_budget(
132-
org_id=org.id, data_category=DataCategory.SEER_AUTOFIX
133-
)
134-
135129
return Response(
136130
{
137131
"integration": {
@@ -143,8 +137,5 @@ def get(self, request: Request, group: Group) -> Response:
143137
"orgHasAcknowledged": org_acknowledgement,
144138
"userHasAcknowledged": user_acknowledgement,
145139
},
146-
"billing": {
147-
"hasAutofixQuota": has_autofix_quota,
148-
},
149140
}
150141
)

src/sentry/autofix/utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,3 @@ def get_autofix_state_from_pr_id(provider: str, pr_id: int) -> AutofixState | No
146146
return None
147147

148148
return AutofixState.validate(result.get("state", None))
149-
150-
151-
class SeerAutomationSource(enum.Enum):
152-
ISSUE_DETAILS = "issue_details"
153-
ALERT = "alert"
154-
POST_PROCESS = "post_process"

src/sentry/integrations/utils/issue_summary_for_alerts.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sentry_sdk
66

77
from sentry import features, options
8-
from sentry.autofix.utils import SeerAutomationSource
98
from sentry.issues.grouptype import GroupCategory
109
from sentry.models.group import Group
1110
from sentry.seer.issue_summary import get_issue_summary
@@ -33,9 +32,7 @@ def fetch_issue_summary(group: Group) -> dict[str, Any] | None:
3332
try:
3433
with sentry_sdk.start_span(op="ai_summary.fetch_issue_summary_for_alert"):
3534
with concurrent.futures.ThreadPoolExecutor() as executor:
36-
future = executor.submit(
37-
get_issue_summary, group, source=SeerAutomationSource.ALERT
38-
)
35+
future = executor.submit(get_issue_summary, group, source="alert")
3936
summary_result, status_code = future.result(timeout=timeout)
4037

4138
if status_code == 200:

src/sentry/seer/autofix.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from django.utils import timezone
1212
from rest_framework.response import Response
1313

14-
from sentry import eventstore, features, quotas
14+
from sentry import eventstore, features
1515
from sentry.api.serializers import EventSerializer, serialize
1616
from sentry.autofix.utils import get_autofix_repos_from_project_code_mappings
17-
from sentry.constants import DataCategory, ObjectStatus
17+
from sentry.constants import ObjectStatus
1818
from sentry.eventstore.models import Event, GroupEvent
1919
from sentry.models.group import Group
2020
from sentry.models.project import Project
@@ -855,14 +855,6 @@ def trigger_autofix(
855855
403,
856856
)
857857

858-
# check billing quota for autofix
859-
has_budget: bool = quotas.backend.has_available_reserved_budget(
860-
org_id=group.organization.id,
861-
data_category=DataCategory.SEER_AUTOFIX,
862-
)
863-
if not has_budget:
864-
return _respond_with_error("No budget for Seer Autofix.", 402)
865-
866858
if event_id is None:
867859
event: Event | GroupEvent | None = group.get_recommended_event_for_environments()
868860
if not event:
@@ -932,11 +924,6 @@ def trigger_autofix(
932924

933925
group.update(seer_autofix_last_triggered=timezone.now())
934926

935-
# log billing event for seer autofix
936-
quotas.backend.record_seer_run(
937-
group.organization.id, group.project.id, DataCategory.SEER_AUTOFIX
938-
)
939-
940927
return Response(
941928
{
942929
"run_id": run_id,

src/sentry/seer/issue_summary.py

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
from django.conf import settings
1111
from django.contrib.auth.models import AnonymousUser
1212

13-
from sentry import eventstore, features, quotas
13+
from sentry import eventstore, features
1414
from sentry.api.serializers import EventSerializer, serialize
1515
from sentry.api.serializers.rest_framework.base import convert_dict_key_case, snake_to_camel_case
16-
from sentry.autofix.utils import SeerAutomationSource, get_autofix_state
17-
from sentry.constants import DataCategory, ObjectStatus
16+
from sentry.autofix.utils import get_autofix_state
17+
from sentry.constants import ObjectStatus
1818
from sentry.eventstore.models import Event, GroupEvent
1919
from sentry.locks import locks
2020
from sentry.models.group import Group
@@ -254,7 +254,7 @@ def _run_automation(
254254
group: Group,
255255
user: User | RpcUser | AnonymousUser,
256256
event: GroupEvent,
257-
source: SeerAutomationSource,
257+
source: str,
258258
):
259259
if features.has(
260260
"organizations:trigger-autofix-on-issue-summary", group.organization, actor=user
@@ -282,9 +282,8 @@ def _run_automation(
282282
not autofix_state
283283
): # Only trigger autofix if we don't have an autofix on this issue already.
284284
auto_run_source_map = {
285-
SeerAutomationSource.ISSUE_DETAILS: "issue_summary_fixability",
286-
SeerAutomationSource.ALERT: "issue_summary_on_alert_fixability",
287-
SeerAutomationSource.POST_PROCESS: "issue_summary_on_post_process_fixability",
285+
"issue_details": "issue_summary_fixability",
286+
"alert": "issue_summary_on_alert_fixability",
288287
}
289288
_trigger_autofix_task.delay(
290289
group_id=group.id,
@@ -298,7 +297,7 @@ def _generate_summary(
298297
group: Group,
299298
user: User | RpcUser | AnonymousUser,
300299
force_event_id: str | None,
301-
source: SeerAutomationSource,
300+
source: str,
302301
cache_key: str,
303302
) -> tuple[dict[str, Any], int]:
304303
"""Core logic to generate and cache the issue summary."""
@@ -336,29 +335,11 @@ def _generate_summary(
336335
return summary_dict, 200
337336

338337

339-
def _log_seer_scanner_billing_event(group: Group, source: SeerAutomationSource):
340-
if source == SeerAutomationSource.ISSUE_DETAILS:
341-
return
342-
343-
quotas.backend.record_seer_run(
344-
group.organization.id, group.project.id, DataCategory.SEER_SCANNER
345-
)
346-
347-
348-
def _has_seer_scanner_budget(group: Group, source: SeerAutomationSource) -> bool:
349-
if source == SeerAutomationSource.ISSUE_DETAILS:
350-
return True
351-
352-
return quotas.backend.has_available_reserved_budget(
353-
org_id=group.organization.id, data_category=DataCategory.SEER_SCANNER
354-
)
355-
356-
357338
def get_issue_summary(
358339
group: Group,
359340
user: User | RpcUser | AnonymousUser | None = None,
360341
force_event_id: str | None = None,
361-
source: SeerAutomationSource = SeerAutomationSource.ISSUE_DETAILS,
342+
source: str = "issue_details",
362343
) -> tuple[dict[str, Any], int]:
363344
"""
364345
Generate an AI summary for an issue.
@@ -380,9 +361,6 @@ def get_issue_summary(
380361
if not get_seer_org_acknowledgement(group.organization.id):
381362
return {"detail": "AI Autofix has not been acknowledged by the organization."}, 403
382363

383-
if not _has_seer_scanner_budget(group, source):
384-
return {"detail": "No budget for Seer Scanner."}, 402
385-
386364
cache_key = f"ai-group-summary-v2:{group.id}"
387365
lock_key = f"ai-group-summary-v2-lock:{group.id}"
388366
lock_duration = 10 # How long the lock is held if acquired (seconds)
@@ -393,7 +371,6 @@ def get_issue_summary(
393371
summary_dict, status_code = _generate_summary(
394372
group, user, force_event_id, source, cache_key
395373
)
396-
_log_seer_scanner_billing_event(group, source)
397374
return convert_dict_key_case(summary_dict, snake_to_camel_case), status_code
398375

399376
# 1. Check cache first
@@ -415,7 +392,6 @@ def get_issue_summary(
415392
summary_dict, status_code = _generate_summary(
416393
group, user, force_event_id, source, cache_key
417394
)
418-
_log_seer_scanner_billing_event(group, source)
419395
return convert_dict_key_case(summary_dict, snake_to_camel_case), status_code
420396

421397
except UnableToAcquireLock:

src/sentry/tasks/autofix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from datetime import datetime, timedelta
33

4-
from sentry.autofix.utils import AutofixStatus, SeerAutomationSource, get_autofix_state
4+
from sentry.autofix.utils import AutofixStatus, get_autofix_state
55
from sentry.models.group import Group
66
from sentry.tasks.base import instrumented_task
77
from sentry.taskworker.config import TaskworkerConfig
@@ -51,4 +51,4 @@ def start_seer_automation(group_id: int):
5151
from sentry.seer.issue_summary import get_issue_summary
5252

5353
group = Group.objects.get(id=group_id)
54-
get_issue_summary(group=group, source=SeerAutomationSource.POST_PROCESS)
54+
get_issue_summary(group=group, source="post_process")

tests/sentry/api/endpoints/test_group_ai_summary.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from unittest.mock import ANY, patch
22

3-
from sentry.autofix.utils import SeerAutomationSource
43
from sentry.testutils.cases import APITestCase, SnubaTestCase
54
from sentry.testutils.helpers.features import apply_feature_flag_on_cls
65
from sentry.testutils.skips import requires_snuba
@@ -29,10 +28,7 @@ def test_endpoint_calls_get_issue_summary(self, mock_get_issue_summary):
2928
assert response.status_code == 200
3029
assert response.data == mock_summary_data
3130
mock_get_issue_summary.assert_called_once_with(
32-
group=self.group,
33-
user=ANY,
34-
force_event_id="test_event_id",
35-
source=SeerAutomationSource.ISSUE_DETAILS,
31+
group=self.group, user=ANY, force_event_id="test_event_id", source="issue_details"
3632
)
3733

3834
@patch("sentry.api.endpoints.group_ai_summary.get_issue_summary")
@@ -45,10 +41,7 @@ def test_endpoint_without_event_id(self, mock_get_issue_summary):
4541
assert response.status_code == 200
4642
assert response.data == mock_summary_data
4743
mock_get_issue_summary.assert_called_once_with(
48-
group=self.group,
49-
user=ANY,
50-
force_event_id=None,
51-
source=SeerAutomationSource.ISSUE_DETAILS,
44+
group=self.group, user=ANY, force_event_id=None, source="issue_details"
5245
)
5346

5447
@patch("sentry.api.endpoints.group_ai_summary.get_issue_summary")
@@ -61,8 +54,5 @@ def test_endpoint_with_error_response(self, mock_get_issue_summary):
6154
assert response.status_code == 400
6255
assert response.data == error_data
6356
mock_get_issue_summary.assert_called_once_with(
64-
group=self.group,
65-
user=ANY,
66-
force_event_id=None,
67-
source=SeerAutomationSource.ISSUE_DETAILS,
57+
group=self.group, user=ANY, force_event_id=None, source="issue_details"
6858
)

tests/sentry/api/endpoints/test_group_autofix_setup_check.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ def test_successful_setup(self):
5555
"orgHasAcknowledged": False,
5656
"userHasAcknowledged": False,
5757
},
58-
"billing": {
59-
"hasAutofixQuota": True,
60-
},
6158
}
6259

6360
def test_current_user_acknowledged_setup(self):
@@ -157,9 +154,6 @@ def test_successful_with_write_access(self, mock_get_repos_and_access):
157154
"orgHasAcknowledged": False,
158155
"userHasAcknowledged": False,
159156
},
160-
"billing": {
161-
"hasAutofixQuota": True,
162-
},
163157
}
164158

165159

tests/sentry/integrations/slack/test_message_builder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from django.urls import reverse
99
from urllib3.response import HTTPResponse
1010

11-
from sentry.autofix.utils import SeerAutomationSource
1211
from sentry.eventstore.models import Event
1312
from sentry.grouping.grouptype import ErrorGroupType
1413
from sentry.incidents.logic import CRITICAL_TRIGGER_LABEL
@@ -996,7 +995,7 @@ def test_build_group_block_with_ai_summary_with_feature_flag(
996995

997996
blocks = SlackIssuesMessageBuilder(group).build()
998997

999-
mock_get_summary.assert_called_once_with(group, source=SeerAutomationSource.ALERT)
998+
mock_get_summary.assert_called_once_with(group, source="alert")
1000999

10011000
# Verify that the original title is \\ present
10021001
assert "IntegrationError" in blocks["blocks"][0]["text"]["text"]

tests/sentry/seer/test_issue_summary.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from unittest.mock import ANY, Mock, call, patch
55

66
from sentry.api.serializers.rest_framework.base import convert_dict_key_case, snake_to_camel_case
7-
from sentry.autofix.utils import SeerAutomationSource
87
from sentry.locks import locks
98
from sentry.seer.issue_summary import (
109
_get_event,
@@ -549,9 +548,7 @@ def test_run_automation_saves_fixability_score(
549548
self.group.refresh_from_db()
550549
assert self.group.seer_fixability_score is None
551550

552-
_run_automation(
553-
self.group, mock_user, mock_event, source=SeerAutomationSource.ISSUE_DETAILS
554-
)
551+
_run_automation(self.group, mock_user, mock_event, source="issue_details")
555552

556553
mock_generate_fixability_score.assert_called_once_with(self.group.id)
557554

@@ -616,9 +613,7 @@ def test_is_issue_fixable_triggers_autofix(
616613

617614
with self.subTest(option=option_value, score=score, should_trigger=should_trigger):
618615
self.group.project.update_option("sentry:autofix_automation_tuning", option_value)
619-
_run_automation(
620-
self.group, mock_user, mock_event, source=SeerAutomationSource.ISSUE_DETAILS
621-
)
616+
_run_automation(self.group, mock_user, mock_event, source="issue_details")
622617

623618
mock_generate_fixability_score.assert_called_once_with(self.group.id)
624619
self.group.refresh_from_db()

0 commit comments

Comments
 (0)