feat(lps): 프록시 전송오류 IP회전 + 시작 프리플라이트 + DECODO/컴포넌트별 비용

프록시(DECODO) 포트/IP 사망(407/ERR_TUNNEL/ERR_HTTP_RESPONSE_CODE_FAILURE)이
봇차단과 구분 없이 예외로 튕겨 같은 죽은 포트로 재시도만 하다 DEAD 되던 문제를 고친다.

- browser_base: is_proxy_error(순수함수) + search 루프에서 프록시 전송오류 시 IP 회전 재시도
  (max_proxy_retries=2). 봇감지 회전과 통합. uses_proxy 프로퍼티.
- 쿠팡 어댑터를 BrowserSearchAdapter 로 통합 — 중복 machinery 제거, 회전 로직 한 곳에서 공유
  (detect_block 순수함수는 유지, 테스트 호환).
- proxy.healthcheck(): 시작 프리플라이트 — 살아있는 포트 선점 + egress IP 로그(빠른 실패·가시성).
  worker_main 기동 시 호출.
- 비용: DecodoConfig.cost_per_gb 추가. metrics 에 proxy_bytes(네이버 직접 제외) + 컴포넌트별
  cost{ai_usd, proxy_usd, total_usd}. FE 원가 타일에 AI/DECODO 분해·프록시 바이트.
- 테스트: is_proxy_error 8종 + 비용 분해 1종.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Fable 5 committed 2026-07-09 15:33:37 +09:00
1 parent 9c478e80fd
commit c955a8f367
10 files changed
+162 -177

No files matched your search

+5 -3
View File
@@ -55,6 +55,7 @@ def build_search_handler(
history=None,
fallback_adapters: dict[str, SearchAdapter] | None = None,
ai_model: str = "",
proxy_cost_per_gb: float = 0.0,
):
"""검색 핸들러 생성.
judge: SimilarityJudge(같은 상품 판정) / keyword_gen: KeywordGenerator(정밀·광역 재검색어) /
@@ -75,13 +76,14 @@ def build_search_handler(
async def _timed_search(adapter, query: str, source: str, metrics: SearchMetrics, crawl: bool):
"""어댑터 검색 1건을 타이밍+바이트 계측하며 실행. 예외는 그대로 전파(호출부가 처리)."""
via_proxy = bool(getattr(adapter, "uses_proxy", False))
t0 = time.monotonic()
try:
res = await adapter.search(query, limit=limit)
metrics.add_fetch(source, getattr(adapter, "last_bytes", 0), int((time.monotonic() - t0) * 1000), crawl=crawl)
metrics.add_fetch(source, getattr(adapter, "last_bytes", 0), int((time.monotonic() - t0) * 1000), crawl=crawl, via_proxy=via_proxy)
return res
except Exception:
metrics.add_fetch(source, 0, int((time.monotonic() - t0) * 1000), crawl=crawl)
metrics.add_fetch(source, 0, int((time.monotonic() - t0) * 1000), crawl=crawl, via_proxy=via_proxy)
raise
async def _search_round(query: str, metrics: SearchMetrics):
@@ -153,7 +155,7 @@ def build_search_handler(
target = {k: payload.get(k, "") for k in ("product_name", "model", "specification", "company")}
base_price = parse_price(payload.get("price"))
cache_key = payload.get("product_code") or base_query
metrics = SearchMetrics(ai_model) # 검색 1건의 리소스/비용/시간 계측
metrics = SearchMetrics(ai_model, proxy_cost_per_gb) # 검색 1건의 리소스/비용/시간 계측
# 0) 네거티브 캐시 — 최근 not_found면 재검색 생략
if neg_cache is not None and await neg_cache.is_negative(cache_key):