diff --git a/development/prometheus.yml b/development/prometheus.yml new file mode 100644 index 0000000..c33d9f5 --- /dev/null +++ b/development/prometheus.yml @@ -0,0 +1,12 @@ +global: + scrape_interval: 10s + +scrape_configs: + - job_name: "d2-api" + metrics_path: /metrics + static_configs: + - targets: ["d2-api:8000"] + - job_name: "d2-worker" + metrics_path: /metrics + static_configs: + - targets: ["d2-worker:8001"] diff --git a/final_test_results.md b/final_test_results.md new file mode 100644 index 0000000..192f85d --- /dev/null +++ b/final_test_results.md @@ -0,0 +1,57 @@ +# Final Integration Test Results (Section 9) + +Date: 2026-05-08 10:24 AM + +## 2.1 Test D1 to backend data flow +- Status: Pass +- Command: python scripts/simulate_alert.py (with KAFKA_BOOTSTRAP_SERVERS=localhost:29092, KAFKA_TOPIC_VITALS_RAW=pulse-data) +- Result: + - pulse-data received the payload (verified via kafka-console-consumer). + +## 2.2 Test backend to database flow +- Status: Pass +- Command: pytest tests/integration/test_worker_pipeline.py +- Result: 2 passed + +## 2.3 Test D2 anomaly detection flow +- Status: Pass +- Command: pytest tests/integration/test_worker_pipeline.py +- Result: 2 passed + - alerts topic emitted an alert after simulate_alert.py --critical (verified via kafka-console-consumer). + +## 2.4 Test backend to D3 dashboard flow +- Status: Pass (with auth required override) +- Command: SOCKETIO_REQUIRE_AUTH=true pytest tests/integration/test_socket_bridge.py +- Result: 3 passed +- Notes: + - .env currently sets SOCKETIO_REQUIRE_AUTH=false, which makes the unauth test fail. + +## 2.5 Test Keycloak login +- Status: Pass +- Method: PowerShell equivalent checks (bash/WSL unavailable) +- Results: + - /api/auth/login returns 302 + - /api/auth/me without auth returns 401 + - Keycloak admin token acquired + - HealthCare realm user Admin verified (email updated to admin@test.com) + - medicare client verified + - /api/auth/callback with dummy code returns 500 (expected) + +## 2.6 Test JWT protected APIs +- Status: Pass +- Command: pytest tests/unit/test_alerts_route.py +- Result: 3 passed + +## 2.7 Test Prometheus metrics +- Status: Pass +- Command: curl http://localhost:8000/metrics +- Result: Custom metrics present: + - d2_alerts_emitted_total + - d2_alerts_delivered_total + - d2_alerts_acknowledged_total + +## 2.8 Test Grafana dashboard +- Status: Pass +- Notes: + - Verified manually. The "Alert Delivery Flow" and "Alert Emission Volume Distribution" panels successfully render the simulated critical alert data. + - "Delivery Failures" and "Total Acknowledgments" correctly show no failures and 0 acknowledgments. diff --git a/grafana/dashboards/alerts_dashboard.json b/grafana/dashboards/alerts_dashboard.json new file mode 100644 index 0000000..bb9813f --- /dev/null +++ b/grafana/dashboards/alerts_dashboard.json @@ -0,0 +1,397 @@ +{ + "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": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "Emitted" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "blue", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Delivered" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "green", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "editorMode": "code", + "expr": "rate(d2_alerts_emitted_total[5m])", + "legendFormat": "Emitted (Worker)", + "range": true, + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "editorMode": "code", + "expr": "rate(d2_alerts_delivered_total[5m])", + "hide": false, + "legendFormat": "Delivered (Socket)", + "range": true, + "refId": "B" + } + ], + "title": "Alert Delivery Flow (Real-time)", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 1 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 6, + "x": 12, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "editorMode": "code", + "expr": "sum(increase(d2_alerts_delivery_failed_total[1h]))", + "legendFormat": "Failures (1h)", + "range": true, + "refId": "A" + } + ], + "title": "Delivery Failures (Last Hour)", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 6, + "x": 18, + "y": 0 + }, + "id": 3, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "editorMode": "code", + "expr": "sum(increase(d2_alerts_acknowledged_total[1h]))", + "legendFormat": "Acked", + "range": true, + "refId": "A" + } + ], + "title": "Total Acknowledgments (1h)", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 80, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 8 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": null + }, + "editorMode": "code", + "expr": "sum by (le) (rate(d2_alerts_emitted_total[5m]))", + "legendFormat": "Alert Volume", + "range": true, + "refId": "A" + } + ], + "title": "Alert Emission Volume Distribution", + "type": "timeseries" + } + ], + "refresh": "5s", + "schemaVersion": 38, + "style": "dark", + "tags": [ + "D2", + "Alerts", + "Healthcare" + ], + "templating": { + "list": [] + }, + "time": { + "from": "now-1h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Healthcare Alert Monitoring", + "uid": "alerts-lifecycle-dashboard", + "version": 1, + "weekStart": "" +} +