Skip to content

Loki Returns Nothing, Queries Time Out, or the Disk Fills Up — A Troubleshooting Decision Tree

Loki bills itself as Prometheus for logs, but the ways it breaks are quite different. I have seen four symptoms dominate, and each one belongs to a different segment of the pipeline. Split them first and every command after gets shorter.

Four symptoms, four segments:

Symptom Segment First command
Nothing (logcli returns empty) collector down / label mismatch /loki/api/v1/labels
Partial (some hours or apps missing) glob miss / incomplete chunks collector positions
Slow or timeout label cardinality / time range / chunk fetch narrow the range and retry
Disk alarm every day retention / compactor missing /loki/api/v1/status/buildinfo

Segment one: nothing found — distinguish "zero lines" from "wrong matcher"

curl -s http://localhost:3100/ready
curl -s http://localhost:3100/loki/api/v1/labels
curl -s http://localhost:3100/loki/api/v1/label/job/values
logcli query '{job="app"}' --limit=10 --since=1h

Labels entirely empty goes to segment two, the collector. Labels present but query empty means the matcher is wrong, and three traps cover almost every case.

Trap one: the matcher must be exact. LogQL's {job="app"} is an exact stream-label match, not a fuzzy one. {job="application"} and {job="App"} match no stream at all and, worse, return empty silently with no error. Copy label names and values from the output of /labels and /label/job/values rather than typing them.

Trap two: do not put high-cardinality fields into stream labels. Teams routinely promote trace_id, user_id, or a raw path into a stream label, and one application splinters into hundreds of thousands of streams. The query then matches a different set of streams than you expect and the result looks incomplete. Stream labels belong to low-cardinality enums such as level, env, and service; high-cardinality fields go through a line filter like |= "trace_id" or structured metadata.

Trap three: the time range. logcli's default window is not the one you picked in Grafana. --since=24h is how you pull yesterday's logs.

Segment two: the file exists on disk but Loki never sees it

This is the collector segment, and the chain is application writes to file, the collector tails it, pushes, and Loki ingests. Verify each link in order:

tail -f /var/log/app/app.log
curl -s -o /dev/null -w "%{http_code}" http://localhost:9080/ready
cat /var/lib/promtail/positions.yaml | grep app.log
journalctl -u promtail --since "10min" | grep -Ei "error|permission|denied"

The three most common breakpoints:

  1. The positions file has no entry for your file, which means the path glob does not cover it. Globs do not recurse by default, so /var/log/*.log never picks up /var/log/subdir/. Use /var/log/**/*.log.
  2. SELinux blocks the tail. A permission denied shows up in the collector log, and ausearch -m avc -ts recent | grep promtail shows the denial record.
  3. In Kubernetes the positions directory lives inside the container, so every pod recreation restarts from zero and gets truncated by retention. Confirm the DaemonSet mounts positions on a hostPath.

I once had an application and the collector in the same pod where path pointed at a host path that does not exist inside the container. The collector logged "no files matched" on every start with exit code zero, nobody noticed, and logging was dark for three days. So the order in this segment is always: file exists, tail process is following it, positions file lists it. Do not skip ahead.

Segment three: slow or timing out

Three root causes, cheapest to dearest:

logcli query '{job="app"}' --since=30m
curl -s http://localhost:3100/loki/api/v1/labels | head
curl -s http://localhost:3100/loki/api/v1/status/metrics | grep -E "streams|chunks"
logcli query '{job="app"}' --limit=100 --since=6h --verbose
  • Range too wide. Loki has no full-text index, so a wider window means more chunks scanned. Shrink to thirty minutes first, then widen.
  • Cardinality exploded. A streams metric in the hundreds of thousands means too many labels; go back to trap two in segment two. The real fix is deleting the high-cardinality label so one application collapses into a handful of streams.
  • Chunks fetched from object storage. Verbose output full of GET requests to an object store means cold data is on S3 and every query pays the round trip. Either accept it or shorten local retention and tune the compactor.

The same logic applies inside Grafana: when one panel hangs, cut the time range to fifteen minutes and add a line filter such as |= "keyword", and you can almost always tell a range problem from a cardinality problem in one try.

Segment four: the disk alarm every day — retention is the real fix

Loki does not delete old data unless you explicitly configure retention, so the disk only ever grows. Three settings must go together:

