spring-cloud / spring-cloud/spring-cloud-commons
The ability to return the IP Address of a DiscoveryClient.getInstances(serviceId) method when EUREKA-INSTANCE-PREFER-IP-ADDRESS is set to false
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 751
- Forks
- 744
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
Currently when you call the DiscoveryClient.getInstances(serviceId) method it returns a List of ServiceInstances - The ServiceInstance class currently has 8 public methods which are:
- getHost()
- getInstanceId()
- getMetadata()
- getPort()
- getScheme()
- getServiceId()
- getUri()
- isSecure()
None of the above methods provides the capability to fetch the IP Address of the service instance. Its always assumed that the getHost() method is capable of giving you the IP Address of the ServiceIntance but this is not always the case. You will always get the IP Address of the instance when you call the getHost() method only if the following is true:
- If on the eureka client the EUREKA-INSTANCE-PREFER-IP-ADDRESS is set to true
However, in the case where EUREKA-INSTANCE-PREFER-IP-ADDRESS is set to false, and EUREKA_INSTANCE_NON-SECURE-PORT is set to a value "80", and EUREKA_INSTANCE_HOSTNAME is set to a value "gontse.ntshegi@yuqar-group.com", the getHost() method will always return "gontse.ntshegi@yuqar-group.com" .
Describe the solution you'd like
When EUREKA-INSTANCE-PREFER-IP-ADDRESS is set to false, and EUREKA_INSTANCE_NON-SECURE-PORT and EUREKA_INSTANCE_HOSTNAME is set I would like to suggest a new method in the ServiceInstance that gets you the IP Address of the instance (e.g getIpAdd). Currently the IP Address value exist in the ServiceInstance/EurekaServiceInstance class as an instance variable of the InstanceInfo class called ipAddr - This value can be made available through a get method in the ServiceInstance class.
Describe alternatives you've considered
N/A
Additional context

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 by tracing DiscoveryClient.getInstances(serviceId) through ServiceInstance and EurekaServiceInstance, then inspect the InstanceInfo.ipAddr value and how EUREKA-INSTANCE-PREFER-IP-ADDRESS affects getHost(). Done means the instance IP can be retrieved when hostname preference is false, without losing the existing hostname behavior; add or update coverage for that configuration if the project has tests for these classes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, distributed-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100