[SCB-2628] remove invocation context for governance (#3167)

diff --git a/core/src/main/java/org/apache/servicecomb/core/governance/ServiceCombInvocationContext.java b/core/src/main/java/org/apache/servicecomb/core/governance/ServiceCombInvocationContext.java
deleted file mode 100644
index 38c1243..0000000
--- a/core/src/main/java/org/apache/servicecomb/core/governance/ServiceCombInvocationContext.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.core.governance;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.servicecomb.governance.InvocationContext;
-import org.springframework.stereotype.Component;
-
-@Component
-public class ServiceCombInvocationContext implements InvocationContext {
-  private static final String CONTEXT_KEY = "x-servicecomb-governance-match";
-
-  private static final ThreadLocal<org.apache.servicecomb.swagger.invocation.context.InvocationContext> contextMgr = new ThreadLocal<>();
-
-  public static void setInvocationContext(
-      org.apache.servicecomb.swagger.invocation.context.InvocationContext invocationContext) {
-    contextMgr.set(invocationContext);
-  }
-
-  public static void removeInvocationContext() {
-    contextMgr.remove();
-  }
-
-  @Override
-  public Map<String, Boolean> getCalculatedMatches() {
-    Map<String, Boolean> result = contextMgr.get().getLocalContext(CONTEXT_KEY);
-    if (result == null) {
-      return Collections.emptyMap();
-    }
-    return result;
-  }
-
-  @Override
-  public void addMatch(String key, Boolean value) {
-    Map<String, Boolean> result = contextMgr.get().getLocalContext(CONTEXT_KEY);
-    if (result == null) {
-      result = new HashMap<>();
-      contextMgr.get().addLocalContext(CONTEXT_KEY, result);
-    }
-    result.put(key, value);
-  }
-}
diff --git a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
index ac5fd41..a1df058 100644
--- a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
+++ b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
@@ -44,7 +44,6 @@
 import org.apache.servicecomb.core.governance.GovernanceConfiguration;
 import org.apache.servicecomb.core.governance.MatchType;
 import org.apache.servicecomb.core.governance.RetryContext;
-import org.apache.servicecomb.core.governance.ServiceCombInvocationContext;
 import org.apache.servicecomb.core.invocation.InvocationFactory;
 import org.apache.servicecomb.foundation.common.utils.AsyncUtils;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
@@ -193,12 +192,7 @@
   public static Response innerSyncInvoke(Invocation invocation) {
     GovernanceRequest request = MatchType.createGovHttpRequest(invocation);
 
-    try {
-      ServiceCombInvocationContext.setInvocationContext(invocation);
-      return decorateSyncRetry(invocation, request);
-    } finally {
-      ServiceCombInvocationContext.removeInvocationContext();
-    }
+    return decorateSyncRetry(invocation, request);
   }
 
   private static Response innerSyncInvokeImpl(Invocation invocation) throws Throwable {
@@ -314,12 +308,7 @@
     DecorateCompletionStage<Response> dcs = Decorators.ofCompletionStage(next);
     GovernanceRequest request = MatchType.createGovHttpRequest(invocation);
 
-    try {
-      ServiceCombInvocationContext.setInvocationContext(invocation);
-      decorateReactiveRetry(invocation, dcs, request);
-    } finally {
-      ServiceCombInvocationContext.removeInvocationContext();
-    }
+    decorateReactiveRetry(invocation, dcs, request);
 
     dcs.get().whenComplete((r, e) -> {
       if (e == null) {
@@ -415,12 +404,7 @@
     DecorateCompletionStage<Response> dcs = Decorators.ofCompletionStage(next);
     GovernanceRequest request = MatchType.createGovHttpRequest(invocation);
 
-    try {
-      ServiceCombInvocationContext.setInvocationContext(invocation);
-      decorateReactiveRetry(invocation, dcs, request);
-    } finally {
-      ServiceCombInvocationContext.removeInvocationContext();
-    }
+    decorateReactiveRetry(invocation, dcs, request);
 
     CompletableFuture<Response> result = new CompletableFuture<>();
     dcs.get().whenComplete((r, e) -> {
diff --git a/governance/src/main/java/org/apache/servicecomb/governance/GovernanceConfiguration.java b/governance/src/main/java/org/apache/servicecomb/governance/GovernanceConfiguration.java
index f1b0f1e..9679999 100644
--- a/governance/src/main/java/org/apache/servicecomb/governance/GovernanceConfiguration.java
+++ b/governance/src/main/java/org/apache/servicecomb/governance/GovernanceConfiguration.java
@@ -124,8 +124,8 @@
   }
 
   @Bean
-  public MatchersManager matchersManager(MatchersService matchersService, InvocationContext invocationContext) {
-    return new MatchersManager(matchersService, invocationContext);
+  public MatchersManager matchersManager(MatchersService matchersService) {
+    return new MatchersManager(matchersService);
   }
 
   // operators
diff --git a/governance/src/main/java/org/apache/servicecomb/governance/InvocationContext.java b/governance/src/main/java/org/apache/servicecomb/governance/InvocationContext.java
deleted file mode 100644
index 07d03ce..0000000
--- a/governance/src/main/java/org/apache/servicecomb/governance/InvocationContext.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.governance;
-
-import java.util.Map;
-
-public interface InvocationContext {
-  Map<String, Boolean> getCalculatedMatches();
-
-  void addMatch(String key, Boolean value);
-}
diff --git a/governance/src/main/java/org/apache/servicecomb/governance/MatchersManager.java b/governance/src/main/java/org/apache/servicecomb/governance/MatchersManager.java
index 4e9685a..1c84a54 100644
--- a/governance/src/main/java/org/apache/servicecomb/governance/MatchersManager.java
+++ b/governance/src/main/java/org/apache/servicecomb/governance/MatchersManager.java
@@ -27,28 +27,17 @@
 public class MatchersManager {
   private MatchersService matchersService;
 
-  private InvocationContext invocationContext;
-
-  public MatchersManager(MatchersService matchersService, InvocationContext invocationContext) {
+  public MatchersManager(MatchersService matchersService) {
     this.matchersService = matchersService;
-    this.invocationContext = invocationContext;
   }
 
   public <T extends AbstractPolicy> T match(GovernanceRequest request, Map<String, T> policies) {
-    Map<String, Boolean> calculatedMatches = invocationContext.getCalculatedMatches();
-
     List<T> sortPolicies = new ArrayList<>(policies.size());
     sortPolicies.addAll(policies.values());
     sortPolicies.sort(T::compareTo);
 
     for (T policy : sortPolicies) {
-      if (calculatedMatches.containsKey(policy.getName())) {
-        return policy;
-      }
-
-      boolean keyMatch = matchersService.checkMatch(request, policy.getName());
-      invocationContext.addMatch(policy.getName(), keyMatch);
-      if (keyMatch) {
+      if (matchersService.checkMatch(request, policy.getName())) {
         return policy;
       }
     }
diff --git a/governance/src/test/java/org/apache/servicecomb/governance/InstanceIsolationTest.java b/governance/src/test/java/org/apache/servicecomb/governance/InstanceIsolationTest.java
index cd8d317..34847c3 100644
--- a/governance/src/test/java/org/apache/servicecomb/governance/InstanceIsolationTest.java
+++ b/governance/src/test/java/org/apache/servicecomb/governance/InstanceIsolationTest.java
@@ -89,6 +89,7 @@
     GovernanceRequest request2 = new GovernanceRequest();
     request2.setInstanceId("instance02");
     request2.setServiceName("service01");
+    request2.setUri("/test");
 
     CircuitBreaker circuitBreaker2 = instanceIsolationHandler.getActuator(request2);
     ds2.withCircuitBreaker(circuitBreaker2);
diff --git a/governance/src/test/java/org/apache/servicecomb/governance/MockConfiguration.java b/governance/src/test/java/org/apache/servicecomb/governance/MockConfiguration.java
index b9a62d8..7b02816 100644
--- a/governance/src/test/java/org/apache/servicecomb/governance/MockConfiguration.java
+++ b/governance/src/test/java/org/apache/servicecomb/governance/MockConfiguration.java
@@ -26,11 +26,6 @@
 @Configuration
 public class MockConfiguration {
   @Bean
-  public MockInvocationContext mockInvocationContext() {
-    return new MockInvocationContext();
-  }
-
-  @Bean
   public MockMicroserviceMeta mockMicroserviceMeta() {
     return new MockMicroserviceMeta();
   }
diff --git a/governance/src/test/java/org/apache/servicecomb/governance/MockInvocationContext.java b/governance/src/test/java/org/apache/servicecomb/governance/MockInvocationContext.java
deleted file mode 100644
index 7c3e927..0000000
--- a/governance/src/test/java/org/apache/servicecomb/governance/MockInvocationContext.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.governance;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-public class MockInvocationContext implements InvocationContext {
-  private final ThreadLocal<Map<String, Boolean>> context = new ThreadLocal<>();
-
-  @Override
-  public Map<String, Boolean> getCalculatedMatches() {
-    Map<String, Boolean> result = context.get();
-    if (result == null) {
-      return Collections.emptyMap();
-    }
-    return result;
-  }
-
-  @Override
-  public void addMatch(String key, Boolean value) {
-    Map<String, Boolean> result = context.get();
-    if (result == null) {
-      result = new HashMap<>();
-      context.set(result);
-    }
-    result.put(key, value);
-  }
-}
diff --git a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderGovernanceHandler.java b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderGovernanceHandler.java
index 3ae2643..8ae3df8 100644
--- a/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderGovernanceHandler.java
+++ b/handlers/handler-governance/src/main/java/org/apache/servicecomb/handler/governance/ProviderGovernanceHandler.java
@@ -24,7 +24,6 @@
 import org.apache.servicecomb.core.Handler;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.governance.MatchType;
-import org.apache.servicecomb.core.governance.ServiceCombInvocationContext;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.governance.handler.BulkheadHandler;
 import org.apache.servicecomb.governance.handler.CircuitBreakerHandler;
@@ -62,14 +61,9 @@
     DecorateCompletionStage<Response> dcs = Decorators.ofCompletionStage(next);
     GovernanceRequest request = MatchType.createGovHttpRequest(invocation);
 
-    try {
-      ServiceCombInvocationContext.setInvocationContext(invocation);
-      addRateLimiting(dcs, request);
-      addCircuitBreaker(dcs, request);
-      addBulkhead(dcs, request);
-    } finally {
-      ServiceCombInvocationContext.removeInvocationContext();
-    }
+    addRateLimiting(dcs, request);
+    addCircuitBreaker(dcs, request);
+    addBulkhead(dcs, request);
 
     dcs.get().whenComplete((r, e) -> {
       if (e == null) {