From 3f3fccd01a96594cbf1e54f90bf42e42f1b06ee6 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 24 Feb 2016 16:45:41 -0700 Subject: [PATCH] Add the option to only query for services that are passing health checks. --- .../cloud/consul/discovery/ConsulDiscoveryClient.java | 2 +- .../cloud/consul/discovery/ConsulDiscoveryProperties.java | 6 ++++++ .../cloud/consul/discovery/ConsulServerList.java | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java index 1a44895e..2dc23ea0 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java @@ -110,7 +110,7 @@ public class ConsulDiscoveryClient implements DiscoveryClient { private void addInstancesToList(List instances, String serviceId) { Response> services = client.getHealthServices(serviceId, - false, QueryParams.DEFAULT); + this.properties.isQueryPassing(), QueryParams.DEFAULT); for (HealthService service : services.getValue()) { String host = findHost(service); instances.add(new DefaultServiceInstance(serviceId, host, service diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryProperties.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryProperties.java index 7318ecab..987fcb1d 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryProperties.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryProperties.java @@ -114,6 +114,12 @@ public class ConsulDiscoveryProperties { */ private Map serverListQueryTags = new HashMap<>(); + /** + * Add the 'passing` parameter to /v1/health/service/serviceName. + * This pushes health check passing to the server. + */ + private boolean queryPassing = false; + @SuppressWarnings("unused") private ConsulDiscoveryProperties() {} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java index bceccad9..ad70ef08 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java @@ -58,12 +58,13 @@ public class ConsulServerList extends AbstractServerList { } private List getServers() { - if (client == null) { + if (this.client == null) { return Collections.emptyList(); } String tag = getTag(); // null is ok - Response> response = client.getHealthServices( - this.serviceId, tag, false, QueryParams.DEFAULT); + Response> response = this.client.getHealthServices( + this.serviceId, tag, this.properties.isQueryPassing(), + QueryParams.DEFAULT); if (response.getValue() == null || response.getValue().isEmpty()) { return Collections.emptyList(); }