Repository navigation
Look up services in their configured datacenter - #1057
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
The discovery docs say that spring.cloud.consul.discovery.datacenters maps a service to the datacenter it is looked up in, for example spring.cloud.consul.discovery.datacenters.STORES=dc-west. The Ribbon server list used to read this map, but nothing has read it since the move to Spring Cloud LoadBalancer. Services in other datacenters could therefore not be found, and the property did nothing. ConsulDiscoveryClient now sets the configured datacenter on the QueryParams it sends for a service, next to the configured consistency mode, the same way the Ribbon server list did. getInstances, getAllInstances, the reactive discovery client and Spring Cloud LoadBalancer all go through this code, so all of them now find services in their configured datacenter. Services without an entry are still looked up in the agent's datacenter. Fixes spring-cloudgh-712 Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The discovery docs say that
spring.cloud.consul.discovery.datacenterssets the datacenter a service is looked up in:spring.cloud.consul.discovery.datacenters.STORES=dc-westThe Ribbon
ConsulServerListused to read this map. Since the move to Spring Cloud LoadBalancer, nothing reads it. Services in another datacenter can't be found through theDiscoveryClientor the load balancer, and the property does nothing.Solution
ConsulDiscoveryClientnow sets the configured datacenter (dc) on theQueryParamsit sends for each service, next to the configured consistency mode. This matches what the Ribbon server list did withnew QueryParams(datacenter, consistencyMode).getInstances,getAllInstances,ConsulReactiveDiscoveryClientand Spring Cloud LoadBalancer all go through this code, so all of them now find services in their configured datacenter. Services without an entry are still looked up in the agent's datacenter.Testing
ConsulDiscoveryClientDatacentersTestsis new. It usesMockRestServiceServerbehind the real HTTP service proxy, likeConsulDiscoveryClientAllInstancesTests, and covers:getInstancessendingdcfor a mapped servicedcfor a service without an entrydccombined with thestaleconsistency modegetAllInstancesusing each service's own datacenterOn
main, the four tests that expectdcfail.I also ran an end-to-end check against two Consul 1.22 agents,
dc-eastanddc-west, joined over the WAN, using a temporary@SpringBootTestthat is not part of this PR. I registeredstoresonly indc-west. The application connected to thedc-eastagent withspring.cloud.consul.discovery.datacenters.stores=dc-west:DiscoveryClient.getInstances("stores")returned10.1.2.3:9090and the Spring Cloud LoadBalancer picked that instance.main, the discovery client returned no instances and the load balancer had nothing to pick.ConsulDiscoveryClientAllInstancesTests, Checkstyle and spring-javaformat pass.Fixes #712