feat: 实现完整可观测性架构与火山v3适配器重构

重构整体架构:
1.  新增telemetry包实现零依赖的Prometheus指标系统
2.  新增metrics包集中管理业务埋点指标
3.  重构火山v3适配器,拆分client/request/response等模块
4.  替换旧的service/stats统计系统为标准指标埋点
5.  新增/metrics观测端点与完整仪表盘支持

功能更新:
- 实现基于IP的限流与并发限制,添加指标埋点
- 重构TTS控制器,支持多格式输出与完整错误分类
- 更新.env.example配置示例,新增多项可选参数
- 替换旧的volcano适配器实现,支持完整的v3 API特性
- 清理冗余代码,移除service/stats与旧adapter实现
This commit is contained in:
sun
2026-08-15 13:30:35 +08:00
parent 07a7dd450c
commit 5b970f49e1
30 changed files with 1875 additions and 836 deletions
+4 -16
View File
@@ -1,5 +1,8 @@
package dto
package dto
// HealthResponse 是 /health 端点的 JSON 响应。
// 数值类信息(请求统计、错误)迁移到 /metrics 端点,
// 这里只保留运行期最关键的状态。
type HealthResponse struct {
Status string `json:"status"`
Service string `json:"service"`
@@ -7,24 +10,9 @@ type HealthResponse struct {
Uptime string `json:"uptime"`
StartTime string `json:"start_time"`
Memory map[string]interface{} `json:"memory"`
APIStats APIStatsResponse `json:"api_stats"`
Errors ErrorResponse `json:"errors"`
ConfigStatus ConfigStatusResponse `json:"config_status"`
}
type APIStatsResponse struct {
TotalRequests int `json:"total_requests"`
SuccessfulRequests int64 `json:"successful_requests"`
FailedRequests int64 `json:"failed_requests"`
ErrorRatePercent string `json:"error_rate_percent"`
AvgResponseTimeMs string `json:"avg_response_time_ms"`
RecentResponseTimesMs []float64 `json:"recent_response_times_ms"`
}
type ErrorResponse struct {
RecentErrorsCount int `json:"recent_errors_count"`
}
type ConfigStatusResponse struct {
AllRequiredVarsSet bool `json:"all_required_vars_set"`
ConfigError bool `json:"config_error"`
+28 -5
View File
@@ -1,7 +1,10 @@
package dto
package dto
import "time"
// OpenAITTSRequest 是 /v1/audio/speech 接收的请求体。
// 仅 input / speed / response_format 实际影响火山侧;
// voice / model 当前保留接收但不做映射,详见 controller。
type OpenAITTSRequest struct {
Model string `json:"model"`
Input string `json:"input"`
@@ -10,6 +13,7 @@ type OpenAITTSRequest struct {
Speed float64 `json:"speed,omitempty"`
}
// V3TTSResponse 是火山 v3 HTTP Chunked 流式响应中每一行的 JSON 结构。
type V3TTSResponse struct {
ReqID string `json:"reqid"`
Code int `json:"code"`
@@ -22,20 +26,39 @@ type V3TTSResponse struct {
Usage *V3Usage `json:"usage,omitempty"`
}
// V3Usage 由 X-Control-Require-Usage-Tokens-Return 触发,包含计费字符数。
type V3Usage struct {
TextWords int `json:"text_words"`
}
// ByteDanceTTSConfig 是 setting 包的全局 TTS 配置,目前只承载鉴权 / URL / 超时;
// 完整的合成参数见 adapter/volcano.Options。
type ByteDanceTTSConfig struct {
ApiKey string
ResourceId string
Speaker string
URL string
Timeout time.Duration
}
// SynthesisResult 是火山适配器向 controller 返回的最终结果。
// Format 与 AudioData 的实际编码一致;controller 据此设置响应 Content-Type。
type SynthesisResult struct {
AudioData []byte
ReqID string
Format string // 实际输出格式,用于设置 Content-Type
AudioData []byte
Format string
SampleRate int
ReqID string
TextWords int // 来自 V3Usage,无 usage 时为 0
Chunks int // 实际收到的音频 chunk 数
AudioBytes int // 解码后总字节数
TTFB time.Duration // 收到首个音频 chunk 的耗时
Duration time.Duration // 整体合成耗时
}
// SubtitleEntry 描述一个字级时间戳条目(当 enable_subtitle / enable_timestamp 启用时返回)。
type SubtitleEntry struct {
Text string
StartMs int
EndMs int
Sequence int
// 原始事件可能为不同形态,这里只保留通用字段
}