From 1cc4bcccfc6e8dfa3b330b2adb16862791ddc9d9 Mon Sep 17 00:00:00 2001 From: Xuewei Niu Date: Sat, 12 Feb 2022 23:29:22 +0800 Subject: [PATCH] fix(adasvc): do not use adaptive service filter if disabled on the client side (#1748) --- cluster/cluster/adaptivesvc/cluster_invoker.go | 1 + common/constant/key.go | 3 +++ filter/adaptivesvc/filter.go | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/cluster/cluster/adaptivesvc/cluster_invoker.go b/cluster/cluster/adaptivesvc/cluster_invoker.go index e4fb479cfe..d54cd15eec 100644 --- a/cluster/cluster/adaptivesvc/cluster_invoker.go +++ b/cluster/cluster/adaptivesvc/cluster_invoker.go @@ -66,6 +66,7 @@ func (ivk *adaptiveServiceClusterInvoker) Invoke(ctx context.Context, invocation invoker := lb.Select(invokers, invocation) // invoke + invocation.SetAttachment(constant.AdaptiveServiceEnabledKey, constant.AdaptiveServiceIsEnabled) result := invoker.Invoke(ctx, invocation) // if the adaptive service encounters an error, DO NOT diff --git a/common/constant/key.go b/common/constant/key.go index 2e27f1df94..fdd9359122 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -380,4 +380,7 @@ const ( // attachment keys AdaptiveServiceRemainingKey = "adaptive-service.remaining" AdaptiveServiceInflightKey = "adaptive-service.inflight" + AdaptiveServiceEnabledKey = "adaptive-service.enabled" + // enabled value + AdaptiveServiceIsEnabled = "1" ) diff --git a/filter/adaptivesvc/filter.go b/filter/adaptivesvc/filter.go index 13652086b9..06bd0e2152 100644 --- a/filter/adaptivesvc/filter.go +++ b/filter/adaptivesvc/filter.go @@ -64,6 +64,11 @@ func newAdaptiveServiceProviderFilter() filter.Filter { func (f *adaptiveServiceProviderFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { + if invocation.GetAttachmentWithDefaultValue(constant.AdaptiveServiceEnabledKey, "") != + constant.AdaptiveServiceIsEnabled { + // the adaptive service is enabled on the invocation + return invoker.Invoke(ctx, invocation) + } l, err := limiterMapperSingleton.getMethodLimiter(invoker.GetURL(), invocation.MethodName()) if err != nil { @@ -91,6 +96,10 @@ func (f *adaptiveServiceProviderFilter) Invoke(ctx context.Context, invoker prot func (f *adaptiveServiceProviderFilter) OnResponse(_ context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { + if result.Attachment(constant.AdaptiveServiceEnabledKey, "") != constant.AdaptiveServiceIsEnabled { + // the adaptive service is enabled on the invocation + return result + } if isErrAdaptiveSvcInterrupted(result.Error()) { // If the Invoke method of the adaptiveServiceProviderFilter returns an error,