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:
@@ -1,4 +1,4 @@
|
||||
package middleware
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"log"
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/volcano-tts/tts-api/common"
|
||||
"github.com/volcano-tts/tts-api/metrics"
|
||||
)
|
||||
|
||||
type RateLimiter struct {
|
||||
@@ -55,6 +56,7 @@ func (rl *RateLimiter) Allow(key string) bool {
|
||||
|
||||
if len(valid) >= rl.limit {
|
||||
rl.requests[key] = valid
|
||||
metrics.RateLimitRejected.Inc(nil)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -90,7 +92,6 @@ func (rl *RateLimiter) cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
// 私有网络 CIDR 范围:仅在直连来源属于这些范围时才信任代理头
|
||||
var privateCIDRs []*net.IPNet
|
||||
|
||||
func init() {
|
||||
@@ -125,9 +126,6 @@ func isPrivateIP(ipStr string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// GetClientIP 提取客户端真实 IP。
|
||||
// 仅当直连来源为私有网络(本地代理、Docker 网桥等)时才信任 X-Forwarded-For / X-Real-IP,
|
||||
// 防止公网直连场景下攻击者伪造代理头绕过速率限制。
|
||||
func GetClientIP(r *http.Request) string {
|
||||
directIP, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user