Skip to content

[INFRA] Centralized log aggregation with Grafana Loki and Promtail #999

Description

@KingFRANKHOOD

Repo Avatar
KingFRANKHOOD/Amana

Feature Description
Deploy a Grafana Loki + Promtail stack for centralized log aggregation across all services (backend, frontend, contracts event listener, PostgreSQL, Redis). Replace ad-hoc docker logs and kubectl logs with structured, searchable, and alertable logging.

Problem Statement
Currently, debugging production issues requires SSH-ing into pods/containers and running docker logs or kubectl logs. There is no centralized log search, no log-based alerting, and no way to correlate logs across services. Pino logs are structured JSON but sit on individual instances.

Proposed Solution

  • Add Loki + Promtail to docker-compose.yml staging profile:
    loki:
      image: grafana/loki:3.0
      ports: ["3100:3100"]
    promtail:
      image: grafana/promtail:3.0
      volumes: ["/var/log:/var/log", "/var/lib/docker/containers:/var/lib/docker/containers"]
  • For K8s: deploy Loki via Helm chart (grafana/loki-stack) with S3 storage backend
  • Promtail config:
    • Scrape Docker container logs (JSON file driver)
    • Parse Pino-structured JSON: extract level, service, trace_id, trade_id, error_code as labels
    • Add compose_service label for service discovery
  • Grafana datasource: add Loki, create "Logs" explore view
  • Log-based alerting (via Loki Ruler):
    • rate({service="backend"} | json | level="error" [5m]) > 10 → warning
    • rate({service="backend"} | json | error_code="DB_CONNECTION_FAILED" [5m]) > 0 → critical
    • rate({service="backend"} | json | level="fatal" [5m]) > 0 → critical
  • Retention: 30 days (Loki), cold storage after 7 days

Alternatives Considered

  1. ELK stack (Elasticsearch, Logstash, Kibana) — heavier, more resource-intensive than Loki
  2. Datadog/Splunk — paid SaaS; not suitable for OSS self-hosted deployment

Impact Area

  • Infrastructure
  • Observability

Priority
P2 - Medium

Implementation Complexity
Moderate

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programdifficulty:mediumModerate implementation complexityenhancementNew feature or requestinfrastructureDocker, CI, environment configp2Priority 2 - Medium

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions