feat(lps): 알림 룰 4종 추가 — 데드라인·검색원가·포트 고갈·예산 누수
협의로 선정한 조기 신호 4종을 AlertManager 에 추가한다. - deadline: 최근 1h JobDeadlineExceeded 수 ≥ LPS_ALERT_DEADLINE_1H(5). 재시도로 살아나면 dead 룰엔 안 잡히는 크롤 행 반복 신호를 별도 집계. - cost: 최근 1h 완료 잡 검색원가 합 ≥ LPS_ALERT_COST_1H_USD(1.0). 비용의 87%가 프록시 대역폭 — 리소스차단 풀림·재시도 루프의 조용한 비용 폭주를 감시. job.result 의 metrics.cost.total_usd JSONB 합산. - proxy_ports_low: 가용 포트 비율 ≤ LPS_ALERT_PORTS_LOW_PCT(30%). 쿨다운 격리 누적 — blocks_1h(80건)보다 먼저 우는 대규모 차단 조기 신호. 워커별 프록시 중 가장 소진된 것 기준(min). - budget_leak: 최근 6h end_reason=block 세션 ≥ LPS_ALERT_BLOCK_SESSIONS_6H(1). 요청 예산(3회)을 지켰는데도 차단됨 = 예산 하향 검토 신호. - deadline_1h·cost_1h_usd 는 queue.ops() 에 편입 → /v1/lps/ops 로도 노출. 포트·세션 지표는 워커 웹훅 스냅샷에 포함(프록시 상태는 워커에만 있음). - 테스트 4건 추가(ops 집계 2·포트 스냅샷 2), 전체 145 passed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e7d2c87fbe
commit
ca7f057e41
6 files changed
+109
-6
No files matched your search
@@ -91,3 +91,26 @@ def test_backoff_is_exponential_capped():
|
||||
assert compute_backoff(2, base=5) == 10
|
||||
assert compute_backoff(3, base=5) == 20
|
||||
assert compute_backoff(100, base=5, cap=600) == 600
|
||||
|
||||
|
||||
async def test_ops_counts_deadline_and_cost(q):
|
||||
# 완료 잡 2건의 검색원가 합산 — claim 반환 잡을 완료(순서 의존 제거)
|
||||
for code, cost in (("b", 0.01), ("c", 0.02)):
|
||||
await q.enqueue(JobType.SEARCH.value, {"q": code})
|
||||
job = await q.claim("w1")
|
||||
await q.complete(job["job_id"], "w1", {"metrics": {"cost": {"total_usd": cost}}})
|
||||
# 데드라인 강제종료 — 재큐(PENDING)로 살아나도 deadline_1h 에 잡혀야 한다(dead 와 별개 축)
|
||||
j1 = await q.enqueue(JobType.SEARCH.value, {"q": "a"})
|
||||
await q.claim("w1")
|
||||
await q.fail(j1, "w1", "JobDeadlineExceeded: 300s", backoff_sec=0)
|
||||
snap = await q.ops()
|
||||
assert snap["deadline_1h"] == 1
|
||||
assert abs(snap["cost_1h_usd"] - 0.03) < 1e-9
|
||||
|
||||
|
||||
async def test_ops_cost_ignores_jobs_without_metrics(q):
|
||||
jid = await q.enqueue(JobType.SEARCH.value, {"q": "x"})
|
||||
await q.claim("w1")
|
||||
await q.complete(jid, "w1", {"count": 3}) # metrics 없는 결과 — 합산에서 무시(0)
|
||||
snap = await q.ops()
|
||||
assert snap["cost_1h_usd"] == 0
|
||||
Reference in new issue
Block a user