Adds Grafana Loki + Promtail to the Docker Compose observability profile, enabling structured-log collection from all errors.bitreport.pt services. - deploy/loki/loki.yaml: Loki server (filesystem storage, TSDB v13, 30-day retention) - deploy/loki/promtail.yaml: Docker SD auto-discovery, JSON parse, Pino level normalisation - deploy/grafana/loki-logs-dashboard.json: Grafana log dashboard (uid er-loki-logs) - docs/OBSERVABILITY_LOKI.md: setup, key LogQL queries, troubleshooting runbook - docker-compose.yml: loki + promtail services under --profile observability; LOG_LEVEL env - .env.example / ingest-api/.env.example: LOG_LEVEL + ER_PUBLISH_LOKI_PORT documented Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
83 lines
3.0 KiB
YAML
83 lines
3.0 KiB
YAML
# Promtail configuration for errors.bitreport.pt log shipping.
|
|
# Discovers Docker containers by compose service name, parses structured JSON logs,
|
|
# and ships to the Loki instance in the same Docker network.
|
|
# Docs: docs/OBSERVABILITY_LOKI.md
|
|
|
|
server:
|
|
http_listen_port: 9080
|
|
grpc_listen_port: 0
|
|
log_level: warn
|
|
|
|
positions:
|
|
filename: /run/promtail/positions.yaml
|
|
|
|
clients:
|
|
- url: http://loki:3100/loki/api/v1/push
|
|
backoff_config:
|
|
min_period: 500ms
|
|
max_period: 5m
|
|
max_retries: 10
|
|
|
|
scrape_configs:
|
|
# --- errors-hub services (Docker Compose auto-discovery) ---
|
|
- job_name: errors-hub-docker
|
|
docker_sd_configs:
|
|
- host: unix:///var/run/docker.sock
|
|
refresh_interval: 10s
|
|
filters:
|
|
# Only scrape containers that belong to this compose project.
|
|
- name: label
|
|
values: ["com.docker.compose.project=errors-bitreport-pt"]
|
|
|
|
relabel_configs:
|
|
# Map compose service name → `service` label
|
|
- source_labels: [__meta_docker_container_label_com_docker_compose_service]
|
|
target_label: service
|
|
# Compose project → `compose_project`
|
|
- source_labels: [__meta_docker_container_label_com_docker_compose_project]
|
|
target_label: compose_project
|
|
# Container name for uniqueness
|
|
- source_labels: [__meta_docker_container_name]
|
|
regex: "/(.*)"
|
|
target_label: container
|
|
# Static labels for every log line from this hub
|
|
- replacement: errors-hub
|
|
target_label: app
|
|
- replacement: production
|
|
target_label: env
|
|
|
|
pipeline_stages:
|
|
# ── Attempt JSON parse ──────────────────────────────────────────────
|
|
- json:
|
|
expressions:
|
|
# Pino uses a numeric `level` (30=info, 40=warn, 50=error)
|
|
# Collector-worker uses a string `level` ("info"/"warn"/"error")
|
|
pino_level: level
|
|
log_msg: msg
|
|
log_err: err
|
|
log_pid: pid
|
|
|
|
# ── Normalize Pino numeric levels to strings ────────────────────────
|
|
# Pino: 10=trace 20=debug 30=info 40=warn 50=error 60=fatal
|
|
- template:
|
|
source: pino_level
|
|
template: |
|
|
{{ if eq .Value "10" }}trace
|
|
{{- else if eq .Value "20" }}debug
|
|
{{- else if eq .Value "30" }}info
|
|
{{- else if eq .Value "40" }}warn
|
|
{{- else if eq .Value "50" }}error
|
|
{{- else if eq .Value "60" }}fatal
|
|
{{- else }}{{ .Value }}
|
|
{{- end }}
|
|
|
|
# Promote the normalized level to a Loki label (low-cardinality)
|
|
- labels:
|
|
level: pino_level
|
|
|
|
# ── Drop noisy debug/trace in production ────────────────────────────
|
|
- match:
|
|
selector: '{level=~"trace|debug"}'
|
|
action: drop
|
|
drop_counter_reason: below_min_level
|