feat(obs): add Loki ruler alert rules and MONITORING.md Loki section (BIT-19957)
- deploy/loki/rules/fake/errors_hub_alerts.yaml: four LogQL-based Loki ruler alert rules (error rate per service, fatal detection, ingest-api sustained errors, collector-worker stall detection) - deploy/loki/loki.yaml: add explicit ruler.storage (local), rule_path, and enable_api/enable_alertmanager_v2 so Loki loads rules from /loki/rules - docker-compose.yml: mount deploy/loki/rules → /loki/rules:ro in the loki service (observability profile) - docs/MONITORING.md: add Loki section with label table, alert rule summary, config file index, and LXC deployment note Paperclip-Issue: BIT-19957 Paperclip-Agent: cto
This commit is contained in:
1 parent
c74e05b844
commit
113eee0b97
4 files changed
+142
No files matched your search
@@ -39,6 +39,13 @@ schema_config:
|
||||
|
||||
ruler:
|
||||
alertmanager_url: http://localhost:9093
|
||||
storage:
|
||||
type: local
|
||||
local:
|
||||
directory: /loki/rules
|
||||
rule_path: /tmp/loki-ruler-tmp
|
||||
enable_api: true
|
||||
enable_alertmanager_v2: true
|
||||
|
||||
limits_config:
|
||||
retention_period: 30d
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
# Loki ruler alert rules — errors.bitreport.pt (errors-hub)
|
||||
# Tenant: fake (auth_enabled: false single-binary)
|
||||
# Labels app="errors-hub", env="production" are set by promtail (both Docker and LXC configs).
|
||||
# Service label values: ingest-api, api, collector-worker, admin-ui, web
|
||||
# Docs: docs/OBSERVABILITY_LOKI.md
|
||||
|
||||
groups:
|
||||
- name: errors_hub_log_alerts
|
||||
interval: 1m
|
||||
rules:
|
||||
# ── Error rate per service ─────────────────────────────────────────────
|
||||
- alert: ErrorsHubServiceErrorRateHigh
|
||||
expr: |
|
||||
sum by (service) (
|
||||
rate({app="errors-hub", level="error"}[5m])
|
||||
) > 0.1
|
||||
for: 5m
|
||||
labels:
|
||||
severity: warning
|
||||
team: observability
|
||||
app: errors-hub
|
||||
annotations:
|
||||
summary: "High error log rate on {{ $labels.service }}"
|
||||
description: >
|
||||
Service {{ $labels.service }} is emitting error-level logs at
|
||||
{{ $value | printf "%.2f" }} lines/s (threshold 0.1/s, 5m window).
|
||||
Check service health; run: docker compose logs {{ $labels.service }} --tail=100
|
||||
|
||||
# ── Fatal log detected ─────────────────────────────────────────────────
|
||||
- alert: ErrorsHubFatalLogDetected
|
||||
expr: |
|
||||
sum by (service) (
|
||||
rate({app="errors-hub", level="fatal"}[5m])
|
||||
) > 0
|
||||
for: 1m
|
||||
labels:
|
||||
severity: critical
|
||||
team: observability
|
||||
app: errors-hub
|
||||
annotations:
|
||||
summary: "Fatal log in {{ $labels.service }}"
|
||||
description: >
|
||||
Service {{ $labels.service }} emitted at least one fatal-level log
|
||||
in the last 5 minutes. Immediate investigation required.
|
||||
Query: {app="errors-hub", service="{{ $labels.service }}", level="fatal"}
|
||||
|
||||
# ── Ingest API sustained error rate ───────────────────────────────────
|
||||
- alert: ErrorsHubIngestApiHighErrorRate
|
||||
expr: |
|
||||
rate({app="errors-hub", service="ingest-api", level="error"}[10m]) > 0.05
|
||||
for: 10m
|
||||
labels:
|
||||
severity: critical
|
||||
team: observability
|
||||
app: errors-hub
|
||||
annotations:
|
||||
summary: "ingest-api sustained error rate (>0.05/s for 10m)"
|
||||
description: >
|
||||
ingest-api is logging errors at {{ $value | printf "%.3f" }} lines/s
|
||||
for 10+ minutes. This may indicate DB connection issues, schema errors,
|
||||
or upstream pressure. Check: {service="ingest-api", level="error"} | json
|
||||
|
||||
# ── Collector worker stalled ───────────────────────────────────────────
|
||||
- alert: ErrorsHubCollectorWorkerStalled
|
||||
expr: |
|
||||
sum(
|
||||
rate({app="errors-hub", service="collector-worker"}[10m])
|
||||
) == 0
|
||||
for: 15m
|
||||
labels:
|
||||
severity: warning
|
||||
team: observability
|
||||
app: errors-hub
|
||||
annotations:
|
||||
summary: "collector-worker has no log output for 15m"
|
||||
description: >
|
||||
collector-worker emitted zero log lines over the last 10m window for
|
||||
15+ minutes. The service may be stopped or stuck in a silent loop.
|
||||
Check: docker compose ps collector-worker; systemctl status bitreport-error-reporting-collector-worker
|
||||
@@ -148,6 +148,7 @@ services:
|
||||
volumes:
|
||||
- ./deploy/loki/loki.yaml:/etc/loki/loki.yaml:ro
|
||||
- loki-data:/loki
|
||||
- ./deploy/loki/rules:/loki/rules:ro
|
||||
ports:
|
||||
- "${ER_PUBLISH_LOKI_PORT:-3100}:3100"
|
||||
healthcheck:
|
||||
|
||||
@@ -24,3 +24,58 @@ Company standards for signals (logs, metrics, tracing, alerting) are summarized
|
||||
| Grafana dashboard JSON (import into your Grafana) | [`../deploy/grafana/error-monitoring-dashboard.json`](../deploy/grafana/error-monitoring-dashboard.json) |
|
||||
|
||||
Scrape **both** the hub API and the ingest API; see `OBSERVABILITY_PROMETHEUS.md` for paths and metric families.
|
||||
|
||||
---
|
||||
|
||||
## Log aggregation (Loki)
|
||||
|
||||
| Topic | Location |
|
||||
|-------|----------|
|
||||
| Architecture, labels, LogQL queries, troubleshooting | [`OBSERVABILITY_LOKI.md`](OBSERVABILITY_LOKI.md) |
|
||||
| Loki server config (schema, retention, ruler) | [`../deploy/loki/loki.yaml`](../deploy/loki/loki.yaml) |
|
||||
| Promtail config — Docker Compose lab | [`../deploy/loki/promtail.yaml`](../deploy/loki/promtail.yaml) |
|
||||
| Promtail config — LXC / production | [`../deploy/loki/promtail-lxc.yaml`](../deploy/loki/promtail-lxc.yaml) |
|
||||
| Promtail systemd unit (LXC) | [`../deploy/loki/systemd/promtail.service`](../deploy/loki/systemd/promtail.service) |
|
||||
| Grafana log dashboard | [`../deploy/grafana/loki-logs-dashboard.json`](../deploy/grafana/loki-logs-dashboard.json) |
|
||||
| Loki ruler alert rules | [`../deploy/loki/rules/fake/errors_hub_alerts.yaml`](../deploy/loki/rules/fake/errors_hub_alerts.yaml) |
|
||||
| LXC operational runbook | [`deployment/loki-lxc-runbook.md`](deployment/loki-lxc-runbook.md) |
|
||||
|
||||
### Labels
|
||||
|
||||
Every log line from errors-hub carries these Loki labels:
|
||||
|
||||
| Label | Values |
|
||||
|-------|--------|
|
||||
| `app` | `errors-hub` (static) |
|
||||
| `env` | `production` (static) |
|
||||
| `service` | `ingest-api`, `api`, `collector-worker`, `admin-ui`, `web` |
|
||||
| `level` | `info`, `warn`, `error`, `fatal` (normalised from Pino numeric levels) |
|
||||
|
||||
Labels are consistent across Docker Compose (Docker SD) and LXC (journald) deployments.
|
||||
`trace` and `debug` lines are dropped by Promtail in both configs.
|
||||
|
||||
### Starting the observability stack
|
||||
|
||||
```bash
|
||||
# Docker Compose (lab) — core services + Loki + Promtail
|
||||
docker compose --profile observability up -d
|
||||
|
||||
# Verify log ingestion
|
||||
curl -s 'http://localhost:3100/loki/api/v1/labels'
|
||||
```
|
||||
|
||||
### Alert rules (Loki ruler)
|
||||
|
||||
Rules live in `deploy/loki/rules/fake/errors_hub_alerts.yaml` and are evaluated by the Loki ruler component.
|
||||
|
||||
| Alert | Condition | Severity |
|
||||
|-------|-----------|----------|
|
||||
| `ErrorsHubServiceErrorRateHigh` | Any service >0.1 error lines/s for 5m | warning |
|
||||
| `ErrorsHubFatalLogDetected` | Any fatal line in any service for 1m | critical |
|
||||
| `ErrorsHubIngestApiHighErrorRate` | ingest-api >0.05 error lines/s for 10m | critical |
|
||||
| `ErrorsHubCollectorWorkerStalled` | collector-worker silent for 15m | warning |
|
||||
|
||||
Alerts route to Alertmanager (`ruler.alertmanager_url` in `deploy/loki/loki.yaml`).
|
||||
For production LXC: point `alertmanager_url` to the central Alertmanager (`http://<observability-ct>:9093`).
|
||||
|
||||
For production LXC deployment, copy `deploy/loki/rules/` to `/loki/rules/` on the Loki LXC; see [`deployment/loki-lxc-runbook.md`](deployment/loki-lxc-runbook.md).
|
||||
Reference in new issue
Block a user