feat: add Prometheus metrics + fix CI/CD health check port
- Add prometheus-client dependency - Create middleware/metrics.py with PrometheusMiddleware - Expose /metrics endpoint in Prometheus text format - Track http_requests_total, translation_total, translation_duration_seconds, file_size_bytes - Instrument translate routes with record_translation() and record_file_size() - Fix deploy.yml health check: localhost:8000 -> localhost:8001 (Portainer conflict) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
8
main.py
8
main.py
@@ -56,6 +56,7 @@ from middleware.security import (
|
||||
RequestLoggingMiddleware,
|
||||
)
|
||||
from middleware.error_handler import ErrorHandlingMiddleware, format_error_response
|
||||
from middleware.metrics import PrometheusMiddleware, get_metrics
|
||||
from middleware.cleanup import (
|
||||
MemoryMonitor,
|
||||
HealthChecker,
|
||||
@@ -359,6 +360,7 @@ app = FastAPI(
|
||||
app.openapi = custom_openapi
|
||||
|
||||
app.add_middleware(ErrorHandlingMiddleware)
|
||||
app.add_middleware(PrometheusMiddleware)
|
||||
app.add_middleware(RequestLoggingMiddleware, log_body=False)
|
||||
app.add_middleware(
|
||||
SecurityHeadersMiddleware,
|
||||
@@ -574,6 +576,12 @@ async def root():
|
||||
}
|
||||
|
||||
|
||||
@app.get("/metrics", tags=["Health"])
|
||||
async def metrics_endpoint():
|
||||
"""Prometheus metrics endpoint"""
|
||||
return get_metrics()
|
||||
|
||||
|
||||
@app.get("/health", tags=["Health"])
|
||||
async def health_check():
|
||||
"""Health check endpoint with detailed system status (Kubernetes liveness probe)"""
|
||||
|
||||
Reference in New Issue
Block a user