spring-cloud / spring-cloud/spring-cloud-consul

Consul Admin Partition Support

Open
#813 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.