Portal Community

Global Retention Configuration

# loki-config.yaml — retention configuration
compactor:
  working_directory: /loki/compactor
  shared_store: s3
  compaction_interval: 10m       # How often compactor runs
  retention_enabled: true         # MUST be true to enable deletion
  retention_delete_delay: 2h      # Wait 2h after marking before deleting
  retention_delete_worker_count: 150

# Global limits (applies to all tenants unless overridden):
limits_config:
  retention_period: 720h          # 30 days (720 hours)
  # Alternative: 2160h = 90 days, 8760h = 1 year

Per-Tenant Retention

BizFirstGO is multi-tenant. You may need different retention periods per tenant — for example, financial tenants requiring 1-year log retention while development tenants need only 7 days:

# loki-config.yaml — per-tenant retention overrides
limits_config:
  retention_period: 720h           # Global default: 30 days

# Per-tenant overrides in a separate runtime config:
# loki-runtime-config.yaml
overrides:
  # Financial tenant — 1-year log retention
  "tenant-financial-corp":
    retention_period: 8760h        # 365 days

  # Development tenant — 7-day retention to save space
  "tenant-dev":
    retention_period: 168h         # 7 days

  # Standard SaaS tenant — 90-day retention
  "tenant-saas-standard":
    retention_period: 2160h        # 90 days

How Loki Compaction Works

PhaseWhat HappensTiming
CompactionMerges small chunks into larger ones for efficient queryEvery 10 minutes (configurable)
Retention markingCompactor marks chunks older than retention_period for deletionDuring compaction run
Deletion delayMarked chunks wait in "to-delete" state (allows abort if misconfigured)2 hours (retention_delete_delay)
Actual deletionChunks are permanently deleted from object storageAfter delay expires

Monitoring Retention

# Check Loki compactor status via metrics:
curl -s http://localhost:3100/metrics | grep loki_compactor

# Key metrics:
# loki_compactor_runs_total                   — total compaction runs
# loki_compactor_blocks_cleaned_total         — chunks deleted by retention
# loki_compactor_retention_marked_for_deletion_total — chunks marked

# Verify retention is working (query should return no data for period before retention):
# In Grafana Explore (Loki):
# Set time range to older than your retention period
# Run any LogQL query
# Expected: "No data" (logs have been deleted)
Retention Is Irreversible

Once logs are deleted by the Loki compactor, they cannot be recovered. Ensure your retention period covers all compliance requirements before enabling deletion. For compliance-sensitive deployments, archive to cold storage (S3 Glacier) before the hot retention period expires — see the Archiving page for configuration.