ELK Logging: Pipelines, ILM & Log Hygiene
Centralize structured JSON logs with Filebeat/Fluent Bit, Elasticsearch data streams, Index Lifecycle Management (ILM), KQL queries, and PII redaction.
TL;DR
Emit structured JSON to stdout, ship with a lightweight collector (Filebeat or Fluent Bit), parse/redact in an ingest pipeline, and store in Elasticsearch data streams managed by ILM (hot → warm → cold → delete). Correlate every log with trace_id and request_id, and mask PII/tokens before they ever hit disk.
Pipeline & KQL quick reference
app (JSON stdout) ─► Filebeat / Fluent Bit ─► Ingest Pipeline (enrich + redact) ─► Elasticsearch Data Stream (ILM) ─► KibanaUseful KQL queries in Kibana Discover:
service.name: "payment-service" and http.response.status_code >= 500
trace_id: "4bf92f3577b34da6a3ce929d0e0e4736"
log.level: "error" and not error.type: "ValidationError"
http.response.status_code: 504 and event.duration > 5000000000ILM & retention tiers
- Hot: Active writes on fast SSD/NVMe; rollover at size/age threshold (e.g.
50GBor1d) so shards stay 20–50 GB. - Warm / Cold: Read-only, force-merged, moved to cheaper spinning/object-backed nodes for compliance retention.
- Delete: Automatically purge indices after your retention policy expires (separate shorter retention for debug/access logs vs audit logs).
Gotchas
- Dynamic mapping explosions: Logging arbitrary user payloads or dynamic map keys at the top level creates thousands of index fields, bloating cluster state across every node.
- Tiny shard sprawl: Creating daily indices for low-volume services leaves thousands of 5 MB shards; use data streams with size-based rollover (
max_primary_shard_size: 30gb). - Logging secrets or PII: Once a bearer token or PAN enters Elasticsearch, it is replicated across shards and snapshots; redact at the app logger and drop/mask in ingest pipelines.
Production checklist
- Apps log single-line JSON to
stdoutwithtimestamp,level,service,trace_id, andrequest_id. - Ingest pipeline or collector redacts
Authorization, cookies, passwords, and PII patterns. - Data streams use ILM policies with size-based rollover (avoiding per-day tiny shards).
- Security/audit logs sit in a separate append-only index/stream with longer retention than noisy debug logs.
Check yourself
Check Yourself
1. Why should Elasticsearch data streams roll over based on shard size (e.g. 30–50 GB) rather than strictly creating a new index every hour or day for every service?
2. What causes an Elasticsearch mapping explosion?
Sources
Prometheus & Grafana Cheatsheet
Essential PromQL queries, metric types (Counter, Gauge, Histogram), cardinality traps, relabeling order, and SLO burn-rate alerting.
DevSecOps Pipeline: Automated Gates from Commit to Admission
How automated security gates—pre-commit secret scanning, SAST, SCA, IaC checks, Trivy, Cosign signing, and Kyverno admission—protect production without manual bottlenecks.