log aggregation, the excessive costs of such systems has become more obvious. This cost arises not just from the technology used to implement full-text search — scaling and sharding an inverted index is hard; either writes touch each shard, or reads must — but also from the operation complexity. [ … ] One common use case for log aggregation systems is to store structured, event-based data — for instance emitting an event for every request to a system, and including all the request details and metadata. With these kind of deployments comes the ability to ask questions like “show me top 10 users with highest 99th percentile latency”, something that you typically cannot do with time series metrics system due to the high cardinality of users. Whilst this use case is totally valid, it is not something we are targeting with this system. Lokiはログ保存のコストと運用のしや すさを重視した設計を選択した。 全文検索や構造化ログへの対応はスコ ープ外として、ログを安く大量に貯め られるようにした。 2018-03 Loki Design Document
200 GET /orders 503 GET /orders 200 GET /cart 201 POST /cart → chunk 書き込み中 201 POST /orders ログ受付中 chunk クローズ済 200 GET /orders 201 POST /pay 200 GET /items chunk クローズ済 201 POST /pay 500 GET /items 200 GET /cart → オブジェクト ストレージ chunk 圧縮済 chunk 圧縮済 chunk 圧縮済
FROM orders api 503 GET /items db SELECT * FROM users ラベルで 振り分け ⇒ {app="api"} Chunk A 200 GET /orders 503 GET /items 200 GET /cart {app="db"} Chunk B SELECT * FROM orders SELECT * FROM users SELECT * FROM sessions
インデックスを 引く 2 → 参照をたどり チャンクを取得 オブジェクトストレージ ラベル → チャンクの場所 {app="api"} → chunk A, C INDEX {app="db"} → chunk B オブジェクトストレージ chunk A chunk C CHUNKS chunk B 対象外
GET /orders 500 POST /pay 5xxの行だけが返る 取得したチャンクだけを展開し、フィルタにマッチする行だけを返す。 chunk A 200 GET /orders 200 GET /cart 304 GET /static 200 POST /login 200 GET /orders 503 GET /orders 200 GET /cart 200 GET /items 200 GET /orders chunk C 200 GET /items 200 GET /orders 500 POST /pay 201 POST /pay 200 GET /cart 200 GET /orders 200 GET /items 200 GET /orders 200 GET /cart 取得したCHUNKS
… 200 alice …02 POST /pay … 500 bob …03 GET /items … 503 alice → 全行をスキャンするので重い 列指向 参照する列だけを読む ts …01 …02 …03 message GET /orders … POST /pay … GET /items … status 200 500 503 user alice bob alice → スキャン量が大幅に減る