Commit 129e0ce4 by windinn Committed by Spencer Gibb

Use prefer-ip-address in statusPageUrlPath

prefer-ip-address does not work in statusPageUrlPath when management port != server port This change gets `prefer-ip-address` via a relaxed property resolver to set the value during the creation of the `EurekaInstanceConfigBean`. fixes gh-1724
parent 309b280d
...@@ -88,9 +88,6 @@ public class EurekaClientAutoConfiguration { ...@@ -88,9 +88,6 @@ public class EurekaClientAutoConfiguration {
@Value("${management.port:${MANAGEMENT_PORT:${server.port:${SERVER_PORT:${PORT:8080}}}}}") @Value("${management.port:${MANAGEMENT_PORT:${server.port:${SERVER_PORT:${PORT:8080}}}}}")
private int managementPort; private int managementPort;
@Value("${eureka.instance.hostname:${EUREKA_INSTANCE_HOSTNAME:}}")
private String hostname;
@Autowired @Autowired
private ConfigurableEnvironment env; private ConfigurableEnvironment env;
...@@ -117,15 +114,18 @@ public class EurekaClientAutoConfiguration { ...@@ -117,15 +114,18 @@ public class EurekaClientAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(value = EurekaInstanceConfig.class, search = SearchStrategy.CURRENT) @ConditionalOnMissingBean(value = EurekaInstanceConfig.class, search = SearchStrategy.CURRENT)
public EurekaInstanceConfigBean eurekaInstanceConfigBean(InetUtils inetUtils) { public EurekaInstanceConfigBean eurekaInstanceConfigBean(InetUtils inetUtils) {
RelaxedPropertyResolver relaxedPropertyResolver = new RelaxedPropertyResolver(env, "eureka.instance.");
String hostname = relaxedPropertyResolver.getProperty("hostname");
boolean preferIpAddress = Boolean.parseBoolean(relaxedPropertyResolver.getProperty("preferIpAddress"));
EurekaInstanceConfigBean instance = new EurekaInstanceConfigBean(inetUtils); EurekaInstanceConfigBean instance = new EurekaInstanceConfigBean(inetUtils);
instance.setNonSecurePort(this.nonSecurePort); instance.setNonSecurePort(this.nonSecurePort);
instance.setInstanceId(getDefaultInstanceId(this.env)); instance.setInstanceId(getDefaultInstanceId(this.env));
instance.setPreferIpAddress(preferIpAddress);
if (this.managementPort != this.nonSecurePort && this.managementPort != 0) { if (this.managementPort != this.nonSecurePort && this.managementPort != 0) {
if (StringUtils.hasText(this.hostname)) { if (StringUtils.hasText(hostname)) {
instance.setHostname(this.hostname); instance.setHostname(hostname);
} }
RelaxedPropertyResolver relaxedPropertyResolver = new RelaxedPropertyResolver(env, "eureka.instance.");
String statusPageUrlPath = relaxedPropertyResolver.getProperty("statusPageUrlPath"); String statusPageUrlPath = relaxedPropertyResolver.getProperty("statusPageUrlPath");
String healthCheckUrlPath = relaxedPropertyResolver.getProperty("healthCheckUrlPath"); String healthCheckUrlPath = relaxedPropertyResolver.getProperty("healthCheckUrlPath");
if (StringUtils.hasText(statusPageUrlPath)) { if (StringUtils.hasText(statusPageUrlPath)) {
......
...@@ -125,6 +125,20 @@ public class EurekaClientAutoConfigurationTests { ...@@ -125,6 +125,20 @@ public class EurekaClientAutoConfigurationTests {
} }
@Test @Test
public void statusPageUrlAndPreferIpAddress() {
EnvironmentTestUtils.addEnvironment(this.context, "server.port=8989",
"management.port=9999", "eureka.instance.hostname=foo",
"eureka.instance.preferIpAddress:true");
setupContext(RefreshAutoConfiguration.class);
EurekaInstanceConfigBean instance = this.context
.getBean(EurekaInstanceConfigBean.class);
assertEquals("statusPageUrl is wrong", "http://" + instance.getIpAddress() + ":9999/info",
instance.getStatusPageUrl());
}
@Test
public void healthCheckUrlPathAndManagementPortKabobCase() { public void healthCheckUrlPathAndManagementPortKabobCase() {
EnvironmentTestUtils.addEnvironment(this.context, "server.port=8989", EnvironmentTestUtils.addEnvironment(this.context, "server.port=8989",
"management.port=9999", "management.port=9999",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment