完整內容,請至幹話王 OTel 戰地筆記:破解 Delta to Cumulative 的兩大夢魘 (ErrOutOfOrder & ErrOlderStart)
接續上一篇我們對 deltatocumulative Processor 的架構剖析,今天我們要進入「深水區」。
在生產環境中,你可能遇過這種情況:Metrics 莫名其妙開始 Drop,去查 deltatocumulative_datapoints 指標時,看到 error 標籤出現了 delta.ErrOutOfOrder 或 delta.ErrOlderStart。
這不僅僅是報錯,這是 Processor 在告訴你:你的數據流違反了物理定律。本文將從 Stream Identity (身份識別) 的源碼層級出發,徹底拆解這兩個錯誤的根源。
要讀懂錯誤,首先得搞懂 Processor 怎麼判定「這是同一條 Stream」。許多人誤以為只要 Metric Name 一樣就是同一條線,這是大錯特錯。
在源碼中,Stream Identity 是一個 Hash 值,其組成結構非常嚴謹:
Stream Identity = Hash of:
┌─────────────────────────────────────────────────────────────────────┐
│ Metric │
│ ├── Scope │
│ │ ├── Resource │
│ │ │ └── resource.attributes (hash) │
│ │ │ (關鍵!: service.name, host.name, k8s.pod.name) │
│ │ ├── scope.name (例: "otelcol/prometheus") │
│ │ ├── scope.version (例: "v0.90.0") │
│ │ └── scope.attributes (hash) │
│ ├── metric.name (例: "http_requests_total") │
│ ├── metric.unit (例: "ms") │
│ ├── metric.type (例: Sum, Histogram) │
│ ├── metric.monotonic (true/false) │
│ └── metric.temporality (Delta/Cumulative) │
└─────────────────────────────────────────────────────────────────────┘
+
datapoint.attributes (hash) (例: method="GET", status="200")