- src/metrics.py: счётчики строк, чанков, файлов (processed/failed) и start_metrics_server - settings: METRICS_ENABLED (true), METRICS_PORT (9100) - main: запуск сервера метрик перед pipeline - pipeline: учёт записанных в Qdrant строк/чанков; финальная группа без чанков сдвигает чекпоинт, не вызывая embed/upsert - helm: порт metrics в контейнере, METRICS_ENABLED/METRICS_PORT в configmap - prometheus-client в зависимостях, тесты и документация
33 lines
992 B
Python
33 lines
992 B
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:
|
|
"""Счётчики зарегистрированы с ожидаемыми именами (с суффиксом _total)."""
|
|
from prometheus_client import REGISTRY
|
|
|
|
names = {
|
|
sample.name
|
|
for metric in REGISTRY.collect()
|
|
for sample in metric.samples
|
|
}
|
|
for name in (
|
|
"etl_rows_processed_total",
|
|
"etl_chunks_upserted_total",
|
|
"etl_files_processed_total",
|
|
"etl_files_failed_total",
|
|
):
|
|
assert name in names
|