|
2 | 2 |
|
3 | 3 | import logging
|
4 | 4 | from datetime import timedelta
|
| 5 | +from functools import lru_cache |
5 | 6 | from typing import Any
|
6 | 7 |
|
7 | 8 | import orjson
|
|
23 | 24 | from sentry.locks import locks
|
24 | 25 | from sentry.models.group import Group
|
25 | 26 | from sentry.models.project import Project
|
| 27 | +from sentry.net.http import connection_from_url |
26 | 28 | from sentry.seer.autofix import trigger_autofix
|
27 | 29 | from sentry.seer.models import SummarizeIssueResponse
|
28 | 30 | from sentry.seer.seer_setup import get_seer_org_acknowledgement
|
29 | 31 | 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 |
31 | 33 | from sentry.tasks.base import instrumented_task
|
32 | 34 | from sentry.taskworker.config import TaskworkerConfig
|
33 | 35 | from sentry.taskworker.namespaces import seer_tasks
|
@@ -173,6 +175,33 @@ def _call_seer(
|
173 | 175 | return SummarizeIssueResponse.validate(response.json())
|
174 | 176 |
|
175 | 177 |
|
| 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 | + |
176 | 205 | def _generate_fixability_score(group: Group):
|
177 | 206 | path = "/v1/automation/summarize/fixability"
|
178 | 207 | body = orjson.dumps(
|
@@ -295,7 +324,10 @@ def _run_automation(
|
295 | 324 | )
|
296 | 325 |
|
297 | 326 | 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) |
299 | 331 |
|
300 | 332 | if not issue_summary.scores:
|
301 | 333 | raise ValueError("Issue summary scores is None or empty.")
|
|
0 commit comments