This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch 1.3.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/1.3.x by this push:
     new 3d39396  [SCB-2136]TESTING status microservice instances are counted 
as latest version (#2113)
3d39396 is described below

commit 3d39396168396f571e772f3c1a49cf167f6f79bc
Author: bao liu <bi...@qq.com>
AuthorDate: Thu Dec 10 09:14:05 2020 +0800

    [SCB-2136]TESTING status microservice instances are counted as latest 
version (#2113)
---
 .../serviceregistry/config/ServiceRegistryConfig.java      |  8 ++++++++
 .../serviceregistry/consumer/MicroserviceVersions.java     | 14 +++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
index 935e809..fd38552 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
@@ -249,6 +249,14 @@ public final class ServiceRegistryConfig {
     return property.get();
   }
 
+  public boolean useUpInstancesOnly() {
+    DynamicBooleanProperty property =
+        DynamicPropertyFactory.getInstance()
+            
.getBooleanProperty("servicecomb.service.registry.instance.useUpInstancesOnly",
+                false);
+    return property.get();
+  }
+
   public boolean isAlwaysOverrideSchema() {
     DynamicBooleanProperty property =
         DynamicPropertyFactory.getInstance()
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
index 16bce48..daec2f6 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
@@ -22,12 +22,14 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import org.apache.servicecomb.serviceregistry.api.Const;
 import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
 import 
org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
 import 
org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
 import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
@@ -164,7 +166,17 @@ public class MicroserviceVersions {
 
   protected void safeSetInstances(List<MicroserviceInstance> pulledInstances, 
String rev) {
     try {
-      setInstances(pulledInstances, rev);
+      List<MicroserviceInstance> filteredInstance = pulledInstances;
+      // 增加一个配置项只使用 `UP` 实例。 在使用 `TESTING` 进行拨测, 并且配置了
+      // servicecomb.references.version-rule=latest 场景,需要保证不使用
+      // `TESTING` 实例。 不能依赖 InstanceStatusDiscoveryFilter, 避免
+      // 构建的 VersionRule 实例列表为空。
+      if (ServiceRegistryConfig.INSTANCE.useUpInstancesOnly()) {
+        filteredInstance = pulledInstances.stream().filter(item -> 
MicroserviceInstanceStatus.UP == item.getStatus())
+            .collect(Collectors.toList());
+      }
+      setInstances(filteredInstance, rev);
+
       validated = true;
     } catch (Throwable e) {
       LOGGER.error("Failed to setInstances, appId={}, microserviceName={}.",

Reply via email to