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
|
||||
|
||||
Reference in New Issue
Block a user