feat: add health check endpoint and suppress health check logs

Added a /health endpoint for application health monitoring

Implemented logging filter to suppress health check requests from logs

Updated Dockerfile and Kubernetes deployment to use the new health check endpoint

Incremented production image tag version
This commit is contained in:
2025-09-04 00:42:53 +02:00
parent cadc34f797
commit b3426f7493
4 changed files with 27 additions and 10 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/ || exit 1
CMD curl -f http://localhost:8000/health || exit 1
# Run the application
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
+17
View File
@@ -14,6 +14,17 @@ from fastapi.templating import Jinja2Templates
from pydantic import BaseModel
from fpdf import FPDF
import logging
# Custom filter to exclude health check logs
class HealthCheckFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
# Exclude health check requests from logs
return "GET /health " not in record.getMessage()
# Apply the filter to Uvicorn's access logger
logging.getLogger("uvicorn.access").addFilter(HealthCheckFilter())
app = FastAPI()
# S3 Configuration
@@ -464,6 +475,12 @@ async def bulk_download(filenames: str = Form(...)):
return {"error": f"Error downloading files: {str(e)}"}
@app.get("/health")
async def health_check():
"""Health check endpoint that returns the status of the application"""
return {"status": "healthy"}
if __name__ == "__main__":
import uvicorn
+2 -2
View File
@@ -46,7 +46,7 @@ spec:
# Liveness probe
livenessProbe:
httpGet:
path: /
path: /health
port: 8000
initialDelaySeconds: 90
periodSeconds: 10
@@ -55,7 +55,7 @@ spec:
# Readiness probe
readinessProbe:
httpGet:
path: /
path: /health
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
@@ -13,7 +13,7 @@ resources:
images:
- name: math-exercises
newName: harbor.cl1.parano.ch/library/math-exercice
newTag: 1.0.5
newTag: 1.0.7
# Production-specific labels