Allow part of a composite contributor in a health group
Closes gh-23027 Co-authored-by: Phillip Webb <pwebb@vmware.com>
This commit is contained in:
@@ -16,8 +16,13 @@
|
||||
|
||||
package smoketest.actuator;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.health.CompositeHealthContributor;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthContributor;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
@@ -33,7 +38,27 @@ public class SampleActuatorApplication {
|
||||
|
||||
@Bean
|
||||
public HealthIndicator helloHealthIndicator() {
|
||||
return () -> Health.up().withDetail("hello", "world").build();
|
||||
return createHealthIndicator("world");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HealthContributor compositeHelloHealthContributor() {
|
||||
Map<String, HealthContributor> map = new LinkedHashMap<>();
|
||||
map.put("spring", createNestedHealthContributor("spring"));
|
||||
map.put("boot", createNestedHealthContributor("boot"));
|
||||
return CompositeHealthContributor.fromMap(map);
|
||||
}
|
||||
|
||||
private HealthContributor createNestedHealthContributor(String name) {
|
||||
Map<String, HealthContributor> map = new LinkedHashMap<>();
|
||||
map.put("a", createHealthIndicator(name + "-a"));
|
||||
map.put("b", createHealthIndicator(name + "-b"));
|
||||
map.put("c", createHealthIndicator(name + "-c"));
|
||||
return CompositeHealthContributor.fromMap(map);
|
||||
}
|
||||
|
||||
private HealthIndicator createHealthIndicator(String value) {
|
||||
return () -> Health.up().withDetail("hello", value).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,4 +23,8 @@ management.endpoint.health.show-details=always
|
||||
management.endpoint.health.group.ready.include=db,diskSpace
|
||||
management.endpoint.health.group.live.include=example,hello,db
|
||||
management.endpoint.health.group.live.show-details=never
|
||||
management.endpoint.health.group.comp.include=compositeHello/spring/a,compositeHello/spring/c
|
||||
management.endpoint.health.group.comp.show-details=always
|
||||
|
||||
management.endpoints.migrate-legacy-ids=true
|
||||
|
||||
|
||||
@@ -67,7 +67,16 @@ abstract class AbstractManagementPortAndPathSampleActuatorApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\",\"groups\":[\"live\",\"ready\"]}");
|
||||
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\",\"groups\":[\"comp\",\"live\",\"ready\"]}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGroupWithComposite() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
|
||||
.getForEntity("http://localhost:" + this.managementPort + "/admin/health/comp", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains(
|
||||
"components\":{\"a\":{\"status\":\"UP\",\"details\":{\"hello\":\"spring-a\"}},\"c\":{\"status\":\"UP\",\"details\":{\"hello\":\"spring-c\"}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user