Commit 93be4a64 by Johannes Edmeier

Merge branch '1.3.x'

parents 69dec9ae ed45e91d
......@@ -281,7 +281,7 @@ The setup is explained <<discover-clients-via-spring-cloud-discovery,above>>.
The informations from the discovered services are converted by the `ServiceInstanceConverter`. Spring Boot Admin ships with a default and Eureka converter implementation. The correct one is selected by AutoConfiguration. You can use your own conversion by implementing the interface and adding the bean to your application context.
TIP: If you want to customize the default conversion of services you can either add `health.path` and/or `mangament.context-path` entries to the services metadata. This allows you to set the health or management path per application. In case you want to configure this for all of your discovered services, you can use the `spring.boot.admin.discovery.converter.*` properties for your Spring Boot Admin Server configuration. The services' metadata takes precedence over the server configuration. For the health-url the `EurekaServiceInstanceConverter` uses the healthCheckUrl registered in Eureka, which can be set for your client via `eureka.instance.healthCheckUrl`.
TIP: If you want to customize the default conversion of services you can either add `health.path`, `management.port` and/or `mangament.context-path` entries to the services metadata. This allows you to set the health or management path per application. In case you want to configure this for all of your discovered services, you can use the `spring.boot.admin.discovery.converter.*` properties for your Spring Boot Admin Server configuration. The services' metadata takes precedence over the server configuration. For the health-url the `EurekaServiceInstanceConverter` uses the healthCheckUrl registered in Eureka, which can be set for your client via `eureka.instance.healthCheckUrl`.
.Discovery configuration options
|===
......
......@@ -96,8 +96,10 @@ public class ApplicationDiscoveryListener {
protected final Set<String> getAllApplicationIdsFromRegistry() {
Set<String> result = new HashSet<>();
for (Application application : registry.getApplications()) {
if (!ignoredServices.contains(application.getName())) {
result.add(application.getId());
}
}
return result;
}
......
......@@ -29,11 +29,13 @@ import de.codecentric.boot.admin.model.Application;
* Converts any {@link ServiceInstance}s to {@link Application}s. To customize the health- or
* management-url for all applications you can set healthEndpointPath or managementContextPath
* respectively. If you want to influence the url per service you can add
* <code>management.context-path</code> or <code>health.path</code> to the instances metadata.
* <code>management.context-path</code> or <code>management.port</code> or <code>health.path</code>
* to the instances metadata.
*
* @author Johannes Edmeier
*/
public class DefaultServiceInstanceConverter implements ServiceInstanceConverter {
private static final String KEY_MANAGEMENT_PORT = "management.port";
private static final String KEY_MANAGEMENT_PATH = "management.context-path";
private static final String KEY_HEALTH_PATH = "health.path";
private String managementContextPath = "";
......@@ -61,8 +63,8 @@ public class DefaultServiceInstanceConverter implements ServiceInstanceConverter
}
protected URI getHealthUrl(ServiceInstance instance) {
String healthPath = defaultIfEmpty(
instance.getMetadata().get(KEY_HEALTH_PATH), healthEndpointPath);
String healthPath = defaultIfEmpty(instance.getMetadata().get(KEY_HEALTH_PATH),
healthEndpointPath);
healthPath = stripStart(healthPath, "/");
return UriComponentsBuilder.fromUri(getManagementUrl(instance)).pathSegment(healthPath)
......@@ -70,12 +72,16 @@ public class DefaultServiceInstanceConverter implements ServiceInstanceConverter
}
protected URI getManagementUrl(ServiceInstance instance) {
String managamentPath = defaultIfEmpty(
instance.getMetadata().get(KEY_MANAGEMENT_PATH), managementContextPath);
String managamentPath = defaultIfEmpty(instance.getMetadata().get(KEY_MANAGEMENT_PATH),
managementContextPath);
managamentPath = stripStart(managamentPath, "/");
return UriComponentsBuilder.fromUri(getServiceUrl(instance)).pathSegment(managamentPath)
.build().toUri();
URI serviceUrl = getServiceUrl(instance);
String managamentPort = defaultIfEmpty(instance.getMetadata().get(KEY_MANAGEMENT_PORT),
String.valueOf(serviceUrl.getPort()));
return UriComponentsBuilder.fromUri(serviceUrl).port(managamentPort)
.pathSegment(managamentPath).build().toUri();
}
protected URI getServiceUrl(ServiceInstance instance) {
......
......@@ -99,7 +99,9 @@ public class ApplicationDiscoveryListenerTest {
@Test
public void deregister_removed_app() {
Object heartbeat = new Object();
registry.register(Application.create("ignored").withHealthUrl("http://health")
.withId("abcdef").build());
listener.setIgnoredServices(Collections.singleton("ignored"));
List<ServiceInstance> instances = new ArrayList<>();
instances.add(new DefaultServiceInstance("service", "localhost", 80, false));
......@@ -108,13 +110,15 @@ public class ApplicationDiscoveryListenerTest {
when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
when(discovery.getInstances("service")).thenReturn(instances);
listener.onApplicationEvent(new HeartbeatEvent(new Object(), heartbeat));
assertEquals(2, registry.getApplications().size());
listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
assertEquals(2, registry.getApplicationsByName("service").size());
assertEquals(1, registry.getApplicationsByName("ignored").size());
instances.remove(0);
listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
assertEquals(1, registry.getApplications().size());
assertEquals(1, registry.getApplicationsByName("service").size());
assertEquals(1, registry.getApplicationsByName("ignored").size());
}
}
......@@ -45,14 +45,15 @@ public class DefaultServiceInstanceConverterTest {
ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
service.getMetadata().put("health.path", "ping");
service.getMetadata().put("management.context-path", "mgmt");
service.getMetadata().put("management.port", "1234");
Application application = new DefaultServiceInstanceConverter().convert(service);
assertThat(application.getId(), nullValue());
assertThat(application.getName(), is("test"));
assertThat(application.getServiceUrl(), is("http://localhost:80"));
assertThat(application.getManagementUrl(), is("http://localhost:80/mgmt"));
assertThat(application.getHealthUrl(), is("http://localhost:80/mgmt/ping"));
assertThat(application.getManagementUrl(), is("http://localhost:1234/mgmt"));
assertThat(application.getHealthUrl(), is("http://localhost:1234/mgmt/ping"));
}
}
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