feat: добавлен сбор метрик: падения запросов к embeded модели; падения запросов к Qdrant, S3; скорости обработки новостей с выделением затраченного времени работы embeded - модели

This commit is contained in:
mike committed 2026-12-02 15:09:50 +03:00
1 parent dd0a124e36
commit a7974404a9
11 files changed
+287 -17

No files matched your search

+19 -5
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
import time
import httpx
import structlog
@@ -12,6 +13,7 @@ from src.embeddings.base import (
EmbeddingProvider,
TransientEmbeddingError,
)
from src.metrics import EMBEDDING_REQUEST_DURATION, EMBEDDING_REQUESTS_FAILED
_RETRYABLE_STATUS = {429, 500, 502, 503, 504}
@@ -68,13 +70,25 @@ class OpenAIEmbeddingProvider(EmbeddingProvider):
async def _embed_batch(self, texts: list[str]) -> list[list[float]]:
"""Один HTTP-запрос к embedding API (с ограничением конкурентности)."""
async with self._semaphore:
response = await self._client.post(
f"{self._api_url}/embeddings",
headers={"Authorization": f"Bearer {self._api_key}"},
json={"model": self._model, "input": texts},
)
started = time.perf_counter()
try:
response = await self._client.post(
f"{self._api_url}/embeddings",
headers={"Authorization": f"Bearer {self._api_key}"},
json={"model": self._model, "input": texts},
)
except httpx.HTTPError as exc:
EMBEDDING_REQUESTS_FAILED.labels(
error_type=type(exc).__name__
).inc()
raise
finally:
EMBEDDING_REQUEST_DURATION.observe(time.perf_counter() - started)
if response.status_code != 200:
EMBEDDING_REQUESTS_FAILED.labels(
error_type=f"http_{response.status_code}"
).inc()
error_type = (
TransientEmbeddingError
if response.status_code in _RETRYABLE_STATUS