fix(observability): 治理SSE慢请求虚报、客户端取消日志污染、退款重试刷屏与会话计数慢查询

This commit is contained in:
yml2213
2026-09-10 20:02:54 +08:00
parent ee0e70ccad
commit 784ffb5f72
7 changed files with 24 additions and 8 deletions
+11 -4
View File
@@ -1,6 +1,8 @@
package middleware
import (
"context"
"errors"
"net/http"
"strings"
"time"
@@ -72,6 +74,10 @@ func RequestLogger(logger *zap.Logger) gin.HandlerFunc {
}
switch {
case errors.Is(c.Request.Context().Err(), context.Canceled):
if logger.Core().Enabled(zap.DebugLevel) {
logger.Debug("HTTP 客户端中断连接", fields...)
}
case status >= 500:
logger.Error("HTTP 请求失败", fields...)
case status == http.StatusTooManyRequests:
@@ -113,7 +119,7 @@ func shouldSkipHTTPLog(path, route string, status int, latencyMs float64) bool {
return false
}
// SSE 的请求耗时就是连接存活时间,由 chathub 单独记录连接生命周期。
if isChatSSEPath(path, route) {
if isSSEPath(path, route) {
return true
}
if latencyMs >= slowRequestThresholdMs {
@@ -122,9 +128,10 @@ func shouldSkipHTTPLog(path, route string, status int, latencyMs float64) bool {
return true
}
func isChatSSEPath(path, route string) bool {
return path == "/api/chats/events" || path == "/api/admin/chats/events" ||
route == "/api/chats/events" || route == "/api/admin/chats/events"
func isSSEPath(path, route string) bool {
return path == "/api/auth/events" || route == "/api/auth/events" ||
path == "/api/chats/events" || route == "/api/chats/events" ||
path == "/api/admin/chats/events" || route == "/api/admin/chats/events"
}
func meaningfulAuthFailure(c *gin.Context) bool {