为什么我的 Loki 日志保留不起作用?

Vin*_*war 9 purge retention grafana-loki promtail

即使指定“retention_period: 12h”,“12h”旧日志也不会删除,因此我面临存储问题,因为日志不会删除。请帮我配置

loki:
  enabled: true
  isDefault: true
  table_manager:
    retention_deletes_enabled: true
    retention_period: 12h
Run Code Online (Sandbox Code Playgroud)

Mar*_*ira 7

我有以下与日志保留相关的配置:

...
compactor:
  ...
  retention_enabled: true
...
limits_config:
  ...
  retention_period: 90d
...
Run Code Online (Sandbox Code Playgroud)

在此处的文档中查看有关 Loki 配置的更多信息


Vla*_*lav 5

Grafana Loki 存储保留

默认情况下,当table_manager.retention_deletes_enabledcompactor.retention_enabled 标志未设置时发送到 Loki 的日志将永远存在。

最短保留期限为24小时

保留期必须是在块中配置的索引和块表的倍数periodperiod_config

示例配置:

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

table_manager:
  retention_deletes_enabled: true
  retention_period: 24h
Run Code Online (Sandbox Code Playgroud)

在 Grafana Loki 中设置保留的另一种方法是通过 Compactor。

limits_config:
  retention_period: 168h

compactor:
  working_directory: /data/retention
  compaction_interval: 10m
  retention_enabled: true
  retention_delete_delay: 2h
  retention_delete_worker_count: 150

schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 24h
Run Code Online (Sandbox Code Playgroud)

请注意,仅当索引周期为 24h 时,保留才可用

要立即清除数据,您可以将retention_delete_delay间隔设置为1m。这是一个延迟,在此之后块将在保留期间被完全删除。

更改配置后不要忘记重新启动 Loki:

systemctl restart loki
systemctl status loki
Run Code Online (Sandbox Code Playgroud)

  • `retention_delete_delay` 只是延迟删除 `limits_config\retention_period` 中定义的内容。其原因在 https://grafana.com/docs/loki/latest/operations/storage/retention/ 中描述为:“1. ...立即删除块可能会导致组件仍然引用旧块,因此它们可能无法执行查询。延迟允许组件刷新其存储,从而优雅地删除对这些块的引用。2.它提供了一个很短的时间窗口,可以在配置错误的情况下取消块删除。 ” (3认同)