fix: VUL-002 修复 transport 错误埋点缺失

VUL-002 (低): transport 层错误不进入 UpstreamErrors 指标
原代码用 if errCode != 0 判断是否记录错误,但合成链路中
多种错误场景的 errCode 本身是 0(火山 v3 业务码非 0 时才
会传入),导致这些场景在 /metrics 上完全不可见:
  - transport_error: client.PostStream 失败(DNS / 连接 / TLS)
  - request_error  : buildRequest 序列化失败
  - wrap_error     : WAV 头拼装失败
  - stream_error (code=0): 读流错误
修复:把判断改为 if status != "ok",status 是上游调用全链
路的权威错误指示器,任何非 ok 状态都计为错误。
codeLabel(0) → "transport" 已有定义,修复后该分类真正生效,
火山接口不可达等网络故障首次在监控上可见。
向后兼容:已统计的 http_XXX 错误(status="http_xxx" != "ok")
行为不变,新增 transport / request / wrap / stream 错误进入指标。
This commit is contained in:
sun
2026-08-26 15:35:24 +08:00
parent 91b0c8acee
commit 171503d775
+4 -1
View File
@@ -131,7 +131,10 @@ func (AdapterRecorder) UpstreamFinished(speaker, model, format, status string, d
if audioBytes > 0 {
UpstreamBytes.Add(float64(audioBytes), telemetry.Labels{"format": format})
}
if errCode != 0 {
// 上游调用只要 status != "ok" 即视为错误。原版 if errCode != 0 会漏掉
// errCode=0 的 request_error / transport_error / wrap_error / stream_error
// (code=0 的流错误) 等场景,导致 transport 类错误在 /metrics 上完全不可见。
if status != "ok" {
UpstreamErrors.Inc(telemetry.Labels{"code": codeLabel(errCode)})
}
}