diff --git a/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerConfiguration.cs b/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerConfiguration.cs index 72f3cbb4..ce6736d7 100644 --- a/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerConfiguration.cs +++ b/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerConfiguration.cs @@ -29,6 +29,7 @@ internal static class PresentationApiLayerConfiguration configuration.SetBasePath(basePath); configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); configuration.AddJsonFile("appsettings.development.json", optional: true, reloadOnChange: true); + configuration.AddEnvironmentVariables(); // environment variables should override the configuration files return services; } diff --git a/src/Lumina.Presentation.Api/Dockerfile b/src/Lumina.Presentation.Api/Dockerfile index 34e09240..297fdfe6 100644 --- a/src/Lumina.Presentation.Api/Dockerfile +++ b/src/Lumina.Presentation.Api/Dockerfile @@ -1,6 +1,10 @@ # This stage is used when running from VS in fast mode (Default for Debug configuration) FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base -RUN mkdir /logs && chown -R app:app /logs +# curl is used by the container healthcheck to probe the /health endpoints +RUN apt-get update \ + && apt-get install -y --no-install-recommends curl \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir /logs && chown -R app:app /logs USER app WORKDIR /app EXPOSE 5214 @@ -18,8 +22,10 @@ COPY ["Lumina.Presentation.Api/Lumina.Presentation.Api.csproj", "Lumina.Presenta COPY ["Lumina.Application/Lumina.Application.csproj", "Lumina.Application/"] COPY ["Lumina.Contracts/Lumina.Contracts.csproj", "Lumina.Contracts/"] COPY ["Lumina.Domain/Lumina.Domain.csproj", "Lumina.Domain/"] +COPY ["Lumina.Domain.SharedKernel/Lumina.Domain.SharedKernel.csproj", "Lumina.Domain.SharedKernel/"] COPY ["Lumina.Infrastructure/Lumina.Infrastructure.csproj", "Lumina.Infrastructure/"] COPY ["Lumina.DataAccess/Lumina.DataAccess.csproj", "Lumina.DataAccess/"] +COPY ["Lumina.Plugins.Contracts/Lumina.Plugins.Contracts.csproj", "Lumina.Plugins.Contracts/"] RUN dotnet restore "./Lumina.Presentation.Api/Lumina.Presentation.Api.csproj" /p:BaseOutputPath=/app/publish/ @@ -49,6 +55,8 @@ FROM base AS final WORKDIR /app COPY --from=publish /app/publish . +# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for +# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set ENV ASPNETCORE_HTTP_PORTS=5214 EXPOSE 5214 ENTRYPOINT ["dotnet", "Lumina.Presentation.Api.dll"] diff --git a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs index 8bea5b86..b99a8a74 100644 --- a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs +++ b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs @@ -25,7 +25,8 @@ internal static class PresentationWebLayerConfiguration // add the configuration sources to the configuration builder configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); configuration.AddJsonFile("appsettings.development.json", optional: true, reloadOnChange: true); - + configuration.AddEnvironmentVariables(); // environment variables should override the configuration files + serviceCollection.AddOptions() .Bind(configuration.GetRequiredSection(ServerConfigurationDto.SECTION_NAME)) .ValidateFluently() diff --git a/src/Lumina.Presentation.Web/Dockerfile b/src/Lumina.Presentation.Web/Dockerfile index b02a6f9f..a8fa08da 100644 --- a/src/Lumina.Presentation.Web/Dockerfile +++ b/src/Lumina.Presentation.Web/Dockerfile @@ -1,6 +1,10 @@ # This stage is used when running from VS in fast mode (Default for Debug configuration) FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base -RUN mkdir /logs && chown -R app:app /logs +# curl is used by the container healthcheck to probe the /health endpoints +RUN apt-get update \ + && apt-get install -y --no-install-recommends curl \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir /logs && chown -R app:app /logs USER app WORKDIR /app EXPOSE 5012 @@ -40,6 +44,8 @@ FROM base AS final WORKDIR /app COPY --from=publish /app/publish . +# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for +# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set ENV ASPNETCORE_HTTP_PORTS=5012 EXPOSE 5012 ENTRYPOINT ["dotnet", "Lumina.Presentation.Web.dll"] diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 10d6ab87..38565799 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -7,6 +7,20 @@ services: dockerfile: Lumina.Presentation.Api/Dockerfile environment: - LOG_PATH=/logs + - OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 + # The API validates JwtSettings:SecretKey and EncryptionSettings:SecretKey with ValidateOnStart(). In the + # Development environment they come from appsettings.development.json; for any non-development run they must be + # supplied here, otherwise the API crashes on startup: + # - JwtSettings__SecretKey= + # - EncryptionSettings__SecretKey= + depends_on: + - otel-collector + healthcheck: + test: ["CMD-SHELL", "curl -sf http://localhost:5214/health/ready || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 60s lumina-web: container_name: lumina-web @@ -16,3 +30,64 @@ services: dockerfile: Lumina.Presentation.Web/Dockerfile environment: - LOG_PATH=/logs + - OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 + - ServerConfiguration__BaseAddress=http://lumina-api + depends_on: + - otel-collector + - lumina-api + healthcheck: + test: ["CMD-SHELL", "curl -sf http://localhost:5012/health/ready || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 60s + + otel-collector: + container_name: otel-collector + image: otel/opentelemetry-collector-contrib:0.159.0 + command: + - "--config=/etc/otelcol/config.yml" + volumes: + - ./otel-collector/otel-collector-config.yml:/etc/otelcol/config.yml:ro + ports: + - "4317:4317" + - "4318:4318" + - "8889:8889" + depends_on: + - jaeger + restart: unless-stopped + + jaeger: + container_name: jaeger + image: jaegertracing/all-in-one:1.76.0 + environment: + - COLLECTOR_OTLP_ENABLED=true + ports: + - "16686:16686" + restart: unless-stopped + + prometheus: + container_name: prometheus + image: prom/prometheus:v3 + volumes: + - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro + ports: + - "9090:9090" + depends_on: + - otel-collector + restart: unless-stopped + + grafana: + container_name: grafana + image: grafana/grafana:13.0.7-ubuntu-slim + environment: + # dev-only stack: set a non-default admin password (override GRAFANA_ADMIN_PASSWORD in real deployments) + - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:-lumina-admin} + volumes: + - ./grafana/provisioning:/etc/grafana/provisioning:ro + - ./grafana/dashboards:/var/lib/grafana/dashboards:ro + ports: + - "127.0.0.1:3000:3000" + depends_on: + - prometheus + restart: unless-stopped diff --git a/src/grafana/dashboards/lumina.json b/src/grafana/dashboards/lumina.json new file mode 100644 index 00000000..27bdcc5c --- /dev/null +++ b/src/grafana/dashboards/lumina.json @@ -0,0 +1,138 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 1, + "id": null, + "links": [], + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "fieldConfig": { + "defaults": { + "unit": "ms" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "desc" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.95, sum(rate(lumina_application_handler_duration_bucket[5m])) by (le, lumina_handler_type))", + "legendFormat": "p95 {{lumina_handler_type}}", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.50, sum(rate(lumina_application_handler_duration_bucket[5m])) by (le, lumina_handler_type))", + "legendFormat": "p50 {{lumina_handler_type}}", + "refId": "B" + } + ], + "title": "Application handler duration", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "fieldConfig": { + "defaults": { + "unit": "ops" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 2, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "desc" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(lumina_application_handler_invocations_total[5m])) by (lumina_handler_type, lumina_outcome)", + "legendFormat": "{{lumina_handler_type}} {{lumina_outcome}}", + "refId": "A" + } + ], + "title": "Application handler invocations", + "type": "timeseries" + } + ], + "refresh": "10s", + "schemaVersion": 40, + "tags": [ + "lumina", + "telemetry" + ], + "templating": { + "list": [] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Lumina", + "uid": "lumina-overview", + "version": 1 +} diff --git a/src/grafana/provisioning/dashboards/dashboards.yml b/src/grafana/provisioning/dashboards/dashboards.yml new file mode 100644 index 00000000..4a016440 --- /dev/null +++ b/src/grafana/provisioning/dashboards/dashboards.yml @@ -0,0 +1,12 @@ +apiVersion: 1 + +providers: + - name: Lumina + orgId: 1 + folder: Lumina + type: file + disableDeletion: false + updateIntervalSeconds: 30 + allowUiUpdates: true + options: + path: /var/lib/grafana/dashboards diff --git a/src/grafana/provisioning/datasources/datasources.yml b/src/grafana/provisioning/datasources/datasources.yml new file mode 100644 index 00000000..27f1a57a --- /dev/null +++ b/src/grafana/provisioning/datasources/datasources.yml @@ -0,0 +1,16 @@ +apiVersion: 1 + +datasources: + - name: Prometheus + uid: prometheus + type: prometheus + access: proxy + url: http://prometheus:9090 + isDefault: true + editable: true + - name: Jaeger + uid: jaeger + type: jaeger + access: proxy + url: http://jaeger:16686 + editable: true diff --git a/src/otel-collector/otel-collector-config.yml b/src/otel-collector/otel-collector-config.yml new file mode 100644 index 00000000..74cb5735 --- /dev/null +++ b/src/otel-collector/otel-collector-config.yml @@ -0,0 +1,46 @@ +receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + +processors: + memory_limiter: + check_interval: 5s + limit_mib: 512 + spike_limit_mib: 128 + batch: + +exporters: + otlp/jaeger: + endpoint: jaeger:4317 + tls: + insecure: true + prometheus: + endpoint: 0.0.0.0:8889 + +extensions: + health_check: + +service: + extensions: + - health_check + pipelines: + traces: + receivers: + - otlp + processors: + - memory_limiter + - batch + exporters: + - otlp/jaeger + metrics: + receivers: + - otlp + processors: + - memory_limiter + - batch + exporters: + - prometheus diff --git a/src/prometheus/prometheus.yml b/src/prometheus/prometheus.yml new file mode 100644 index 00000000..0d185162 --- /dev/null +++ b/src/prometheus/prometheus.yml @@ -0,0 +1,9 @@ +global: + scrape_interval: 15s + evaluation_interval: 15s + +scrape_configs: + - job_name: otel-collector + static_configs: + - targets: + - otel-collector:8889