Add OpenTelemetry instrumentation with distributed tracing and metrics: - Structured JSON logging with trace context correlation - Auto-instrumentation for FastAPI, asyncpg, httpx, redis - OTLP exporter for traces and Prometheus metrics endpoint Implement Celery worker and notification task system: - Celery app with Redis/SQS broker support and configurable queues - Notification tasks for incident fan-out, webhooks, and escalations - Pluggable TaskQueue abstraction with in-memory driver for testing Add Grafana observability stack (Loki, Tempo, Prometheus, Grafana): - OpenTelemetry Collector for receiving OTLP traces and logs - Tempo for distributed tracing backend - Loki for log aggregation with Promtail DaemonSet - Prometheus for metrics scraping with RBAC configuration - Grafana with pre-provisioned datasources and API overview dashboard - Helm templates for all observability components Enhance application infrastructure: - Global exception handlers with structured ErrorResponse schema - Request logging middleware with timing metrics - Health check updated to verify task queue connectivity - Non-root user in Dockerfile for security - Init containers in Helm deployments for dependency ordering - Production Helm values with autoscaling and retention policies
39 lines
864 B
Docker
39 lines
864 B
Docker
# Multi-stage Dockerfile for API and Worker services
|
|
FROM python:3.14-slim AS base
|
|
|
|
WORKDIR /app
|
|
|
|
# Install uv
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
|
|
|
# Install Python dependencies
|
|
COPY pyproject.toml uv.lock README.md ./
|
|
RUN uv sync --no-cache --no-dev
|
|
|
|
# Copy application code
|
|
COPY app/ ./app/
|
|
COPY worker/ ./worker/
|
|
COPY migrations/ ./migrations/
|
|
|
|
# Set up non-root user and cache directory
|
|
RUN useradd -m -u 1000 appuser && \
|
|
mkdir -p /app/.cache && \
|
|
chown -R appuser:appuser /app
|
|
|
|
ENV UV_CACHE_DIR=/app/.cache
|
|
|
|
# API service target
|
|
FROM base AS api
|
|
|
|
USER appuser
|
|
EXPOSE 8000
|
|
|
|
CMD ["uv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
|
# Worker service target
|
|
FROM base AS worker
|
|
|
|
USER appuser
|
|
|
|
CMD ["uv", "run", "celery", "-A", "worker.celery_app", "worker", "--loglevel=info", "-Q", "critical,default,low"]
|