spring-cloud / spring-cloud/spring-cloud-consul
Consul Admin Partition Support
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 822
- Forks
- 539
- Avg merge
- 9h 31m
- Merged PRs (30d)
- 7
Description
Describe the bug
Using spring-cloud-starter-consul-discovery version 3.1.2. Using a combination of Spring Boot microservice, Spring Cloud Consul plugins, Consul agents on Kubernetes, and Consul Enterprise with Admin Partitions. The microservices are able to register into the correct admin partition (as seen on Consul UI). However, when using DiscoveryClient, no microservices are able to be found. It appears it is only querying the default partition. Unable to find environment variable or Java API call to specify admin partition to query in.
pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
<version>3.1.2</version>
</dependency>
Sample code:
import org.springframework.cloud.client.discovery.DiscoveryClient;
...
@Component
public class AppDiscoveryClient {
@Autowired
private DiscoveryClient discoveryClient;
...
private URI serviceUri(String serviceName) {
List<ServiceInstance> instances = discoveryClient.getInstances(serviceName);
if (instances == null || instances.isEmpty()) {
throw new RuntimeException("Cannot find microservice " + serviceName);
}
ServiceInstance serviceInstance = instances.get(0);
return serviceInstance.getUri();
}
...
from logs:
Registering service with consul: NewService{id='api-10-0-0-147', name='api', tags=[contextPath=/api], address='10.0.0.147', meta={secure=false}, port=8080, enableTagOverride=null, check=Check{script='null', dockerContainerID='null', shell='null', interval='10s', ttl='null', http='http://10.0.0.147:8080/api/actuator/health', method='null', header={}, tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null', grpc='null', grpcUseTLS=null}, checks=null}
When trying to query from another Spring boot microservice, there is the exception thrown of "Cannot find microservice api". When using the Consul REST API, the entries appear when adding partition as a query parameter to the GET services.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DiscoveryClient.getInstances(serviceName) lookup and compare its Consul request with the Consul REST API request that includes the partition query parameter. Trace how the admin partition could be configured or passed through the Spring Cloud Consul discovery path. Done means services in the configured admin partition are discoverable through DiscoveryClient rather than only through the default partition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100