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:
1 parent
9c478e80fd
commit
c955a8f367
10 files changed
+162
-177
No files matched your search
@@ -10,7 +10,11 @@ Decodo residential 은 **포트 기반 sticky** 모델이다:
|
||||
"""
|
||||
|
||||
import time
|
||||
from urllib.parse import quote
|
||||
|
||||
import httpx
|
||||
|
||||
from common.logger import LOG
|
||||
from config.server_configs import decodo_config
|
||||
|
||||
|
||||
@@ -52,3 +56,25 @@ class DecodoProxy:
|
||||
"username": self.username,
|
||||
"password": self.password,
|
||||
}
|
||||
|
||||
def _proxy_url(self, port: int) -> str:
|
||||
return f"http://{quote(self.username)}:{quote(self.password)}@{self.host}:{port}"
|
||||
|
||||
async def healthcheck(self, timeout: float = 6.0) -> tuple[str | None, int | None]:
|
||||
"""시작 프리플라이트: 현재 포트로 egress IP 확인, 실패하면 회전하며 살아있는 포트를 찾는다.
|
||||
반환: (egress_ip, port) 성공 / (None, None) 전 포트 실패. residential IP 는 실행 중에도
|
||||
죽으므로 이건 '빠른 실패+가시성'용이고, 실제 회복은 런타임 IP 회전이 담당한다."""
|
||||
if not self.enabled:
|
||||
return None, None
|
||||
n = self.port_end - self.port_start + 1
|
||||
for _ in range(n):
|
||||
port = self._port()
|
||||
try:
|
||||
async with httpx.AsyncClient(proxy=self._proxy_url(port), timeout=timeout) as c:
|
||||
r = await c.get("https://ip.decodo.com/ip")
|
||||
if r.status_code == 200:
|
||||
return r.text.strip(), port
|
||||
except Exception as ex:
|
||||
LOG.d(f"[proxy] 포트 {port} 헬스체크 실패: {type(ex).__name__} → 회전")
|
||||
self.rotate()
|
||||
return None, None
|
||||
Reference in new issue
Block a user