Commit f95f7a51 by Johannes Edmeier

Use Eureka's securedHealthUrl if available

Sometimes Eureka only provides only the securedhealthUrl for the service. Previous to this commit the applciation won't be registered in that case. So with this commit the securedHealthUrl from Eureka is used, when available fixes #224
parent daf683e5
......@@ -20,6 +20,9 @@ import java.net.URI;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.netflix.appinfo.InstanceInfo;
import de.codecentric.boot.admin.model.Application;
......@@ -35,6 +38,11 @@ public class EurekaServiceInstanceConverter extends DefaultServiceInstanceConver
Assert.isInstanceOf(EurekaServiceInstance.class, instance,
"serviceInstance must be of type EurekaServiceInstance");
return URI.create(((EurekaServiceInstance) instance).getInstanceInfo().getHealthCheckUrl());
InstanceInfo instanceInfo = ((EurekaServiceInstance) instance).getInstanceInfo();
String healthUrl = instanceInfo.getSecureHealthCheckUrl();
if (StringUtils.isEmpty(healthUrl)) {
healthUrl = instanceInfo.getHealthCheckUrl();
}
return URI.create(healthUrl);
}
}
......@@ -8,7 +8,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.URI;
import java.util.Collections;
import org.junit.Test;
import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance;
......@@ -20,8 +19,9 @@ import de.codecentric.boot.admin.model.Application;
public class EurekaServiceInstanceConverterTest {
@Test
public void convert() {
public void convert_secure() {
InstanceInfo instanceInfo = mock(InstanceInfo.class);
when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("");
when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
EurekaServiceInstance service = mock(EurekaServiceInstance.class);
when(service.getInstanceInfo()).thenReturn(instanceInfo);
......@@ -36,10 +36,33 @@ public class EurekaServiceInstanceConverterTest {
assertThat(application.getServiceUrl(), is("http://localhost:80"));
assertThat(application.getManagementUrl(), is("http://localhost:80/mgmt"));
assertThat(application.getHealthUrl(), is("http://localhost:80/mgmt/ping"));
}
@Test
public void convert_missing_mgmtpath() {
InstanceInfo instanceInfo = mock(InstanceInfo.class);
when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
EurekaServiceInstance service = mock(EurekaServiceInstance.class);
when(service.getInstanceInfo()).thenReturn(instanceInfo);
when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
when(service.getServiceId()).thenReturn("test");
Application application = new EurekaServiceInstanceConverter().convert(service);
// no management url in metadata
when(service.getMetadata()).thenReturn(Collections.<String, String> emptyMap());
application = new EurekaServiceInstanceConverter().convert(service);
assertThat(application.getManagementUrl(), is("http://localhost:80"));
}
@Test
public void convert_secure_healthUrl() {
InstanceInfo instanceInfo = mock(InstanceInfo.class);
when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("https://localhost:80/health");
EurekaServiceInstance service = mock(EurekaServiceInstance.class);
when(service.getInstanceInfo()).thenReturn(instanceInfo);
when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
when(service.getServiceId()).thenReturn("test");
Application application = new EurekaServiceInstanceConverter().convert(service);
assertThat(application.getHealthUrl(), is("https://localhost:80/health"));
}
}
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