fix(observability): 治理SSE慢请求虚报、客户端取消日志污染、退款重试刷屏与会话计数慢查询
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user