DevOps · Observability

Grafana Loki Log Aggregation

Loki takes a deliberately different approach to log aggregation — index only labels, not the full text — which makes it cheaper to run, with trade-offs worth understanding before you adopt it.

John Kihiu12 min read

Grafana Loki is a log aggregation system built around one central design decision: unlike search-heavy stacks that fully index every log line, Loki indexes only a small set of labels and stores the log content compressed and unindexed. This makes it markedly cheaper and simpler to operate at scale — and it shapes how you query it. Understanding that trade-off is the key to knowing whether Loki fits your needs.

Index labels, not content

Traditional log stacks index the full text of every log, which makes arbitrary full-text search fast but is expensive in storage and compute — the index can dwarf the logs themselves. Loki indexes only labels (metadata like service, environment, level) and keeps the actual log content compressed. The result is far lower storage and operational cost, at the price of not having a full-text index. It is a deliberate bet that most log queries start by narrowing on labels.

How you query with LogQL

Loki's query language, LogQL, reflects the design: you first select a stream by its labels, then filter the content within that stream. Because you narrow by label first and search text second, queries are efficient when your labels are well-chosen and can be slow if you try to search broadly across everything without label filters. This makes label design the most important thing you do in Loki — good labels make it fast and cheap; poor labelling undermines the whole model.

When Loki fits

Loki suits teams that want cost-effective, scalable log aggregation and whose queries naturally start from labels — which most operational debugging does ("show me errors from this service in this environment"). It is especially attractive if you already use Grafana and Prometheus, because it shares that ecosystem and label-based mental model, giving you metrics and logs in one pane. It is a weaker fit if you genuinely need fast arbitrary full-text search across all logs, where a fully-indexed stack still wins.

Label cardinality is the thing to get right

Loki's efficiency depends on sensible labels, and its classic pitfall is high-cardinality labels — putting something like a user id or request id in a label, which explodes the number of streams and degrades performance. Keep labels low-cardinality (service, environment, level) and put high-cardinality identifiers in the log content, queried by filter. Getting cardinality wrong is the fastest way to make Loki slow and expensive, defeating its whole purpose.

Grafana Loki aggregates logs cost-effectively by indexing only labels and leaving content unindexed, queried with LogQL that narrows by label before filtering text. That design makes it cheaper and simpler than full-text stacks, fits label-oriented operational debugging well, and pairs naturally with Grafana and Prometheus. Adopt it where its model fits your queries, keep label cardinality low, and reserve fully-indexed alternatives for when true arbitrary full-text search is the requirement.

John Kihiu
Acumatica ERP Developer · Laravel Engineer

Independent software engineer in Nairobi specialising in Acumatica customisations, Laravel backends, and tax fiscalisation integrations across East and Southern Africa.