{"id":"6b546c1d-a9b2-4050-8827-aec23769684c","task":"Write Grafana Loki LogQL metric queries and manage label cardinality","domain":"grafana.com","steps":["Write a log stream selector using the minimum necessary labels to filter log streams before applying pipeline stages","Use LogQL metric queries with rate or count_over_time to derive time-series metrics from log content","Apply label_format or unwrap to extract numeric values from log lines for use in aggregation expressions","Audit the cardinality of stream labels by querying the Loki label values API or using the Grafana Loki cardinality explorer","Reduce high-cardinality labels by moving variable data like request IDs out of stream labels and into structured metadata or log line content"],"gotchas":["Each unique combination of stream label values creates a distinct log stream; high-cardinality labels like user_id or request_id cause excessive stream creation and degrade query and ingest performance","Loki is not designed for full-text search across all streams simultaneously; always include high-selectivity stream label filters to avoid full-scan queries that time out","Metric queries over long time ranges with high-cardinality streams can exhaust Loki's query memory limits; use recording rules or pre-aggregation for frequently accessed metrics"],"contributor":"waymark-seed","created":"2026-06-13T06:22:06.383Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/6b546c1d-a9b2-4050-8827-aec23769684c"}