BM: Baca dalam Bahasa Melayu
World O4: The Diary & One Order
Loki and LogQL basics
You will learn: to pick a diary by its labels and filter its lines with LogQL.
Checked with Prometheus 3 on 1 Nov 2026
The problem
Five services keep five diaries, on five machines. A payment timed out somewhere. Where do you start?
Pick one answer.
Watch
Loki: Grafana's log store. It indexes only the labels of each diary, not every word, so it stays small and cheap. keeps every diary on one shelf. It indexes only the labels, like app. Not every word.
Try it
Ask for kedai-api’s lines that contain “timeout”. Tap the pieces in order.
Tap the pieces in the right order.
Hint
Braces first: they pick the diary. Then the filter.Predict
Which lines does {app="kedai-api"} | json | level="error" return?
0 of 1 found
LogQL: Loki's query language. Pick diaries by label in braces, then filter lines: {app="kedai-api"} |= "timeout". reads like a pipe. | json turns fields into labels. Then you can filter on them.
Check
Real Loki 3.7 agrees: one line, two ways to ask. Notice its trace_id. You will need it soon.
Check
parse error : queries require at least one regexp or equality matcher that does not have an empty-compatible value. For instance, app=~".*" does not meet this requirement, but app=~".+" willYou asked for {app=~".*"}: “every diary”. Loki refused. Which fix works?
Pick one answer.
You did it!
You can now pick diaries by label and filter their lines with LogQL.
Go deeper (optional)
LogQL can count too: sum by (app) (count_over_time({app=~"kedai-.*"} | json | level=~"error|warn" [10m])) counts problem lines per app. Keep labels few and fixed, like app. Never put order_id in a label: each value makes a new log stream: One diary in Loki: all lines with the same set of labels. Too many label values make too many diaries..
Real mission
docker network create logs-trydocker run -d --name loki-try --network logs-try -p 3100:3100 grafana/loki:3.7.9curl -s -H "Content-Type: application/json" -X POST http://localhost:3100/loki/api/v1/push --data-raw "{\"streams\":[{\"stream\":{\"app\":\"try\"},\"values\":[[\"$(date +%s)000000000\",\"hello loki\"]]}]}"docker run --rm --network logs-try grafana/logcli:3.7.9 --addr=http://loki-try:3100 query --quiet '{app="try"}'docker rm -f loki-try && docker network rm logs-try
0 of 5 steps done · Your ticks are saved.
Bahasa Melayu
Lima servis simpan lima diari, di lima mesin. Satu bayaran tamat masa entah di mana. Nak mula dari mana?
Loki simpan setiap diari di satu rak. Ia indeks label sahaja, contohnya app. Bukan setiap perkataan.
Minta baris kedai-api yang ada “timeout”. Ketik kepingan mengikut urutan.
LogQL dibaca macam paip. | json tukar medan jadi label. Kemudian anda boleh tapis padanya.
Loki 3.7 sebenar setuju: satu baris, dua cara bertanya. Perhatikan trace_idnya. Anda akan perlukannya nanti.
parse error : queries require at least one regexp or equality matcher that does not have an empty-compatible value. For instance, app=~".*" does not meet this requirement, but app=~".+" willAnda minta {app=~".*"}: “semua diari”. Loki tolak. Pembetulan mana yang berfungsi?
Kini anda boleh pilih diari ikut label dan tapis barisnya dengan LogQL.
You finished this before. Practice is always welcome!
Official docs: Loki overview · LogQL: log queries · LogQL: metric queries · logcli
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?