feat(proxy,billing,pool): 增强隧道/流中断诊断日志、修复缓存 TTL 差异化计价

- stream_processor: 上游流中断时记录完整异常链与已传输 token 统计
- hub_transport: 断连影响 in-flight 流、STREAM_ERROR、超时场景补充 warning 日志;
  未启用时跳过重连循环,重连失败日志降频避免刷屏
- tunnel_manager: 流超时/错误/全部取消/STREAM_ERROR 增加诊断日志与字节统计
- billing_integration: 计费时自动补全 cache_ttl_minutes(从 provider key 查询
  或从 5m/1h 细分 token 回推),修复缓存 TTL 差异化计价缺失
- PoolManagement.vue: 移除重复的账号告警 Badge
- 新增 billing integration 单元测试
This commit is contained in:
fawney19
2026-03-06 00:14:10 +08:00
parent 228cbc8f87
commit fa71cddb60
6 changed files with 315 additions and 20 deletions

View File

@@ -1057,6 +1057,31 @@ class StreamProcessor:
except GeneratorExit:
raise
except (httpx.StreamClosed, httpx.HTTPError) as exc:
# 记录上游流中断的详细诊断信息
elapsed = time.monotonic() - start_time if start_time else 0
exc_chain = []
seen: set[int] = set()
cause: BaseException | None = exc
while cause is not None and id(cause) not in seen:
seen.add(id(cause))
exc_chain.append(f"{type(cause).__name__}: {cause}")
cause = cause.__cause__ or cause.__context__
logger.warning(
"[{}] upstream stream error: provider={}, model={}, "
"yielded_any={}, has_completion={}, elapsed={:.1f}s, "
"input_tokens={}, output_tokens={}, "
"exception_chain=[{}]",
self.request_id,
ctx.provider_name,
ctx.model,
yielded_any,
ctx.has_completion,
elapsed,
ctx.input_tokens,
ctx.output_tokens,
" -> ".join(exc_chain),
)
# 连接关闭/协议错误best-effort flush 残留 SSE避免丢失尾部 usage。
try:
if buffer: