Skip to content

Commit 3de5fa7

Browse files
authored
fix(seer): Fixability make_signed_seer_api_request + conn pool (#94236)
1 parent 68c83a2 commit 3de5fa7

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/sentry/seer/issue_summary.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
from datetime import timedelta
5+
from functools import lru_cache
56
from typing import Any
67

78
import orjson
@@ -23,11 +24,12 @@
2324
from sentry.locks import locks
2425
from sentry.models.group import Group
2526
from sentry.models.project import Project
27+
from sentry.net.http import connection_from_url
2628
from sentry.seer.autofix import trigger_autofix
2729
from sentry.seer.models import SummarizeIssueResponse
2830
from sentry.seer.seer_setup import get_seer_org_acknowledgement
2931
from sentry.seer.seer_utils import AutofixAutomationTuningSettings, FixabilityScoreThresholds
30-
from sentry.seer.signed_seer_api import sign_with_seer_secret
32+
from sentry.seer.signed_seer_api import make_signed_seer_api_request, sign_with_seer_secret
3133
from sentry.tasks.base import instrumented_task
3234
from sentry.taskworker.config import TaskworkerConfig
3335
from sentry.taskworker.namespaces import seer_tasks
@@ -173,6 +175,33 @@ def _call_seer(
173175
return SummarizeIssueResponse.validate(response.json())
174176

175177

178+
@lru_cache(maxsize=1)
179+
def create_fixability_connection_pool():
180+
return connection_from_url(
181+
settings.SEER_SEVERITY_URL,
182+
timeout=settings.SEER_FIXABILITY_TIMEOUT,
183+
)
184+
185+
186+
def _generate_fixability_score_via_conn_pool(group: Group):
187+
payload = {
188+
"group_id": group.id,
189+
"organization_slug": group.organization.slug,
190+
"organization_id": group.organization.id,
191+
"project_id": group.project.id,
192+
}
193+
response = make_signed_seer_api_request(
194+
create_fixability_connection_pool(),
195+
"/v1/automation/summarize/fixability",
196+
body=orjson.dumps(payload, option=orjson.OPT_NON_STR_KEYS),
197+
timeout=settings.SEER_FIXABILITY_TIMEOUT,
198+
)
199+
if response.status >= 400:
200+
raise Exception(f"Seer API error: {response.status}")
201+
response_data = orjson.loads(response.data)
202+
return SummarizeIssueResponse.validate(response_data)
203+
204+
176205
def _generate_fixability_score(group: Group):
177206
path = "/v1/automation/summarize/fixability"
178207
body = orjson.dumps(
@@ -295,7 +324,10 @@ def _run_automation(
295324
)
296325

297326
with sentry_sdk.start_span(op="ai_summary.generate_fixability_score"):
298-
issue_summary = _generate_fixability_score(group)
327+
if group.organization.id == 1: # TODO(kddubey): rm temp guard
328+
issue_summary = _generate_fixability_score_via_conn_pool(group)
329+
else:
330+
issue_summary = _generate_fixability_score(group)
299331

300332
if not issue_summary.scores:
301333
raise ValueError("Issue summary scores is None or empty.")

src/sentry/seer/signed_seer_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def make_signed_seer_api_request(
2020
connection_pool: HTTPConnectionPool,
2121
path: str,
2222
body: bytes,
23-
timeout: int | None = None,
23+
timeout: int | float | None = None,
2424
retries: int | None = None,
2525
metric_tags: dict[str, Any] | None = None,
2626
) -> BaseHTTPResponse:

0 commit comments

Comments
 (0)