|
| 1 | +# Alerting flow (OnCall) |
| 2 | + |
| 3 | +- Routing: Prometheus Alertmanager → Grafana OnCall (two integrations: `critical`/`warning`) → OnCall outgoing webhook → `oncall-discord-proxy` → Discord webhooks (`#alerts-critical`, `#alerts-warning`). |
| 4 | +- Discord: one message per alert group, updated in-place on resolve; every message includes the `@OnCall` role mention. |
| 5 | +- OnCall stack lives in `monitoring-oncall` (HelmRelease `oncall`) with a dedicated Grafana UI: `https://${ENV_PREFIX}oncall.${BASE_DOMAIN}/grafana`. |
| 6 | +- Storage: Postgres + Redis subcharts (RabbitMQ is disabled); Grafana state on a local PV (`/mnt/data/oncall-grafana`). |
| 7 | + |
| 8 | +## Bootstrap and wiring |
| 9 | +- Job `oncall-bootstrap` (namespace `monitoring-oncall`) runs on reconcile: |
| 10 | + - reads `alertmanager-oncall` and `alertmanager-discord-proxy` secrets, |
| 11 | + - creates/updates two Alertmanager integrations with fixed tokens (`alertmanager-critical`, `alertmanager-warning`), |
| 12 | + - configures outgoing webhooks (trigger: status change) to call the in-cluster Discord proxy. |
| 13 | +- If you rotate tokens/webhooks, update SOPS secrets and rerun the job: |
| 14 | + `k3s kubectl delete job/oncall-bootstrap -n monitoring-oncall`. |
| 15 | + |
| 16 | +## Smoke test (FIRING → RESOLVED, 15s, no spam) |
| 17 | +This hits the OnCall Alertmanager integration endpoint directly (deterministic; good for formatting and “edit-on-resolve”). |
| 18 | + |
| 19 | +1) Get integration URLs (from the node): |
| 20 | +``` |
| 21 | +export KUBECONFIG=/etc/rancher/k3s/k3s.yaml |
| 22 | +critical=$(k3s kubectl -n monitoring get secret alertmanager-oncall -o jsonpath='{.data.critical_url}' | base64 -d) |
| 23 | +warning=$(k3s kubectl -n monitoring get secret alertmanager-oncall -o jsonpath='{.data.warning_url}' | base64 -d) |
| 24 | +``` |
| 25 | + |
| 26 | +2) Fire and resolve: |
| 27 | +``` |
| 28 | +k3s kubectl -n monitoring-oncall run --rm -i alert-smoke --restart=Never --image=curlimages/curl -- sh -c ' |
| 29 | +set -euo pipefail |
| 30 | +cat >/tmp/firing.json <<EOF |
| 31 | +{ |
| 32 | + "receiver": "oncall-smoke", |
| 33 | + "status": "firing", |
| 34 | + "alerts": [ |
| 35 | + { |
| 36 | + "status": "firing", |
| 37 | + "labels": { |
| 38 | + "alertname": "oncall-smoke-delay15", |
| 39 | + "severity": "warning", |
| 40 | + "cluster": "prod", |
| 41 | + "namespace": "monitoring", |
| 42 | + "instance": "51.158.67.237:9100" |
| 43 | + }, |
| 44 | + "annotations": { |
| 45 | + "summary": "OnCall Discord smoke test", |
| 46 | + "description": "Expect one Discord message that updates on resolve" |
| 47 | + }, |
| 48 | + "startsAt": "2025-01-01T00:00:00Z", |
| 49 | + "endsAt": "0001-01-01T00:00:00Z" |
| 50 | + } |
| 51 | + ], |
| 52 | + "commonLabels": { |
| 53 | + "alertname": "oncall-smoke-delay15", |
| 54 | + "severity": "warning", |
| 55 | + "cluster": "prod", |
| 56 | + "namespace": "monitoring", |
| 57 | + "instance": "51.158.67.237:9100" |
| 58 | + }, |
| 59 | + "commonAnnotations": { |
| 60 | + "summary": "OnCall Discord smoke test", |
| 61 | + "description": "Expect one Discord message that updates on resolve" |
| 62 | + }, |
| 63 | + "version": "4" |
| 64 | +} |
| 65 | +EOF |
| 66 | +cat >/tmp/resolved.json <<EOF |
| 67 | +{ |
| 68 | + "receiver": "oncall-smoke", |
| 69 | + "status": "resolved", |
| 70 | + "alerts": [ |
| 71 | + { |
| 72 | + "status": "resolved", |
| 73 | + "labels": { |
| 74 | + "alertname": "oncall-smoke-delay15", |
| 75 | + "severity": "warning", |
| 76 | + "cluster": "prod", |
| 77 | + "namespace": "monitoring", |
| 78 | + "instance": "51.158.67.237:9100" |
| 79 | + }, |
| 80 | + "annotations": { |
| 81 | + "summary": "OnCall Discord smoke test", |
| 82 | + "description": "Expect one Discord message that updates on resolve" |
| 83 | + }, |
| 84 | + "startsAt": "2025-01-01T00:00:00Z", |
| 85 | + "endsAt": "2025-01-01T00:00:15Z" |
| 86 | + } |
| 87 | + ], |
| 88 | + "commonLabels": { |
| 89 | + "alertname": "oncall-smoke-delay15", |
| 90 | + "severity": "warning", |
| 91 | + "cluster": "prod", |
| 92 | + "namespace": "monitoring", |
| 93 | + "instance": "51.158.67.237:9100" |
| 94 | + }, |
| 95 | + "commonAnnotations": { |
| 96 | + "summary": "OnCall Discord smoke test", |
| 97 | + "description": "Expect one Discord message that updates on resolve" |
| 98 | + }, |
| 99 | + "version": "4" |
| 100 | +} |
| 101 | +EOF |
| 102 | +curl -sS -XPOST -H "Content-Type: application/json" -d @/tmp/firing.json "$warning" |
| 103 | +sleep 15 |
| 104 | +curl -sS -XPOST -H "Content-Type: application/json" -d @/tmp/resolved.json "$warning" |
| 105 | +' |
| 106 | +``` |
| 107 | + |
| 108 | +Expected: |
| 109 | +- Exactly one Discord message in `#alerts-warning` with the `@OnCall` mention. |
| 110 | +- The message is edited in-place on resolve (no second message). |
| 111 | +- The title links to the OnCall alert group. |
| 112 | + |
| 113 | +## Logs |
| 114 | +- Discord proxy: `k3s kubectl -n monitoring-oncall logs deploy/oncall-discord-proxy --tail=200` |
| 115 | +- OnCall engine: `k3s kubectl -n monitoring-oncall logs deploy/oncall-engine --tail=200` |
| 116 | +- Alertmanager: `k3s kubectl -n monitoring logs sts/alertmanager-monitoring-kube-prometheus-alertmanager --tail=200` |
0 commit comments