schema_config:
  configs:
    - from: 2024-01-01
      store: tsdb
      object_store: filesystem
      schema: v13
      index:
        prefix: index_
        period: 24h
limits_config:
  retention_period: 168h
  retention_delete_worker_count: 150
compactor:
  working_directory: /loki/wal
  compaction_interval: 10m
  retention_enabled: true
  retention_delete_delay: 2h

Three points:

  1. retention_enabled and retention_period must both be set; the period without the compactor does nothing.
  2. Keep retention_delete_delay at two hours so the logs you are about to query are not deleted mid-query.
  3. Put the compactor working directory and index on local disk or object storage so the compactor cannot fill the disk it is cleaning.

Verify:

curl -s http://localhost:3100/loki/api/v1/status/buildinfo | grep -i retention
du -sh /loki/chunks && df -h /loki
watch -n 60 'du -sh /loki/chunks'

One hidden item: the write-ahead log. The WAL is not part of normal queries, but if a query window lands on the WAL boundary or the WAL is sized to eat the disk, the alarm fires faster than chunks grow. Read max_query_lookback and the WAL size together.

A single card

Symptom Segment One check
logcli entirely empty labels empty curl /loki/api/v1/labels
Labels exist, query empty matcher wrong copy a value from /label/job/values
File exists, Loki does not have it collector grep the file name in positions.yaml
Glob misses subdirectories collector change path to **/*.log
Query times out range too wide retry with --since=30m
Query is slow cardinality a streams metric in the hundreds of thousands means too many labels
Slow and hits S3 chunk fetch watch for object-store GETs in --verbose
Disk alarm retention missing retention_enabled plus retention_period
Compactor never reclaims partial config are both fields present

One question I ask before touching anything

Before I start I ask: "Is there zero, or is a piece missing?" Zero lines means the collector or the matcher is wrong about nine times out of ten, and query performance is not even in the picture. A piece missing means I narrow by time or application, and the cause is almost always a glob that missed a directory, a pod that was never reattached, or an incomplete chunk. Get the direction right and every command afterwards tests one hypothesis instead of flailing.

Beyond troubleshooting: one habit I keep reminding myself of

Loki's traps differ from Prometheus's. Prometheus usually fails at scraping; Loki usually fails at label design. So I run a label health check on every investigation: list every label name, pull out the high-cardinality ones such as trace_id, user_id, path, and pod_uid, and demote every one of them out of stream labels into a line filter or structured metadata. Even when the current incident is not caused by labels, that pass removes the single biggest latent risk.

There is one more lesson: a slow query and a full disk are often the same root cause. Too many labels fragment the stream set, every small chunk stores duplicate metadata, and that both slows queries and eats the disk. When both symptoms show up together, do not treat them separately; fix the label design once and both usually clear.

Changing label design is a migration, not a config edit

I keep saying label design is the root cause, but the moment you actually change it is where people ship the worst outages, because changing a stream label is a data migration, not a config edit. Loki organizes chunks by stream (the label set), so the instant you touch any stream label, every chunk stored under the old labels stops matching your new queries — old logs go missing, dashboards go dark, and it looks like "Loki is broken" when you actually cut your own streams.

So I change labels in three steps and never in one shot:

  1. Add first, never delete. To demote trace_id out of stream labels, first add the new path — a |= line filter or structured metadata — so new logs flow through both routes while the old label is still in place. Both old and new queries keep matching; nothing breaks.
  2. Leave an observation window before removing the old one. Once the new path has run stably for a full retention cycle (I use seven days) and I have confirmed no old query still relies on trace_id as a stream label, only then do I drop the label from promtail. Before I drop it I re-check it against /loki/api/v1/labels.
  3. Change one label at a time and watch the streams metric after each. Batch changes interfere with each other and make it impossible to say which label caused a regression. After each change I watch the streams count in /status/metrics collapse as expected (it should fall clearly once a high-cardinality label is gone) and confirm harmless before the next one.

One blood-and-tears lesson: after you change a label in promtail, the positions file does not reset just because the label changed — it only tracks file offsets. So old files do not get re-read because the label moved. If you expect "change the label and history logs auto-move to the new stream," you are wrong: the old chunks stay under the old labels forever, and only new logs take the new ones. To truly normalize, you rebuild the index or let the data age out of retention on its own.