- 网关客户端新增原始数据收集器,记录最后一次尝试的明文请求、HTTP 状态、响应体与 code/msg/trace_id - tb_card_traffic_collection 只写成功读数,新增 carrier_id 与原始数据列;新增 tb_card_traffic_collection_failure,失败不判断有无套餐并带错误详情 - 采集记录在线保留当月加最近 2 个整月,到期分区摘出、导出 csv.gz、校验行数与 SHA-256 后删除,本地保留 3 个月 - 新增采集成功/失败、卡日流量、套餐日流量详单、冲正流水、退款后处理尝试列表接口:可查单个也可查全部,分页与条件筛选 - 停复机记录支持资产标识、场景、原因、指令号筛选;单卡历史支持动作、结果、来源筛选 - 单卡采集记录支持筛选与合并失败记录;套餐日流量详单支持分页;退款列表支持后处理状态筛选 - 测试环境 api、worker 日志分目录,保留 40 个压缩备份;worker 挂载 archive 目录 - 迁移 000272、000273 需维护者在测试库执行后再部署 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
)
|
|
|
|
// RawCapture 收集一次网关调用的原始数据(最后一次 HTTP 尝试),供业务记录留存。
|
|
// 只保存加密前的明文业务请求与网关响应;不含加密报文、签名、应用标识、密钥与请求头。
|
|
type RawCapture struct {
|
|
// Request 是加密前的明文业务请求({"params": ...});不记录载荷的调用为空。
|
|
Request json.RawMessage
|
|
// HTTPStatus 是 HTTP 状态码;没拿到响应(超时、连接失败)时为 0。
|
|
HTTPStatus int
|
|
// Response 是网关原始响应体;没拿到响应体时为空。
|
|
Response []byte
|
|
// GatewayCode、GatewayMsg、TraceID 是网关响应外层字段;响应无法解析时为空。
|
|
GatewayCode *int
|
|
GatewayMsg string
|
|
TraceID string
|
|
// Attempts 是网关客户端内部 HTTP 尝试次数。
|
|
Attempts int
|
|
}
|
|
|
|
type rawCaptureKey struct{}
|
|
|
|
// WithRawCapture 在请求上下文上挂载原始数据收集器;未挂载的调用不收集。
|
|
func WithRawCapture(ctx context.Context) (context.Context, *RawCapture) {
|
|
capture := &RawCapture{}
|
|
return context.WithValue(ctx, rawCaptureKey{}, capture), capture
|
|
}
|
|
|
|
func rawCaptureFrom(ctx context.Context) *RawCapture {
|
|
capture, _ := ctx.Value(rawCaptureKey{}).(*RawCapture)
|
|
return capture
|
|
}
|
|
|
|
// resetResponse 在每次 HTTP 尝试前清空上一次的响应,保证留存的是最后一次尝试。
|
|
func (c *RawCapture) resetResponse() {
|
|
if c == nil {
|
|
return
|
|
}
|
|
c.HTTPStatus, c.Response, c.GatewayCode, c.GatewayMsg, c.TraceID = 0, nil, nil, "", ""
|
|
}
|