Optimize default endpoint ip address resolution (#831)
This commit is contained in:
committed by
Marcin Grzejszczak
parent
b2afd0b4a9
commit
0bdb39c9cd
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.sleuth.zipkin2;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -52,24 +53,27 @@ public class DefaultEndpointLocator implements EndpointLocator {
|
||||
|
||||
private final Registration registration;
|
||||
private final ServerProperties serverProperties;
|
||||
private final InetUtils inetUtils;
|
||||
private final ZipkinProperties zipkinProperties;
|
||||
private final RelaxedPropertyResolver resolver;
|
||||
private Integer port;
|
||||
private InetAddress firstNonLoopbackAddress;
|
||||
|
||||
public DefaultEndpointLocator(Registration registration, ServerProperties serverProperties,
|
||||
Environment environment, ZipkinProperties zipkinProperties, InetUtils inetUtils) {
|
||||
this.registration = registration;
|
||||
this.serverProperties = serverProperties;
|
||||
this.zipkinProperties = zipkinProperties;
|
||||
if (inetUtils == null) {
|
||||
this.inetUtils = new InetUtils(new InetUtilsProperties());
|
||||
} else {
|
||||
this.inetUtils = inetUtils;
|
||||
}
|
||||
this.firstNonLoopbackAddress = findFirstNonLoopbackAddress(inetUtils);
|
||||
this.resolver = new RelaxedPropertyResolver(environment);
|
||||
}
|
||||
|
||||
private InetAddress findFirstNonLoopbackAddress(InetUtils inetUtils) {
|
||||
if (inetUtils == null) {
|
||||
inetUtils = new InetUtils(new InetUtilsProperties());
|
||||
}
|
||||
return inetUtils.findFirstNonLoopbackAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Endpoint local() {
|
||||
String serviceName = getLocalServiceName();
|
||||
@@ -124,7 +128,7 @@ public class DefaultEndpointLocator implements EndpointLocator {
|
||||
return builder;
|
||||
}
|
||||
else {
|
||||
return builder.ip(this.inetUtils.findFirstNonLoopbackAddress());
|
||||
return builder.ip(this.firstNonLoopbackAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user