@@ -83,8 +83,15 @@ func (p *KeyProvider) UpdateStatus(apiKey *models.APIKey, group *models.Group, i
8383 logrus .WithFields (logrus.Fields {"keyID" : apiKey .ID , "error" : err }).Error ("Failed to handle key success" )
8484 }
8585 } else {
86- if err := p .handleFailure (apiKey , group , keyHashKey , activeKeysListKey , errorMessage ); err != nil {
87- logrus .WithFields (logrus.Fields {"keyID" : apiKey .ID , "error" : err }).Error ("Failed to handle key failure" )
86+ if app_errors .IsUnCounted (errorMessage ) {
87+ logrus .WithFields (logrus.Fields {
88+ "keyID" : apiKey .ID ,
89+ "error" : errorMessage ,
90+ }).Debug ("Uncounted error, skipping failure handling" )
91+ } else {
92+ if err := p .handleFailure (apiKey , group , keyHashKey , activeKeysListKey ); err != nil {
93+ logrus .WithFields (logrus.Fields {"keyID" : apiKey .ID , "error" : err }).Error ("Failed to handle key failure" )
94+ }
8895 }
8996 }
9097 }()
@@ -117,29 +124,6 @@ func (p *KeyProvider) executeTransactionWithRetry(operation func(tx *gorm.DB) er
117124 return err
118125}
119126
120- // shouldCountFailure 判断错误是否应该计入失败次数
121- func (p * KeyProvider ) shouldCountFailure (errorMsg string ) bool {
122- if errorMsg == "" {
123- return true // 没有错误信息时默认计数
124- }
125-
126- // 转换为小写进行匹配
127- errorLower := strings .ToLower (errorMsg )
128-
129- // 不计入失败次数的错误模式
130- excludePatterns := []string {
131- "resource has been exhausted (e.g. check quota)." , // Resource has been exhausted (e.g. check quota).
132- }
133-
134- for _ , pattern := range excludePatterns {
135- if strings .Contains (errorLower , pattern ) {
136- return false
137- }
138- }
139-
140- return true // 其他错误计入失败次数
141- }
142-
143127func (p * KeyProvider ) handleSuccess (keyID uint , keyHashKey , activeKeysListKey string ) error {
144128 keyDetails , err := p .store .HGetAll (keyHashKey )
145129 if err != nil {
@@ -186,7 +170,7 @@ func (p *KeyProvider) handleSuccess(keyID uint, keyHashKey, activeKeysListKey st
186170 })
187171}
188172
189- func (p * KeyProvider ) handleFailure (apiKey * models.APIKey , group * models.Group , keyHashKey , activeKeysListKey string , errorMessage string ) error {
173+ func (p * KeyProvider ) handleFailure (apiKey * models.APIKey , group * models.Group , keyHashKey , activeKeysListKey string ) error {
190174 keyDetails , err := p .store .HGetAll (keyHashKey )
191175 if err != nil {
192176 return fmt .Errorf ("failed to get key details from store: %w" , err )
@@ -198,16 +182,6 @@ func (p *KeyProvider) handleFailure(apiKey *models.APIKey, group *models.Group,
198182
199183 failureCount , _ := strconv .ParseInt (keyDetails ["failure_count" ], 10 , 64 )
200184
201- // 判断是否应该计入失败次数
202- shouldCount := p .shouldCountFailure (errorMessage )
203- if ! shouldCount {
204- logrus .WithFields (logrus.Fields {
205- "keyID" : apiKey .ID ,
206- "errorMessage" : errorMessage ,
207- }).Debug ("Error not counted towards failure threshold" )
208- return nil // 不计入失败次数,直接返回
209- }
210-
211185 // 获取该分组的有效配置
212186 blacklistThreshold := group .EffectiveConfig .BlacklistThreshold
213187
0 commit comments