Loki — Intermediate
Advanced LogQL — unwrap, top-K, and percentile queries
Beyond basic label selection and text filtering, LogQL's real power for operational work is turning log content into numeric aggregates without a separate metrics pipeline. unwrap is the key mechanism — it extracts a numeric field from a parsed log line and treats it as a value to aggregate, rather than just counting matching lines:
The practical value here: a service that never explicitly emitted a request_duration_seconds metric can still get a real p99 latency figure, as long as it logs duration as a structured field — unwrap plus quantile_over_time derives the metric after the fact from logs that were already being written for other reasons.
Running Loki in Kubernetes
The loki-stack Helm chart bundles Loki, Promtail, and Grafana together — the fastest path to a working setup for evaluation or a smaller deployment:
Kubernetes pod logs are picked up automatically once Promtail is running, with pod metadata already attached as labels without any additional configuration:
For production deployments at real scale, the distributed/microservices installation mode (covered in Advanced) is the better fit than this bundled single-chart approach — loki-stack is deliberately optimized for getting something running quickly, not for independently scaling ingestion versus query load.
Log retention and storage configuration
Retention needs two pieces configured together, not just one — a common early misconfiguration is setting retention_period alone and assuming that's sufficient:
max_streams_per_user is worth calling out specifically — it's a blunt but effective safety net against a label-cardinality mistake turning into a full Ingester OOM: once a tenant hits the cap, new streams are rejected rather than silently accepted, which surfaces a cardinality problem as an explicit error instead of a slow-building memory crisis.
Alerting directly from log content
Loki's Ruler evaluates LogQL metric queries on a schedule and can fire alerts through the same Alertmanager most teams already use for Prometheus — meaning log-based and metric-based alerting share one notification pipeline rather than needing two separate systems:
This is genuinely useful for exactly the class of problem that never had a metric emitted for it in the first place — a specific exception type, a business-logic error condition logged as text — without needing to add application code to also emit a corresponding Prometheus metric before it becomes alertable.

