优化mesh请求

This commit is contained in:
2025-04-16 22:02:53 +08:00
parent 834ce55f26
commit 1a55576e10
2 changed files with 6 additions and 9 deletions

View File

@ -173,9 +173,12 @@ func (c *client) doRequest(apiList []*RequestConfigGroupItem) bool {
c.resp.Lock.Lock()
defer c.resp.Lock.Unlock()
if !resp.IsSuccess {
// 哪些接口请求失败: 注意,接口请求失败不代表整体失败,接口可能针对失败配置规则 continue
c.resp.FailApiAlias = append(c.resp.FailApiAlias, apiCfg.Alias)
// 判断是否已经是最终失败
if apiCfg.FailBehavior.FinalFailure || apiCfg.FailBehavior.Action == FailBehaviorError {
if apiCfg.FailBehavior.Action == FailBehaviorError {
c.resp.FinalFailure = true
c.resp.FailureApiAlias = apiCfg.Alias // 导致最终请求失败的接口
// 判断是否继续, 只能阻断后续分组请求,无法阻断当前租的请求
isContinue = FailBehaviorContinue == apiCfg.FailBehavior.Action
}
@ -191,14 +194,9 @@ func (c *client) doRequest(apiList []*RequestConfigGroupItem) bool {
func (c *client) initApiCfg(apiCfg *RequestConfigGroupItem) {
if apiCfg.FailBehavior == nil {
apiCfg.FailBehavior = &RequestConfigGroupItemFailBehavior{
Action: FailBehaviorError, // 默认失败终止请求
FinalFailure: true, // 默认一旦失败,则争个整个失败
Action: FailBehaviorError, // 默认失败终止请求
}
}
if apiCfg.FailBehavior.Action == FailBehaviorError {
// 配置了请求失败则报错, 一定是导致结果最终失败
apiCfg.FailBehavior.FinalFailure = true
}
// 每一个请求有独立的context
apiCfg.RequestCfg.Ctx = context.WithValue(c.reqCfg.Ctx, "alias", apiCfg.Alias)
}