DEBUG.WIKI
ZgoCloud:多地区部署,按需选节点;日本、美国、香港、德国
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS
晚安云;香港 CN2 ¥15/月

解决 Grafana Tempo 报错 traces dropped ingester queue full 故障

分析 Grafana Tempo 提示 traces dropped due to ingester queue full 根因,详解 Ingester 内存缓冲、WAL 磁盘调优与并行分片配置。

问题现象

OpenTelemetry Collector 向 Grafana Tempo 推送全链路追踪 Trace 数据时大量报错并丢弃:

2026-11-15T09:35:10.123Z [ERROR] tempo-distributor: failed to push trace batch: rpc error: code = ResourceExhausted desc = ingester queue is full

监控指标 tempo_distributor_bytes_received_total 出现大面积断崖式下跌。

触发根因

  1. Ingester 写入队列打满(ResourceExhausted):后端 Ingester 实例数量不足或内存缓冲区饱和,无法及时将接收到的 Trace 写入 WAL 临时日志。
  2. 底层 WAL 磁盘 I/O 写入延迟高:WAL 所在物理盘吞吐受限,导致内存中的 Block Flush 周期拉长。
  3. 缺少合理的全局采样率控制。

诊断排查步骤

  1. 检查 Tempo Ingester 的队列深度与内存占用:
curl -s http://tempo:3200/metrics | grep "tempo_ingester_live_traces"
curl -s http://tempo:3200/metrics | grep "tempo_discarded_spans_total"
  1. 检查 WAL 挂载卷的磁盘 I/O:
iostat -xz 1 5

解决步骤与操作命令

步骤一:调大 Ingester 队列与并发上限

在 Tempo 配置文件中的 ingester 段落优化缓冲参数:

ingester:
  max_block_duration: 30m
  max_block_bytes: 1073741824 # 1GB
  complete_block_timeout: 15m
  flush_check_period: 30s
  trace_idle_period: 10s

步骤二:水平扩容 Ingester 副本数并开启哈希环分片

在 Kubernetes 部署中提高 Ingester 副本数量:

kubectl scale statefulset tempo-ingester --replicas=5 -n monitoring

Distributor 会根据 Trace ID 将写入请求均匀哈希分发至各 Ingester 分片。

步骤三:前置 OpenTelemetry Collector 开启尾部采样(Tail Sampling)

避免将全量无价值的 200 HTTP Trace 推入 Tempo,使用 Tail-based Sampling 优先保留异常或慢追踪:

processors:
  tail_sampling:
    decision_wait: 10s
    expected_trajectories: 100000
    policies:
      [
        {
          name: errors-policy,
          type: status_code,
          status_code: {status_codes: [ERROR]}
        },
        {
          name: probabilistic-policy,
          type: probabilistic,
          probabilistic: {sampling_percentage: 10}
        }
      ]

验证方法

观察 Distributor 监控指标: tempo_discarded_spans_total 增量归零,各 Ingester 内存与 WAL 队列平稳运转,Grafana 追踪链路完全恢复可用。