feat: 建立可观测性、容量与恢复验证基线
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user