fix(ops): 优化错误日志过滤和查询逻辑
后端改动: - 添加 resolved 参数默认值处理(向后兼容,默认显示未解决错误) - 新增 status_codes_other 查询参数支持 - 移除 service 层的高级设置过滤逻辑,简化错误日志查询流程 前端改动: - 完善错误日志相关组件的国际化支持 - 优化 Ops 监控面板和设置对话框的用户体验
This commit is contained in:
@@ -86,12 +86,13 @@ type OpsErrorLogFilter struct {
|
||||
GroupID *int64
|
||||
AccountID *int64
|
||||
|
||||
StatusCodes []int
|
||||
Phase string
|
||||
Owner string
|
||||
Source string
|
||||
Resolved *bool
|
||||
Query string
|
||||
StatusCodes []int
|
||||
StatusCodesOther bool
|
||||
Phase string
|
||||
Owner string
|
||||
Source string
|
||||
Resolved *bool
|
||||
Query string
|
||||
|
||||
// View controls error categorization for list endpoints.
|
||||
// - errors: show actionable errors (exclude business-limited / 429 / 529)
|
||||
|
||||
@@ -261,64 +261,9 @@ func (s *OpsService) GetErrorLogs(ctx context.Context, filter *OpsErrorLogFilter
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Apply error filtering based on settings (for historical data)
|
||||
result = s.filterErrorLogsBySettings(ctx, result)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// filterErrorLogsBySettings filters error logs based on advanced settings.
|
||||
// This ensures that historical errors are also filtered when viewing the dashboard.
|
||||
func (s *OpsService) filterErrorLogsBySettings(ctx context.Context, result *OpsErrorLogList) *OpsErrorLogList {
|
||||
if result == nil || len(result.Errors) == 0 {
|
||||
return result
|
||||
}
|
||||
|
||||
settings, err := s.GetOpsAdvancedSettings(ctx)
|
||||
if err != nil || settings == nil {
|
||||
// If we can't get settings, return unfiltered (fail open)
|
||||
return result
|
||||
}
|
||||
|
||||
filtered := make([]*OpsErrorLog, 0, len(result.Errors))
|
||||
for _, errLog := range result.Errors {
|
||||
if shouldFilterErrorLog(settings, errLog) {
|
||||
continue // Skip this error
|
||||
}
|
||||
filtered = append(filtered, errLog)
|
||||
}
|
||||
|
||||
// Update total count to reflect filtered results
|
||||
result.Errors = filtered
|
||||
result.Total = len(filtered)
|
||||
return result
|
||||
}
|
||||
|
||||
// shouldFilterErrorLog determines if an error log should be filtered based on settings.
|
||||
func shouldFilterErrorLog(settings *OpsAdvancedSettings, errLog *OpsErrorLog) bool {
|
||||
if settings == nil || errLog == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
msgLower := strings.ToLower(errLog.Message)
|
||||
|
||||
// Check if count_tokens errors should be ignored
|
||||
if settings.IgnoreCountTokensErrors && strings.Contains(errLog.RequestPath, "/count_tokens") {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if context canceled errors should be ignored
|
||||
if settings.IgnoreContextCanceled && strings.Contains(msgLower, "context canceled") {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if "no available accounts" errors should be ignored
|
||||
if settings.IgnoreNoAvailableAccounts && strings.Contains(msgLower, "no available accounts") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *OpsService) GetErrorLogByID(ctx context.Context, id int64) (*OpsErrorLogDetail, error) {
|
||||
if err := s.RequireMonitoringEnabled(ctx); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user