spring-cloud / spring-cloud/spring-cloud-gateway

DiscoveryClientRouteDefinitionLocator cannot find proper service when use metadata in Path Predicate

Open
#1,299 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

I'm using spring-cloud-gateway to dynamically redirect to services registered in consul, but in my case, the same serviceId may have different tags for different instance. For example:
service ID: user-service
instance1 Tags: version: 1.0
instance2 Tags: version: 1.1

my spring cloud configuration looks like:
predicates:
- Path='/'+serviceId+'/'+metadata['version']+'/**'

But I DiscoveryClientRouteDefinitionLocator Line 100
.map(instances -> instances.get(0)).filter(includePredicate)
So only one version works, need take metadata into consideration.
Further more, even have different RouteDefinition for different version, gateway can load service, but cannot locate correct version, I guess that is because DiscoveryClient will return all instances according serviceId.

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 by reading DiscoveryClientRouteDefinitionLocator around line 100 and trace how instances are selected before includePredicate is applied. Use the stated Consul setup with multiple instances of user-service and different version tags to inspect route selection. Done means separate metadata-based Path Predicate routes locate the matching service instance rather than only the first instance returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.