feat(observability): integrate Loki for centralised log aggregation (BIT-14248)

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]>
This commit is contained in:
David SantosandClaude Sonnet 4.6 committed 2026-04-27 08:03:20 +00:00
1 parent 94d2d12c97
commit 8bb49ce32b
7 files changed
+929

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
# Loki configuration for errors.bitreport.pt log aggregation.
# Docs: docs/OBSERVABILITY_LOKI.md
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
log_level: warn
common:
instance_addr: 127.0.0.1
path_prefix: /loki
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100
schema_config:
configs:
- from: 2024-01-01
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
ruler:
alertmanager_url: http://localhost:9093
limits_config:
retention_period: 30d
ingestion_rate_mb: 4
ingestion_burst_size_mb: 8
max_cache_freshness_per_query: 10m
reject_old_samples: true
reject_old_samples_max_age: 168h
compactor:
working_directory: /loki/compactor
retention_enabled: true
retention_delete_delay: 2h
retention_delete_worker_count: 150
delete_request_store: filesystem
+82
View File
@@ -0,0 +1,82 @@
# 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