42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""Тесты Prometheus-метрик сервиса (src/metrics.py)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from src import metrics
|
|
|
|
|
|
def test_start_metrics_server_uses_given_port(mocker) -> None:
|
|
"""start_metrics_server передаёт порт в prometheus_client.start_http_server."""
|
|
start_mock = mocker.patch("src.metrics.start_http_server")
|
|
|
|
metrics.start_metrics_server(9100)
|
|
|
|
start_mock.assert_called_once_with(9100)
|
|
|
|
|
|
def test_metric_names_exposed_in_registry() -> None:
|
|
"""Метрики зарегистрированы с ожидаемыми именами."""
|
|
from prometheus_client import REGISTRY
|
|
|
|
names = {
|
|
name
|
|
for metric in REGISTRY.collect()
|
|
for name in (
|
|
metric.name,
|
|
f"{metric.name}_total",
|
|
*(sample.name for sample in metric.samples),
|
|
)
|
|
}
|
|
for name in (
|
|
"etl_rows_processed_total",
|
|
"etl_chunks_upserted_total",
|
|
"etl_files_processed_total",
|
|
"etl_files_failed_total",
|
|
"etl_embedding_requests_failed_total",
|
|
"etl_qdrant_requests_failed_total",
|
|
"etl_s3_requests_failed_total",
|
|
"etl_file_process_duration_seconds",
|
|
"etl_embedding_request_duration_seconds",
|
|
):
|
|
assert name in names
|