DEBUG.WIKI
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证
阿里云;从建站到云上业务;云服务器 · 数据库 · 对象存储;查看产品 →
搬瓦工;先看线路,再选 VPS;CN2 GIA · 对应线路套餐;查看线路 →

解决 Prometheus 报错 sample timestamp out of order 乱序拒绝

分析 Prometheus 远程存储接收端报 sample timestamp out of order 根因,详解时钟同步偏差、乱序时间窗口配置与指标重叠排查。

问题现象

Prometheus 向远程时序库推流时收到 HTTP 400 拒绝响应:

ts=2026-11-15T13:50:00.123Z caller=dedup.go:120 component=remote level=warn remote_name=vm msg="Failed to send batch, retrying" err="server returned HTTP status 400 Bad Request: duplicate sample for timestamp or out of order"

触发根因

  1. 多个 Prometheus 实例向同一时序库推送完全相同标签但时间戳逆流的采样点:两个 Prometheus 高可用副本未配置去重(Deduplication),互相交替抢先写入同一时序。
  2. 被监控目标的时间戳(Timestamp)发生回拨。

诊断排查步骤

  1. 检查推送端 Prometheus 的标签识别(External Labels):
global:
  external_labels:
    replica: A # 检查是否两个实例配置了相同标签

解决步骤与操作命令

步骤一:为每个 Prometheus 实例配置独一无二的 replica 标签

global:
  scrape_interval: 15s
  external_labels:
    cluster: prod-k8s
    prometheus_replica: $(POD_NAME)

步骤二:在目标时序库端开启乱序接收容忍(Out of Order Support)

若使用 VictoriaMetrics 或 Thanos Receive,开启乱序窗口:

# VictoriaMetrics 启动参数开启容忍轻微乱序
-retentionPeriod=30d
-search.latencyOffset=30s

验证方法

观察 Prometheus remote_write 状态: 错误日志立即停止,各分片样本被远端时序库平稳吸纳,Grafana 曲线连贯展示无断点。