「Grafana Loki」- 处理重复日志

问题描述

在 Grafana Loki 中,我们发现重复日志,这些日志具有相同的时间戳。

解决方案

出现重复日志的原因由很多,这里将讨论我们遇到的问题。

场景:应用程序写入内容相同的日志

Loki logs panel deduplication · Issue #22498 · grafana/grafana · GitHub

原因分析

在短时间内,应用程序写入大量内容相同的日志。仔细观察,日志时间戳的毫秒位是不同的。

解决方案

我们在 Grafana 的 Panel 中,开启 Deduplication: Exact 选项,对日志进行去重。

Exact,根据 De-duplication of successive lines that are identical, ignoring ISO datetimes. 描述,将忽略前缀 ISO 时间的不同。

场景:… Maximum active stream limit exceeded …

how can I increase the maximum active stream limit? · Issue #3335 · grafana/loki · GitHub

在 Promtail Log 中,我们看到类似如下内容:

level=warn ts=2022-11-10T05:10:49.533015596Z caller=client.go:349 component=client
 host=loki-loki-distributed-gateway.loki.svc.cluster.local msg="error sending batch, will retry" 
 status=429 error="server returned HTTP status 429 Too Many Requests (429): Maximum 
 active stream limit exceeded, reduce the number of active streams (reduce labels or 
 reduce label values), or contact your Loki administrator to see if the limit can be increased"

我们猜测是重试导致日志重复,但是我们并不能十分确定。

针对 … Maximum active stream limit exceeded … 信息,我们尝试修改 limits_config.max_streams_per_user: 0 配置,后面再做进一步观察。

场景:其他原因导致的日志重复

在 GitHub 中,与重复日志相关的问题:
Duplicate logs in loki with multiple replicas of Promtail · Issue #7141
Single Store Loki (boltdb-shipper index type)/Write Deduplication disabled