Mount the instrumentator immediately after FastAPI app creation, excluding /health and /metrics from request metrics to keep http_requests_total focused on real application traffic. Refs #652 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
833 B
Python
25 lines
833 B
Python
"""Tests for Prometheus metrics exposed by the OCR service.
|
|
|
|
Each test that asserts on a counter/gauge value uses a fresh CollectorRegistry
|
|
(see decision #3 on issue #652) to keep the metrics isolated between tests.
|
|
"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from main import app
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_metrics_endpoint_returns_200():
|
|
"""`GET /metrics` returns 200 with Prometheus exposition content."""
|
|
with patch("main.kraken_engine.load_models"), \
|
|
patch("main.load_spell_checker"):
|
|
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
|
response = await client.get("/metrics")
|
|
|
|
assert response.status_code == 200
|
|
assert "text/plain" in response.headers.get("content-type", "")
|