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
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
{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.