fix(chat): 优化后台限流与 SSE 日志
This commit is contained in:
@@ -108,16 +108,25 @@ func isPaymentNotifyPath(path string) bool {
|
||||
}
|
||||
|
||||
// shouldSkipHTTPLog 判断是否为无需记录的普通请求。
|
||||
func shouldSkipHTTPLog(_, _ string, status int, latencyMs float64) bool {
|
||||
func shouldSkipHTTPLog(path, route string, status int, latencyMs float64) bool {
|
||||
if status >= 500 || status == http.StatusTooManyRequests {
|
||||
return false
|
||||
}
|
||||
// SSE 的请求耗时就是连接存活时间,由 chathub 单独记录连接生命周期。
|
||||
if isChatSSEPath(path, route) {
|
||||
return true
|
||||
}
|
||||
if latencyMs >= slowRequestThresholdMs {
|
||||
return false
|
||||
}
|
||||
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 meaningfulAuthFailure(c *gin.Context) bool {
|
||||
value, ok := c.Get(ContextAuthFailureReason)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user