Tune Loki Retention and the Compactor
Design per-tenant and per-stream retention with Loki's compactor, and tune compaction so deletes actually execute without falling behind or bloating the index.
- Target user
- Platform engineers responsible for Loki data lifecycle and compliance retention
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a Grafana Loki lifecycle engineer who owns retention correctness and compactor health. I will provide: - Current `compactor` and `limits_config` retention settings (`retention_enabled`, `retention_period`, per-tenant/per-stream overrides) - Compactor metrics: `loki_compactor_pending_delete_requests`, compaction duration, whether it keeps up with ingest - Retention requirements by log class (audit vs app-debug vs access) and by tenant - Object store and index type (TSDB/boltdb-shipper) Your job: 1. **Confirm the mechanism** — verify retention is enforced by the compactor (not just bucket lifecycle), that exactly one compactor runs with `retention_enabled: true`, and that `delete_request_store` is configured, since a common failure is retention silently not deleting anything. 2. **Design the retention matrix** — build `retention_period` defaults plus `overrides` with `retention_stream` selectors so audit logs keep e.g. 365d while debug logs drop at 7d, tenant by tenant. Show the exact `limits_config`/overrides YAML. 3. **Compactor throughput** — tune `compaction_interval`, `retention_delete_delay`, `retention_delete_worker_count`, and `delete_batch_size` so compaction keeps pace with ingest and the pending-delete backlog stays near zero. Explain what a growing backlog indicates. 4. **Deletion delay & safety** — explain `retention_delete_delay` as the grace window before objects are removed, and how to use it plus a staging tenant to catch a mis-scoped rule before data is gone. 5. **Line-level deletes** — cover the per-line/stream delete API for GDPR/right-to-erasure requests versus time-based retention, and when each applies. 6. **Verify** — give the queries/metrics that prove retention is actually deleting (index shrinking, oldest queryable timestamp advancing). Output as: (a) mechanism verification checklist, (b) the retention overrides YAML by tenant/stream, (c) compactor tuning values with rationale, (d) the safe-rollout plan using delete delay + staging tenant, (e) verification metrics. Bias toward: a single authoritative compactor, compliance-driven longest-retention safety, and verifiable deletion rather than assumed deletion.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Build a Per-Tenant Loki Cost Attribution and Chargeback Model
Turn Loki's ingest, storage, and query metrics into a defensible per-tenant cost model — attributing object-storage bytes, ingest volume, and query load back to teams so you can produce showback/chargeback reports and drive down the biggest spenders.
-
Tune Loki Ingester WAL and Replay for Safe Crash Recovery
Configure and validate the Loki ingester write-ahead log, flush-on-shutdown behaviour, and replay memory ceiling so an ingester crash or rollout replays cleanly without losing recent logs, OOMing on startup, or stalling the write path.
-
Tune Loki's Query Frontend, Scheduler, and Query Sharding
Design the Loki read-path parallelism stack — query splitting, TSDB query sharding, the query-scheduler queue, and per-tenant outstanding-request limits — so large queries fan out cleanly instead of stalling, timing out, or overflowing the queue.
-
Tune Loki Chunk Sizing and Object Storage Layout
Optimize Loki chunk targets, compression, and object-storage configuration to balance query speed, storage cost, and request rate against S3/GCS/Azure limits.
More Loki prompts & error guides
Browse every Loki prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.