feat: 建立可观测性、容量与恢复验证基线

This commit is contained in:
weijuesen
2026-08-14 14:54:56 +08:00
parent 126c215a6b
commit 1e6a5dbfb8
16 changed files with 398 additions and 3 deletions
+3
View File
@@ -2,6 +2,7 @@ import shutil
import subprocess
import threading
import time
import uuid
from fastapi import FastAPI, File, HTTPException, Request, UploadFile
@@ -21,8 +22,10 @@ stream_worker = StreamTaskWorker(config.STREAM_TASK_MAX_WORKERS)
async def count_requests(request: Request, call_next):
global _requests, _latency_total
start = time.time()
request_id = request.headers.get("x-request-id") or str(uuid.uuid4())
response = await call_next(request)
latency = (time.time() - start) * 1000
response.headers["X-Request-ID"] = request_id
with _lock:
_requests += 1
_latency_total += latency
+1
View File
@@ -31,6 +31,7 @@ def test_health():
def test_detect_ok():
r = client.post("/detect", files={"file": ("a.png", TINY_PNG, "image/png")})
assert r.status_code == 200
assert r.headers.get("x-request-id")
body = r.json()
assert body["model"] == "mock"
assert body["modelVersion"]