refactor(ops): 重构ops核心服务层代码
This commit is contained in:
@@ -236,7 +236,68 @@ func (s *OpsService) GetErrorLogs(ctx context.Context, filter *OpsErrorLogFilter
|
||||
if s.opsRepo == nil {
|
||||
return &OpsErrorLogList{Errors: []*OpsErrorLog{}, Total: 0, Page: 1, PageSize: 20}, nil
|
||||
}
|
||||
return s.opsRepo.ListErrorLogs(ctx, filter)
|
||||
result, err := s.opsRepo.ListErrorLogs(ctx, filter)
|
||||
if err != nil {
|
||||
log.Printf("[Ops] GetErrorLogs failed: %v", err)
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user