Skip to content

Commit

Permalink
fix(adasvc): do not use adaptive service filter if disabled on the cl…
Browse files Browse the repository at this point in the history
…ient side (#1748)
  • Loading branch information
justxuewei authored Feb 12, 2022
1 parent 74eb62e commit 1cc4bcc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions cluster/cluster/adaptivesvc/cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,7 @@ const (
// attachment keys
AdaptiveServiceRemainingKey = "adaptive-service.remaining"
AdaptiveServiceInflightKey = "adaptive-service.inflight"
AdaptiveServiceEnabledKey = "adaptive-service.enabled"
// enabled value
AdaptiveServiceIsEnabled = "1"
)
9 changes: 9 additions & 0 deletions filter/adaptivesvc/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1cc4bcc

Please sign in to comment.