1. 22 Feb, 2026 1 commit
  2. 14 Feb, 2026 3 commits
  3. 13 Feb, 2026 1 commit
    • yangjianbo's avatar
      fix(ops): 修复日志级别过滤并增强OpenAI错误诊断日志 · f96acf6e
      yangjianbo authored
      - 移除 warn 级别下 access info 的强制入库补写,确保运行时日志级别真实生效
      
      - 将 OpenAI fallback matched 与 passthrough 断流提示按需求降级为 info
      
      - 为 codex_cli_only 与 instructions required 场景补充请求诊断字段(含 User-Agent)
      
      - 出于安全考虑移除请求体预览,仅保留 request_body_size 与白名单头信息
      
      - 新增/更新回归测试,覆盖 Forward 入口到日志落库链路
      f96acf6e
  4. 12 Feb, 2026 2 commits
  5. 09 Feb, 2026 1 commit
  6. 08 Feb, 2026 1 commit
    • yangjianbo's avatar
      test: 完善自动化测试体系(7个模块,73个任务) · bb5a5dd6
      yangjianbo authored
      
      
      系统性地修复、补充和强化项目的自动化测试能力:
      
      1. 测试基础设施修复
         - 修复 stubConcurrencyCache 缺失方法和构造函数参数不匹配
         - 创建 testutil 共享包(stubs.go, fixtures.go, httptest.go)
         - 为所有 Stub 添加编译期接口断言
      
      2. 中间件测试补充
         - 新增 JWT 认证中间件测试(有效/过期/篡改/缺失 Token)
         - 补充 rate_limiter 和 recovery 中间件测试场景
      
      3. 网关核心路径测试
         - 新增账户选择、等待队列、流式响应、并发控制、计费、Claude Code 检测测试
         - 覆盖负载均衡、粘性会话、SSE 转发、槽位管理等关键逻辑
      
      4. 前端测试体系(11个新测试文件,163个测试用例)
         - Pinia stores: auth, app, subscriptions
         - API client: 请求拦截器、响应拦截器、401 刷新
         - Router guards: 认证重定向、管理员权限、简易模式限制
         - Composables: useForm, useTableLoader, useClipboard
         - Components: LoginForm, ApiKeyCreate, Dashboard
      
      5. CI/CD 流水线重构
         - 重构 backend-ci.yml 为统一的 ci.yml
         - 前后端 4 个并行 Job + Postgres/Redis services
         - Race 检测、覆盖率收集与门禁、Docker 构建验证
      
      6. E2E 自动化测试
         - e2e-test.sh 自动化脚本(Docker 启动→健康检查→测试→清理)
         - 用户注册→登录→API Key→网关调用完整链路测试
         - Mock 模式和 API Key 脱敏支持
      
      7. 修复预存问题
         - tlsfingerprint dialer_test.go 缺失 build tag 导致集成测试编译冲突
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      bb5a5dd6
  7. 07 Feb, 2026 6 commits
    • yangjianbo's avatar
      perf(日志): 降噪优化,将常规成功日志降级为 Debug 级别 · 53e1c8b2
      yangjianbo authored
      
      
      - GIN Logger 中间件跳过 /health 和 /setup/status 的请求日志
      - UsageCleanup 空闲轮询(no_task)日志降级为 slog.Debug
      - Scheduler 常规 rebuild ok 日志降级为 slog.Debug
      - DashboardAggregation 常规聚合完成日志降级为 slog.Debug
      - TokenRefresh 无刷新活动时周期日志降级为 slog.Debug
      
      生产环境(Info 级别)下自动静默,debug 模式下仍可见。
      错误、警告类日志保持原有级别不变。
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      53e1c8b2
    • yangjianbo's avatar
      test: 为代码审核修复添加详细单元测试(7个测试文件,50+测试用例) · 00caf0bc
      yangjianbo authored
      
      
      新增测试文件:
      - cors_test.go: CORS 条件化头部测试(12个测试,覆盖白名单/黑名单/通配符/凭证/多源/Vary)
      - gateway_helper_backoff_test.go: nextBackoff 退避测试(6个测试+基准,验证指数增长/边界/抖动/收敛)
      - billing_cache_jitter_test.go: jitteredTTL 抖动测试(5个测试+基准,验证范围/上界/方差/均值)
      - subscription_calculate_progress_test.go: calculateProgress 纯函数测试(9个测试,覆盖日/周/月限额/超限截断/过期)
      - openai_gateway_handler_test.go: SSE JSON 转义测试(7个子用例,验证双引号/反斜杠/换行符安全)
      
      更新测试文件:
      - response_transformer_test.go: 增强 generateRandomID 测试(7个测试,含并发/字符集/降级计数器)
      - security_headers_test.go: 适配 GenerateNonce 新签名
      - api_key_auth_test.go: 适配 NewSubscriptionService 新参数
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      00caf0bc
    • yangjianbo's avatar
      fix: 修复代码审核发现的10个问题(P0安全+P1数据一致性+P2性能优化) · 9634494b
      yangjianbo authored
      
      
      P0: OpenAI SSE 错误消息 JSON 注入 — 使用 json.Marshal 替代 fmt.Sprintf
      P1: subscription 续期包裹 Ent 事务确保原子性
      P1: CSP nonce 生成处理 crypto/rand 错误,失败降级为 unsafe-inline
      P1: singleflight 透传数据库真实错误,不再吞没为 not found
      P1: GetUserSubscriptionsWithProgress 提取 calculateProgress 消除 N+1
      P2: billing_cache/gateway_helper 迁移到 math/rand/v2 消除全局锁争用
      P2: generateRandomID 降级分支增加原子计数器防碰撞
      P2: CORS 非白名单 origin 不再设置 Allow-Headers/Methods/Max-Age
      P2: Turnstile 验证移除 VerifyCode 空值跳过条件防绕过
      P2: Redis Cluster Lua 脚本空 KEYS 添加兼容性警告注释
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      9634494b
    • yangjianbo's avatar
      fix(audit): 第二批审计修复 — P0 生产 Bug、安全加固、性能优化、缓存一致性、代码质量 · 2588fa6a
      yangjianbo authored
      
      
      基于 backend-code-audit 审计报告,修复剩余 P0/P1/P2 共 34 项问题:
      
      P0 生产 Bug:
      - 修复 time.Since(time.Now()) 计时逻辑错误 (P0-03)
      - generateRandomID 改用 crypto/rand 替代固定索引 (P0-04)
      - IncrementQuotaUsed 重写为 Ent 原子操作消除 TOCTOU 竞态 (P0-05)
      
      安全加固:
      - gateway/openai handler 错误响应替换为泛化消息,防止内部信息泄露 (P1-14)
      - usage_log_repo dateFormat 参数改用白名单映射,防止 SQL 注入 (P1-16)
      - 默认配置安全加固:sslmode=prefer、response_headers=true、mode=release (P1-18/19, P2-15)
      
      性能优化:
      - gateway handler 循环内 defer 替换为显式 releaseWait 闭包 (P1-02)
      - group_repo/promo_code_repo Count 前 Clone 查询避免状态污染 (P1-03)
      - usage_log_repo 四个查询添加 LIMIT 10000 防止 OOM (P1-07)
      - GetBatchUsageStats 添加时间范围参数,默认最近 30 天 (P1-10)
      - ip.go CIDR 预编译为包级变量 (P1-11)
      - BatchUpdateCredentials 重构为先验证后更新 (P1-13)
      
      缓存一致性:
      - billing_cache 添加 jitteredTTL 防止缓存雪崩 (P2-10)
      - DeductUserBalance/UpdateSubscriptionUsage 错误传播修复 (P2-12)
      - UserService.UpdateBalance 成功后异步失效 billingCache (P2-13)
      
      代码质量:
      - search 截断改为按 rune 处理,支持多字节字符 (P2-01)
      - TLS Handshake 改为 HandshakeContext 支持 context 取消 (P2-07)
      - CORS 预检添加 Access-Control-Max-Age: 86400 (P2-16)
      
      测试覆盖:
      - 新增 user_service_test.go(UpdateBalance 缓存失效 6 个用例)
      - 新增 batch_update_credentials_test.go(fail-fast + 类型验证 7 个用例)
      - 新增 response_transformer_test.go、ip_test.go、usage_log_repo_unit_test.go、search_truncate_test.go
      - 集成测试:IncrementQuotaUsed 并发测试、billing_cache 错误传播测试
      - config_test.go 补充 server.mode/sslmode 默认值断言
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      2588fa6a
    • yangjianbo's avatar
      fix(middleware): 管理员JWT增加TokenVersion校验 · 65c0d8b5
      yangjianbo authored
      管理员改密后旧JWT会被拒绝,并补充单元测试覆盖。
      65c0d8b5
    • yangjianbo's avatar
      perf(middleware): 优化订阅模式认证中间件,5次串行调用降至2步同步+1步异步 · 0e514ed8
      yangjianbo authored
      
      
      - 为 GetActiveSubscription 添加 ristretto L1 缓存 + singleflight 防击穿
      - 合并 ValidateSubscription + CheckUsageLimits 为纯内存 ValidateAndCheckLimits
      - 窗口维护操作(激活/重置)异步化,不再阻塞首字节
      - 缓存返回浅拷贝,避免并发 data race 和缓存污染
      - 所有管理操作(分配/续期/撤销/扩展/窗口重置)同步失效 L1 缓存
      - 新增 SubscriptionCacheConfig 可配置 L1 缓存大小/TTL/抖动
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      0e514ed8
  8. 05 Feb, 2026 1 commit
  9. 04 Feb, 2026 2 commits
  10. 03 Feb, 2026 2 commits
    • bayma888's avatar
      fix(test): add IncrementQuotaUsed to all APIKeyRepository test stubs · e59e3a9f
      bayma888 authored
      Add the missing IncrementQuotaUsed method to:
      - fakeAPIKeyRepo (api_key_auth_google_test.go)
      - stubApiKeyRepo (api_key_auth_test.go)
      - apiKeyRepoStub (api_key_service_delete_test.go)
      - authRepoStub (api_key_service_cache_test.go)
      e59e3a9f
    • bayma888's avatar
      feat(api-key): add independent quota and expiration support · 6146be14
      bayma888 authored
      This feature allows API Keys to have their own quota limits and expiration
      times, independent of the user's balance.
      
      Backend:
      - Add quota, quota_used, expires_at fields to api_key schema
      - Implement IsExpired() and IsQuotaExhausted() checks in middleware
      - Add ResetQuota and ClearExpiration API endpoints
      - Integrate quota billing in gateway handlers (OpenAI, Anthropic, Gemini)
      - Include quota/expiration fields in auth cache for performance
      - Expiration check returns 403, quota exhausted returns 429
      
      Frontend:
      - Add quota and expiration inputs to key create/edit dialog
      - Add quick-select buttons for expiration (+7, +30, +90 days)
      - Add reset quota confirmation dialog
      - Add expires_at column to keys list
      - Add i18n translations for new features (en/zh)
      
      Migration:
      - Add 045_add_api_key_quota.sql for new columns
      6146be14
  11. 02 Feb, 2026 1 commit
  12. 24 Jan, 2026 1 commit
    • shaw's avatar
      feat(subscription): 订阅过期状态自动更新与服务端排序 · b0aa2354
      shaw authored
      - 新增 SubscriptionExpiryService 定时任务,每分钟更新过期订阅状态
      - 订阅列表支持服务端排序(按过期时间、状态、创建时间)
      - 实时显示正确的过期状态,无需等待定时任务
      - 允许对已过期订阅进行续期操作
      - DataTable 组件支持 serverSideSort 模式
      b0aa2354
  13. 16 Jan, 2026 2 commits
  14. 11 Jan, 2026 2 commits
    • IanShaw027's avatar
      fix(lint): 修复所有golangci-lint错误 · 54c5788b
      IanShaw027 authored
      - 修复depguard错误:为ops service文件添加redis导入例外
      - 修复errcheck错误:添加错误检查和类型断言检查
      - 修复gofmt错误:格式化代码
      - 修复ineffassign错误:移除无效的idx++赋值
      - 修复staticcheck错误:合并条件赋值
      - 修复unused错误:移除未使用的字段和函数
        - ops_cleanup_service.go: entryID字段
        - ops_retry.go: status字段
        - ops_upstream_context.go: getOpsUpstreamErrors函数
      54c5788b
    • yangjianbo's avatar
      perf(认证): 引入 API Key 认证缓存与轻量删除查询 · 44a93c19
      yangjianbo authored
      增加 L1/L2 缓存、负缓存与单飞回源
      使用 key+owner 轻量查询替代全量加载并清理旧接口
      补充缓存失效与余额更新测试,修复随机抖动 lint
      
      测试: make test
      44a93c19
  15. 10 Jan, 2026 3 commits
  16. 09 Jan, 2026 6 commits
    • yangjianbo's avatar
      fix(分组): 防止降级环并校验上下文分组 · 2597fe78
      yangjianbo authored
      - 增加降级链路环检测并拦截配置
      
      - 仅复用合法分组上下文并必要时回退查询
      
      - 标注 GetByIDLite 轻量语义并补充测试
      2597fe78
    • IanShaw027's avatar
      feat(运维监控): 增强监控功能和健康评分系统 · 585257d3
      IanShaw027 authored
      后端改进:
      - 新增健康评分计算服务(ops_health_score.go)
      - 添加分布式锁支持(ops_advisory_lock.go)
      - 优化指标采集和聚合逻辑
      - 新增运维指标采集间隔配置(60-3600秒)
      - 移除未使用的WebSocket查询token认证中间件
      - 改进清理服务和告警评估逻辑
      
      前端改进:
      - 简化OpsDashboard组件结构
      - 完善国际化文本(中英文)
      - 新增运维监控相关API类型定义
      - 添加运维指标采集间隔设置界面
      - 优化错误详情模态框
      
      测试:
      - 添加健康评分单元测试
      - 更新API契约测试
      585257d3
    • yangjianbo's avatar
      perf(网关): 复用分组上下文减少热路径查询 · 67554324
      yangjianbo authored
      新增 GetByIDLite 并在网关与 Gemini 选择流程复用上下文 group,避免 COUNT 触发
      更新 API key 中间件注入 group 上下文,减少重复查库
      补充 gateway/gemini 中间件与仓库层回归测试
      
      测试: make test
      67554324
    • Edric.Li's avatar
      feat(api-key): 添加 IP 白名单/黑名单限制功能 (#221) · 0a4641c2
      Edric.Li authored
      * feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking
      
      - Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
      - Add IP address logging to usage logs (admin-only visibility)
      - Remove billing_type column from usage logs UI (redundant)
      - Use generic "Access denied" error message for security
      
      Backend:
      - New ip package with IP/CIDR validation and matching utilities
      - Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
      - Middleware IP restriction check after API key validation
      - Input validation for IP/CIDR patterns on create/update
      
      Frontend:
      - API key form with enable toggle for IP restriction
      - Shield icon indicator in table for keys with IP restriction
      - Removed billing_type filter and column from usage views
      
      * fix: update API contract tests for ip_whitelist/ip_blacklist fields
      
      Add ip_whitelist and ip_blacklist fields to expected JSON responses
      in API contract tests to match the new API key schema.
      0a4641c2
    • Edric Li's avatar
      feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking · 90798f14
      Edric Li authored
      - Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
      - Add IP address logging to usage logs (admin-only visibility)
      - Remove billing_type column from usage logs UI (redundant)
      - Use generic "Access denied" error message for security
      
      Backend:
      - New ip package with IP/CIDR validation and matching utilities
      - Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
      - Middleware IP restriction check after API key validation
      - Input validation for IP/CIDR patterns on create/update
      
      Frontend:
      - API key form with enable toggle for IP restriction
      - Shield icon indicator in table for keys with IP restriction
      - Removed billing_type filter and column from usage views
      90798f14
    • IanShaw027's avatar
      feat(handler): 实现运维监控 API 处理器和中间件 · f3ed95d4
      IanShaw027 authored
      - 新增 ops 错误日志记录器(ops_error_logger.go)
      - 新增 ops 主处理器(ops_handler.go)
      - 新增告警管理处理器(ops_alerts_handler.go)
      - 新增仪表板处理器(ops_dashboard_handler.go)
      - 新增实时监控处理器(ops_realtime_handler.go)
      - 新增配置管理处理器(ops_settings_handler.go)
      - 新增 WebSocket 处理器(ops_ws_handler.go)
      - 扩展设置 DTO 支持 ops 配置
      - 新增客户端请求 ID 中间件(client_request_id.go)
      - 新增 WebSocket 查询令牌认证中间件(ws_query_token_auth.go)
      - 更新管理员认证中间件支持 ops 路由
      - 注册 handler 依赖注入
      f3ed95d4
  17. 04 Jan, 2026 2 commits
    • yangjianbo's avatar
      fix(后端): 修复 lint 失败并清理无用代码 · 5dd8b880
      yangjianbo authored
      修正测试中的 APIKey 名称引用
      移除不可达返回与未使用函数
      统一 gofmt 格式并处理 Close 错误
      5dd8b880
    • IanShaw027's avatar
      fix(lint): 修复所有 Go 命名规范问题 · a4953785
      IanShaw027 authored
      - 全局替换 ApiKey → APIKey(类型、字段、方法、变量)
      - 修复所有 initialism 命名(API, SMTP, HTML, URL 等)
      - 添加所有缺失的包注释
      - 修复导出符号的注释格式
      
      主要修改:
      - ApiKey → APIKey(所有出现的地方)
      - ApiKeyID → APIKeyID
      - ApiKeyIDs → APIKeyIDs
      - TestSmtpConnection → TestSMTPConnection
      - HtmlURL → HTMLURL
      - 添加 20+ 个包注释
      - 修复 10+ 个导出符号注释格式
      
      验证结果:
      - ✓ golangci-lint: 0 issues
      - ✓ 单元测试: 通过
      - ✓ 集成测试: 通过
      a4953785
  18. 03 Jan, 2026 2 commits
    • ianshaw's avatar
      chore: 更新依赖、配置和代码生成 · 112a2d08
      ianshaw authored
      主要更新:
      - 更新 go.mod/go.sum 依赖
      - 重新生成 Ent ORM 代码
      - 更新 Wire 依赖注入配置
      - 添加 docker-compose.override.yml 到 .gitignore
      - 更新 README 文档(Simple Mode 说明和已知问题)
      - 清理调试日志
      - 其他代码优化和格式修复
      112a2d08
    • ianshaw's avatar
      refactor: 移除 Ops 监控模块 · df1ef3de
      ianshaw authored
      移除未完成的运维监控功能,简化系统架构:
      - 删除 ops_handler, ops_service, ops_repo 等后端代码
      - 删除 ops 相关数据库迁移文件
      - 删除前端 OpsDashboard 页面和 API
      df1ef3de
  19. 02 Jan, 2026 1 commit
    • IanShaw's avatar
      运维监控系统安全加固和功能优化 (#21) · 45bd9ac7
      IanShaw authored
      * fix(ops): 修复运维监控系统的关键安全和稳定性问题
      
      ## 修复内容
      
      ### P0 严重问题
      1. **DNS Rebinding防护** (ops_alert_service.go)
         - 实现IP钉住机制防止验证后的DNS rebinding攻击
         - 自定义Transport.DialContext强制只允许拨号到验证过的公网IP
         - 扩展IP黑名单,包括云metadata地址(169.254.169.254)
         - 添加完整的单元测试覆盖
      
      2. **OpsAlertService生命周期管理** (wire.go)
         - 在ProvideOpsMetricsCollector中添加opsAlertService.Start()调用
         - 确保stopCtx正确初始化,避免nil指针问题
         - 实现防御式启动,保证服务启动顺序
      
      3. **数据库查询排序** (ops_repo.go)
         - 在ListRecentSystemMetrics中添加显式ORDER BY updated_at DESC, id DESC
         - 在GetLatestSystemMetric中添加排序保证
         - 避免数据库返回顺序不确定导致告警误判
      
      ### P1 重要问题
      4. **并发安全** (ops_metrics_collector.go)
         - 为lastGCPauseTotal字段添加sync.Mutex保护
         - 防止数据竞争
      
      5. **Goroutine泄漏** (ops_error_logger.go)
         - 实现worker pool模式限制并发goroutine数量
         - 使用256容量缓冲队列和10个固定worker
         - 非阻塞投递,队列满时丢弃任务
      
      6. **生命周期控制** (ops_alert_service.go)
         - 添加Start/Stop方法实现优雅关闭
         - 使用context控制goroutine生命周期
         - 实现WaitGroup等待后台任务完成
      
      7. **Webhook URL验证** (ops_alert_service.go)
         - 防止SSRF攻击:验证scheme、禁止内网IP
         - DNS解析验证,拒绝解析到私有IP的域名
         - 添加8个单元测试覆盖各种攻击场景
      
      8. **资源泄漏** (ops_repo.go)
         - 修复多处defer rows.Close()问题
         - 简化冗余的defer func()包装
      
      9. **HTTP超时控制** (ops_alert_service.go)
         - 创建带10秒超时的http.Client
         - 添加buildWebhookHTTPClient辅助函数
         - 防止HTTP请求无限期挂起
      
      10. **数据库查询优化** (ops_repo.go)
          - 将GetWindowStats的4次独立查询合并为1次CTE查询
          - 减少网络往返和表扫描次数
          - 显著提升性能
      
      11. **重试机制** (ops_alert_service.go)
          - 实现邮件发送重试:最多3次,指数退避(1s/2s/4s)
          - 添加webhook备用通道
          - 实现完整的错误处理和日志记录
      
      12. **魔法数字** (ops_repo.go, ops_metrics_collector.go)
          - 提取硬编码数字为有意义的常量
          - 提高代码可读性和可维护性
      
      ## 测试验证
      -  go test ./internal/service -tags opsalert_unit 通过
      -  所有webhook验证测试通过
      -  重试机制测试通过
      
      ## 影响范围
      - 运维监控系统安全性显著提升
      - 系统稳定性和性能优化
      - 无破坏性变更,向后兼容
      
      * feat(ops): 运维监控系统V2 - 完整实现
      
      ## 核心功能
      - 运维监控仪表盘V2(实时监控、历史趋势、告警管理)
      - WebSocket实时QPS/TPS监控(30s心跳,自动重连)
      - 系统指标采集(CPU、内存、延迟、错误率等)
      - 多维度统计分析(按provider、model、user等维度)
      - 告警规则管理(阈值配置、通知渠道)
      - 错误日志追踪(详细错误信息、堆栈跟踪)
      
      ## 数据库Schema (Migration 025)
      ### 扩展现有表
      - ops_system_metrics: 新增RED指标、错误分类、延迟指标、资源指标、业务指标
      - ops_alert_rules: 新增JSONB字段(dimension_filters, notify_channels, notify_config)
      
      ### 新增表
      - ops_dimension_stats: 多维度统计数据
      - ops_data_retention_config: 数据保留策略配置
      
      ### 新增视图和函数
      - ops_latest_metrics: 最新1分钟窗口指标(已修复字段名和window过滤)
      - ops_active_alerts: 当前活跃告警(已修复字段名和状态值)
      - calculate_health_score: 健康分数计算函数
      
      ## 一致性修复(98/100分)
      ### P0级别(阻塞Migration)
      -  修复ops_latest_metrics视图字段名(latency_p99→p99_latency_ms, cpu_usage→cpu_usage_percent)
      -  修复ops_active_alerts视图字段名(metric→metric_type, triggered_at→fired_at, trigger_value→metric_value, threshold→threshold_value)
      -  统一告警历史表名(删除ops_alert_history,使用ops_alert_events)
      -  统一API参数限制(ListMetricsHistory和ListErrorLogs的limit改为5000)
      
      ### P1级别(功能完整性)
      -  修复ops_latest_metrics视图未过滤window_minutes(添加WHERE m.window_minutes = 1)
      -  修复数据回填UPDATE逻辑(QPS计算改为request_count/(window_minutes*60.0))
      -  添加ops_alert_rules JSONB字段后端支持(Go结构体+序列化)
      
      ### P2级别(优化)
      -  前端WebSocket自动重连(指数退避1s→2s→4s→8s→16s,最大5次)
      -  后端WebSocket心跳检测(30s ping,60s pong超时)
      
      ## 技术实现
      ### 后端 (Go)
      - Handler层: ops_handler.go(REST API), ops_ws_handler.go(WebSocket)
      - Service层: ops_service.go(核心逻辑), ops_cache.go(缓存), ops_alerts.go(告警)
      - Repository层: ops_repo.go(数据访问), ops.go(模型定义)
      - 路由: admin.go(新增ops相关路由)
      - 依赖注入: wire_gen.go(自动生成)
      
      ### 前端 (Vue3 + TypeScript)
      - 组件: OpsDashboardV2.vue(仪表盘主组件)
      - API: ops.ts(REST API + WebSocket封装)
      - 路由: index.ts(新增/admin/ops路由)
      - 国际化: en.ts, zh.ts(中英文支持)
      
      ## 测试验证
      -  所有Go测试通过
      -  Migration可正常执行
      -  WebSocket连接稳定
      -  前后端数据结构对齐
      
      * refactor: 代码清理和测试优化
      
      ## 测试文件优化
      - 简化integration test fixtures和断言
      - 优化test helper函数
      - 统一测试数据格式
      
      ## 代码清理
      - 移除未使用的代码和注释
      - 简化concurrency_cache实现
      - 优化middleware错误处理
      
      ## 小修复
      - 修复gateway_handler和openai_gateway_handler的小问题
      - 统一代码风格和格式
      
      变更统计: 27个文件,292行新增,322行删除(净减少30行)
      
      * fix(ops): 运维监控系统安全加固和功能优化
      
      ## 安全增强
      - feat(security): WebSocket日志脱敏机制,防止token/api_key泄露
      - feat(security): X-Forwarded-Host白名单验证,防止CSRF绕过
      - feat(security): Origin策略配置化,支持strict/permissive模式
      - feat(auth): WebSocket认证支持query参数传递token
      
      ## 配置优化
      - feat(config): 支持环境变量配置代理信任和Origin策略
        - OPS_WS_TRUST_PROXY
        - OPS_WS_TRUSTED_PROXIES
        - OPS_WS_ORIGIN_POLICY
      - fix(ops): 错误日志查询限流从5000降至500,优化内存使用
      
      ## 架构改进
      - refactor(ops): 告警服务解耦,独立运行评估定时器
      - refactor(ops): OpsDashboard统一版本,移除V2分离
      
      ## 测试和文档
      - test(ops): 添加WebSocket安全验证单元测试(8个测试用例)
      - test(ops): 添加告警服务集成测试
      - docs(api): 更新API文档,标注限流变更
      - docs: 添加CHANGELOG记录breaking changes
      
      ## 修复文件
      Backend:
      - backend/internal/server/middleware/logger.go
      - backend/internal/handler/admin/ops_handler.go
      - backend/internal/handler/admin/ops_ws_handler.go
      - backend/internal/server/middleware/admin_auth.go
      - backend/internal/service/ops_alert_service.go
      - backend/internal/service/ops_metrics_collector.go
      - backend/internal/service/wire.go
      
      Frontend:
      - frontend/src/views/admin/ops/OpsDashboard.vue
      - frontend/src/router/index.ts
      - frontend/src/api/admin/ops.ts
      
      Tests:
      - backend/internal/handler/admin/ops_ws_handler_test.go (新增)
      - backend/internal/service/ops_alert_service_integration_test.go (新增)
      
      Docs:
      - CHANGELOG.md (新增)
      - docs/API-运维监控中心2.0.md (更新)
      
      * fix(migrations): 修复calculate_health_score函数类型匹配问题
      
      在ops_latest_metrics视图中添加显式类型转换,确保参数类型与函数签名匹配
      
      * fix(lint): 修复golangci-lint检查发现的所有问题
      
      - 将Redis依赖从service层移到repository层
      - 添加错误检查(WebSocket连接和读取超时)
      - 运行gofmt格式化代码
      - 添加nil指针检查
      - 删除未使用的alertService字段
      
      修复问题:
      - depguard: 3个(service层不应直接import redis)
      - errcheck: 3个(未检查错误返回值)
      - gofmt: 2个(代码格式问题)
      - staticcheck: 4个(nil指针解引用)
      - unused: 1个(未使用字段)
      
      代码统计:
      - 修改文件:11个
      - 删除代码:490行
      - 新增代码:105行
      - 净减少:385行
      45bd9ac7