feat(audit): 请求审计中新增不同账号调度详情、完整HTTP请求/响应报文、默认7天全量日志记录等完整诊断生命周期重要功能 - #983
Conversation
…nd fix audit detail inspection
…t log retention settings
|
@chenyme 能合并一下吗 这个功能非常重要 我每天都在使用... |
# Conflicts: # backend/internal/transport/http/inference/handler.go
SummaryImprove the request audit system with privacy-safe request metadata, per-account scheduling diagnostics, bounded failure details, configurable retention, and a redesigned admin audit view. The implementation deliberately avoids persisting user prompts and successful model output. It focuses on the information operators need to diagnose routing, account selection, upstream failures, and interrupted streams without turning the audit database into a full traffic archive. What changedRequest metadataRequest audits now record bounded and sanitized metadata:
Query strings are stripped before persistence. Headers related to authorization, cookies, credentials, API keys, tokens, sessions, signatures, and passwords are stored as Per-attempt upstream diagnosticsEach failed scheduling or upstream attempt can now be inspected independently, including:
Failures that occur after an upstream Diagnostic storage is bounded to:
Retention and cleanupAdd an independent audit retention policy:
The cleanup implementation works across SQLite, MySQL, and PostgreSQL. Admin UIRedesign the audit detail dialog around three focused views:
Additional UI improvements include:
Data policyStored
Not stored
What was removed and whyFull request-body captureThe original implementation persisted complete client request bodies. This was removed because request bodies may contain prompts, conversation history, private files, images, audio, credentials, and large base64 payloads. Persisting them would introduce substantial privacy, security, compliance, and database-growth risks. Request metadata and sanitized headers are sufficient for routing and connectivity diagnosis. Successful response-body and SSE persistenceSuccessful response bodies and reconstructed SSE output are no longer stored. They duplicate content already delivered to the client, can be extremely large, and would make normal successful traffic the main source of database growth. Failure diagnostics provide more operational value at a much lower storage cost. SSE response reconstructionThe protocol-specific SSE accumulator and response reconstruction logic were removed after successful response persistence was dropped. Keeping this code would add memory usage and maintenance complexity while risking incorrectly reconstructed Responses, Chat Completions, and Anthropic Messages payloads. Body-recording settingsThe following settings and UI controls were removed:
Optional body recording would create ambiguous security expectations and could be accidentally enabled in production. The audit policy is now explicit and consistent: metadata for all requests, bounded response excerpts for failures only. Query-string persistenceOnly the request path is retained. Query strings may contain signed URLs, temporary tokens, credentials, or user-provided data. They are unnecessary for identifying the API operation being audited. Request/response payload tabsThe full payload tabs and copy actions were removed because the backend no longer exposes or persists those bodies. Leaving them in the interface would imply that sensitive payload capture is supported. Unrelated repository changesThe following unrelated changes from the original branch were removed to keep the PR focused:
Compatibility
Validation
|
…me#989 thinking-hold / chenyme#983 audit,保留 Console team 熔断)
📌 概述 (Overview)
完善网关请求审计体系,提供客户端完整请求报文、服务端响应报文(含 SSE 流式自动重组)的持久化与可视化诊断能力,修复上游流式中断时的尝试诊断记录,并新增跨数据库兼容的日志保留策略与独立设置面板。
✨ 主要功能与变更 (Features & Improvements)
1. 客户端完整 HTTP 请求报文捕获与查看
2. 服务端响应报文捕获与 SSE 流式自动组包
3. 修复上游流式中断诊断回溯
200 OK响应头但随后中途断开(如upstream_stream_interrupted/upstream_stream_incomplete)时,网关未记录尝试诊断导致后台显示“在发送到上游前失败”的问题。response_stream诊断快照,准确记录所调用的账号、节点、状态码及底层网络 Transport 错误。4. 独立「日志设置」面板与定时自动清理
retentionDays):支持自由配置日志保留时长(默认 7 天,设为 0 永久保留)。recordRequestBody(记录请求体)与recordResponseBody(记录响应体)独立开关。🔍 影响与兼容性 (Compatibility)
response_body字段,跨 SQLite / MySQL / PostgreSQL 存储源无缝兼容。go test ./...)与前端静态类型编译(npm run build)均 100% 通过。