Log retention policy

  • What Grafana loki version and what operating system are you using?

loki, version 2.9.4 on RHEL 8

  • What are you trying to achieve?

Everything is working fine.

  • How are you trying to achieve it?

I’ve set up separate hosts for Grafana Loki and Grafana, and their integration is functioning well. However, I’m still unsure about Loki’s log retention. Despite the configuration file specifying a retention period of ‘period: 24h’, I’m seeing old logs persisting. Can you help clarify the following?

1-Could you explain the purpose of these directories?

filesystem:
chunks_directory: /grafanaloki/loki/chunks
rules_directory: /grafanaloki/loki/rules

2-In the schema configuration:

schema_config:
configs:

  • from: 2020-10-24
    store: boltdb-shipper
    object_store: filesystem
    schema: v11
    index:
    prefix: index_
    period: 24h

What does ‘24h’ signify here?

3- If I aim to retain logs for only 60 days, what adjustments should I make to the configuration?

Thank you

  • Can you copy/paste the configuration(s) that you are having problems with?

auth_enabled: false

server:
http_listen_port: 3100
grpc_listen_port: 9096

common:
instance_addr: 127.0.0.1
path_prefix: /grafanaloki/loki
storage:
filesystem:
chunks_directory: /grafanaloki/loki/chunks
rules_directory: /grafanaloki/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory

query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100

schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h

ruler:
alertmanager_url: http://localhost:9093

query_scheduler:
max_outstanding_requests_per_tenant: 4096

The 24h in index means the period the index files will be grouped into. Keep it 24h, no reason to use anything other than 24h there.

In order to configure retention you want too use compactor, see Retention | Grafana Loki documentation.

Thank you!
Just wondering what is my current retention period. I mean the default one if I have not explicitly configured the retention period.

This is the documentation on Loki retention: Retention | Grafana Loki documentation

You essentially need two things:

  1. Enable retention for compactor (don’t use table manager).
  2. Configure retention_period under limits_config.

If you use everything default I don’t think retention is enabled at all (meaning logs are kept indefinitely).

Thanks a lot. Let me try the compactor config and monitor.