Centralised Logging with Grafana Loki

Label design, retention, query patterns and how to avoid rebuilding Elasticsearch costs with a log system meant to be cheap.

Published Mar 24, 2026Updated Aug 24, 20269 min read5 views
  • grafana
  • kubernetes
  • linux
  • observability

Loki indexes labels, not content

The cost model only works if label cardinality stays low. Labels select streams; the log line content is searched by brute force over the selected streams.

  • Good labels: cluster, namespace, app, level, environment.

  • Bad labels: request_id, user_id, pod IP, trace ID, timestamp.

A Promtail / Alloy scrape config

YAML
scrape_configs:
  - job_name: kubernetes-pods
    kubernetes_sd_configs: [{ role: pod }]
    relabel_configs:
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
      - source_labels: [__meta_kubernetes_pod_label_app]
        target_label: app
      - action: labeldrop
        regex: __meta_kubernetes_pod_annotation_.*

Queries that stay fast

text
{namespace="payments", app="api"} |= "level=error" | logfmt | duration > 2s

sum by (app) (
  rate({namespace="payments"} |= "level=error" [5m])
)

Retention and storage

Store chunks in object storage with a lifecycle policy. Two tiers work well: 14 days queryable at full fidelity, and a longer compliance tier that is retrievable but not routinely queried.

Correlate, do not duplicate

  • Metrics answer 'is it broken and how badly'.

  • Logs answer 'what exactly happened to this request'.

  • Traces answer 'where did the time go'.

  • Link them with a shared trace ID in the log line body — not as a label.

Back to all docs