diff --git a/xdssuite/retry.go b/xdssuite/retry.go index 2c9d20e..99545b4 100644 --- a/xdssuite/retry.go +++ b/xdssuite/retry.go @@ -21,6 +21,7 @@ import ( "sync/atomic" "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/pkg/klog" "github.com/cloudwego/kitex/pkg/retry" "github.com/cloudwego/kitex/pkg/rpcinfo" @@ -98,6 +99,7 @@ func updateRetryPolicy(rc *retrySuit, res map[string]xdsresource.Resource) { } if wildcarRetryPolicy == nil { + klog.Debugf("[XDS] retry policy is empty, disable it, res number %v", len(res)) wildcarRetryPolicy = &retry.Policy{ Enable: false, } diff --git a/xdssuite/retry_test.go b/xdssuite/retry_test.go index 401d8fe..49c21e6 100644 --- a/xdssuite/retry_test.go +++ b/xdssuite/retry_test.go @@ -44,6 +44,13 @@ func TestRetry(t *testing.T) { r := &retrySuit{ Container: retry.NewRetryContainer(), } + updateRetryPolicy(r, map[string]xdsresource.Resource{}) + + assert.Equal(t, newContainer(map[string]retry.Policy{ + wildcardRetryKey: { + Enable: false, + }, + }), dump(r.Dump())) updateRetryPolicy(r, map[string]xdsresource.Resource{ "1": &xdsresource.RouteConfigResource{ @@ -148,6 +155,24 @@ func TestRetry(t *testing.T) { }, }, }, + wildcardRetryKey: { + Enable: true, + Type: retry.FailureType, + FailurePolicy: &retry.FailurePolicy{ + RetrySameNode: false, + StopPolicy: retry.StopPolicy{ + MaxRetryTimes: 3, + MaxDurationMS: 1000, + }, + BackOffPolicy: &retry.BackOffPolicy{ + BackOffType: retry.RandomBackOffType, + CfgItems: map[retry.BackOffCfgKey]float64{ + retry.MaxMSBackOffCfgKey: 2000, + retry.MinMSBackOffCfgKey: 1000, + }, + }, + }, + }, }), dump(r.Dump())) updateRetryPolicy(r, map[string]xdsresource.Resource{ @@ -189,5 +214,19 @@ func TestRetry(t *testing.T) { }, }, }, + wildcardRetryKey: { + Enable: true, + Type: retry.FailureType, + FailurePolicy: &retry.FailurePolicy{ + RetrySameNode: false, + StopPolicy: retry.StopPolicy{ + MaxRetryTimes: 2, + MaxDurationMS: 5000, + }, + BackOffPolicy: &retry.BackOffPolicy{ + BackOffType: retry.NoneBackOffType, + }, + }, + }, }), dump(r.Dump())) }