Skip to content

Commit

Permalink
Merge branch '1.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
joshiste committed Aug 7, 2016
2 parents 69dec9a + ed45e91 commit 93be4a6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion spring-boot-admin-docs/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
|===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ protected void discover() {
protected final Set<String> getAllApplicationIdsFromRegistry() {
Set<String> result = new HashSet<>();
for (Application application : registry.getApplications()) {
result.add(application.getId());
if (!ignoredServices.contains(application.getName())) {
result.add(application.getId());
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
* 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 = "";
Expand Down Expand Up @@ -61,21 +63,25 @@ public Application convert(ServiceInstance instance) {
}

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)
.build().toUri();
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public void single_discovery_for_same_heartbeat() {

@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));
Expand All @@ -108,13 +110,15 @@ public void deregister_removed_app() {
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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ public void test_convert_with_metadata() {
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"));
}

}

0 comments on commit 93be4a6

Please sign in to comment.