loki日志之留存日志不生效问题解决

总结:loki日志存留时间(issue 中表示table_manager对文件系统留存设置没用,需使用compactor): https://github.com/grafana/loki/issues/6300#issuecomment-1431887039

前文:kubernetes 部署loki-stack ,配置文件中已经设置:table_manager.retention_deletes_enabled,以及retention_period, 但是分析在留存时间n倍长的时间都剩余存储还是不断的在减少,并没有固定在一个范围

上图为剩余存储图

一开始看到剩余存储的波浪线不断起伏 仍然有上升以为是生效了的,但是时间越久 资源不论多少总能无限增大,于是排查日志存留问题:官方grafana一股子付费grafana cloud的味,对于文档的优化并不多,从文档中并没有发现什么不对的地方。

这里在官方issue下发现 https://github.com/grafana/loki/issues/6300#issuecomment-1431887039 有用户通过不断尝试总算发现能够生效的原因(感谢大佬,同时鄙视文档- -),大佬使用了

compactor配置,而没有使用table_manager,同时在issue其他楼层也发现用户提出了使用compactor而不是table_manager,因为table_manager的留存配置对于文件存储是没有用的 ,对于使用s3存储方才有用 https://github.com/grafana/loki/issues/6300#issuecomment-1146556014
于是修改loki yaml:

auth_enabled: false
chunk_store_config:
  max_look_back_period: 0s
compactor:
  compaction_interval: 10m
  retention_delete_delay: 1h
  retention_enabled: true
  retention_delete_worker_count: 150
  shared_store: filesystem
  working_directory: /data/loki/boltdb-shipper-compactor
ingester:
  chunk_block_size: 262144
  chunk_idle_period: 3m
  chunk_retain_period: 1m
  lifecycler:
    ring:
      replication_factor: 1
  max_transfer_retries: 0
  wal:
    dir: /data/loki/wal
limits_config:
  enforce_metric_name: false
  max_entries_limit_per_query: 5000
  reject_old_samples: true
  reject_old_samples_max_age: 72h
  retention_period: 240h
memberlist:
  join_members:
  - 'loki-memberlist'
schema_config:
  configs:
  - from: "2023-10-24"
    index:
      period: 24h
      prefix: index_
    object_store: filesystem
    schema: v11
    store: boltdb-shipper
server:
  grpc_listen_port: 9095
  http_listen_port: 3100
storage_config:
  boltdb_shipper:
    active_index_directory: /data/loki/boltdb-shipper-active
    cache_location: /data/loki/boltdb-shipper-cache
    cache_ttl: 24h
    shared_store: filesystem
  filesystem:
    directory: /data/loki/chunks

修改后重启loki服务,并且在日志排查mark file 出现则表示生成过期文件,后续清理:
kubectl logs -n loki-stack loki-0 -f | grep 'mark file'
level=info ts= caller=marker.go:78 msg="mark file created" file=/data/loki/boltdb-shipper-compactor/retention/markers/1716937742808095008
level=info ts= caller=marker.go:78 msg="mark file created" file=/data/loki/boltdb-shipper-
...

这里可以看到生效后瞬间释放大量过期无用日志。

loki 较新版本还支持通过调用API的方式清理Loki日志:
curl -X DELETE ‘http://x.x.x.x:3100/api/v1/purge?dryRun=false&keepHours=0&deleteAll=true&index=loki_local’

查询接口:curl -sG http://x.x.x.x:3100/api/prom/query\?limit=10 –data-urlencode ‘query={app=”loki”}’ | jq

curl -sG http://x.x.x.x:3100/api/prom/query\?limit=10 –data-urlencode ‘query={app=”loki”}’

但是loki-stack中的loki版本过旧 部分API不支持。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