spring-cloud-commons icon indicating copy to clipboard operation
spring-cloud-commons copied to clipboard

The ability to return the IP Address of a DiscoveryClient.getInstances(serviceId) method when EUREKA-INSTANCE-PREFER-IP-ADDRESS is set to false

Open GontseNtshegi opened this issue 4 years ago • 0 comments

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:

  1. getHost()
  2. getInstanceId()
  3. getMetadata()
  4. getPort()
  5. getScheme()
  6. getServiceId()
  7. getUri()
  8. 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:

  1. 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 "[email protected]", the getHost() method will always return "[email protected]" .

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 image

GontseNtshegi avatar Jan 25 '21 16:01 GontseNtshegi