From 31025d9f6c9248db88061855c3231a203ed3c80f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 22 Nov 2017 13:54:11 -0800 Subject: [PATCH] Drop status endpoint Drop the status endpoint and merge functionality back into the health endpoint. The `management.endpoint.health.show-details` property can be used to change if full details, or just the status is displayed. Fixes gh-11113 --- .../src/main/asciidoc/index.adoc | 1 - .../web/WebEndpointAutoConfiguration.java | 2 +- .../HealthEndpointAutoConfiguration.java | 14 +-- .../health/HealthEndpointProperties.java | 43 +++++++ ...ndpointManagementContextConfiguration.java | 27 +---- .../HealthEndpointDocumentationTests.java | 5 +- .../StatusEndpointDocumentationTests.java | 82 -------------- .../HealthEndpointAutoConfigurationTests.java | 40 +++---- ...veManagementContextConfigurationTests.java | 30 +---- ...etManagementContextConfigurationTests.java | 25 ----- .../JmxEndpointIntegrationTests.java | 2 +- ...intsAutoConfigurationIntegrationTests.java | 14 --- ...ebMvcEndpointExposureIntegrationTests.java | 6 +- .../boot/actuate/health/HealthEndpoint.java | 14 ++- .../ReactiveHealthEndpointWebExtension.java | 8 +- .../ReactiveStatusEndpointWebExtension.java | 53 --------- .../boot/actuate/health/StatusEndpoint.java | 46 -------- .../health/StatusEndpointWebExtension.java | 49 -------- .../actuate/health/HealthEndpointTests.java | 16 ++- .../HealthEndpointWebIntegrationTests.java | 3 +- .../actuate/health/StatusEndpointTests.java | 53 --------- .../StatusEndpointWebIntegrationTests.java | 105 ------------------ .../appendix-application-properties.adoc | 1 + .../asciidoc/production-ready-features.adoc | 4 - .../customsecurity/SecurityConfiguration.java | 2 +- .../src/main/resources/application.properties | 1 + ...AndPathSampleActuatorApplicationTests.java | 8 +- ...ctuatorCustomSecurityApplicationTests.java | 2 +- .../application-endpoints.properties | 3 +- .../jersey/SampleJerseyApplicationTests.java | 2 +- .../SampleSecureWebFluxApplicationTests.java | 4 +- .../SampleWebFluxApplicationTests.java | 2 +- 32 files changed, 127 insertions(+), 540 deletions(-) create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/StatusEndpointDocumentationTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveStatusEndpointWebExtension.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/StatusEndpoint.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/StatusEndpointWebExtension.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/StatusEndpointTests.java delete mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/StatusEndpointWebIntegrationTests.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/index.adoc b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/index.adoc index e30d7e6616..87205a3cff 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/index.adoc +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/index.adoc @@ -66,5 +66,4 @@ include::endpoints/prometheus.adoc[leveloffset=+1] include::endpoints/scheduledtasks.adoc[leveloffset=+1] include::endpoints/sessions.adoc[leveloffset=+1] include::endpoints/shutdown.adoc[leveloffset=+1] -include::endpoints/status.adoc[leveloffset=+1] include::endpoints/threaddump.adoc[leveloffset=+1] diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java index 1fd830d89f..206a428a61 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java @@ -105,7 +105,7 @@ public class WebEndpointAutoConfiguration { public ExposeExcludePropertyEndpointFilter webIncludeExcludePropertyEndpointFilter() { return new ExposeExcludePropertyEndpointFilter<>( WebAnnotationEndpointDiscoverer.class, this.properties.getExpose(), - this.properties.getExclude(), "info", "status"); + this.properties.getExclude(), "info", "health"); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java index 07ab3899a3..ff492261a0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java @@ -27,9 +27,9 @@ import org.springframework.boot.actuate.health.HealthEndpoint; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.OrderedHealthAggregator; import org.springframework.boot.actuate.health.ReactiveHealthIndicator; -import org.springframework.boot.actuate.health.StatusEndpoint; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -44,6 +44,7 @@ import org.springframework.util.ClassUtils; * @since 2.0.0 */ @Configuration +@EnableConfigurationProperties(HealthEndpointProperties.class) public class HealthEndpointAutoConfiguration { private final HealthIndicator healthIndicator; @@ -69,15 +70,8 @@ public class HealthEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean @ConditionalOnEnabledEndpoint - public HealthEndpoint healthEndpoint() { - return new HealthEndpoint(this.healthIndicator); - } - - @Bean - @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint - public StatusEndpoint statusEndpoint() { - return new StatusEndpoint(this.healthIndicator); + public HealthEndpoint healthEndpoint(HealthEndpointProperties properties) { + return new HealthEndpoint(this.healthIndicator, properties.isShowDetails()); } private static class ReactiveHealthIndicators { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java new file mode 100644 index 0000000000..7f0eb2d064 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.health; + +import org.springframework.boot.actuate.health.HealthEndpoint; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Configuration properties for {@link HealthEndpoint}. + * + * @author Phillip Webb + */ +@ConfigurationProperties("management.endpoint.health") +public class HealthEndpointProperties { + + /** + * Whether to show full health details instead of just the status. + */ + private boolean showDetails; + + public boolean isShowDetails() { + return this.showDetails; + } + + public void setShowDetails(boolean showDetails) { + this.showDetails = showDetails; + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointManagementContextConfiguration.java index 8d6a7d705f..f08a47186e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointManagementContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointManagementContextConfiguration.java @@ -31,9 +31,6 @@ import org.springframework.boot.actuate.health.HealthStatusHttpMapper; import org.springframework.boot.actuate.health.OrderedHealthAggregator; import org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension; import org.springframework.boot.actuate.health.ReactiveHealthIndicator; -import org.springframework.boot.actuate.health.ReactiveStatusEndpointWebExtension; -import org.springframework.boot.actuate.health.StatusEndpoint; -import org.springframework.boot.actuate.health.StatusEndpointWebExtension; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; @@ -85,19 +82,10 @@ public class HealthWebEndpointManagementContextConfiguration { @ConditionalOnEnabledEndpoint @ConditionalOnBean(HealthEndpoint.class) public ReactiveHealthEndpointWebExtension reactiveHealthEndpointWebExtension( - HealthStatusHttpMapper healthStatusHttpMapper) { + HealthStatusHttpMapper healthStatusHttpMapper, + HealthEndpointProperties properties) { return new ReactiveHealthEndpointWebExtension(this.reactiveHealthIndicator, - healthStatusHttpMapper); - } - - @Bean - @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint - @ConditionalOnBean(StatusEndpoint.class) - public ReactiveStatusEndpointWebExtension reactiveStatusEndpointWebExtension( - HealthStatusHttpMapper healthStatusHttpMapper) { - return new ReactiveStatusEndpointWebExtension(this.reactiveHealthIndicator, - healthStatusHttpMapper); + healthStatusHttpMapper, properties.isShowDetails()); } } @@ -115,15 +103,6 @@ public class HealthWebEndpointManagementContextConfiguration { return new HealthEndpointWebExtension(delegate, healthStatusHttpMapper); } - @Bean - @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint - @ConditionalOnBean(StatusEndpoint.class) - public StatusEndpointWebExtension statusEndpointWebExtension( - StatusEndpoint delegate, HealthStatusHttpMapper healthStatusHttpMapper) { - return new StatusEndpointWebExtension(delegate, healthStatusHttpMapper); - } - } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/HealthEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/HealthEndpointDocumentationTests.java index 3beaa5993c..044e95b564 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/HealthEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/HealthEndpointDocumentationTests.java @@ -57,7 +57,8 @@ public class HealthEndpointDocumentationTests extends AbstractEndpointDocumentat fieldWithPath("status").description( "Overall status of the application."), fieldWithPath("details") - .description("Details of the health of the application."), + .description("Details of the health of the application " + + "(only included when `management.endpoint.health.show-details` is `true`)."), fieldWithPath("details.*.status").description( "Status of a specific part of the application."), subsectionWithPath("details.*.details").description( @@ -73,7 +74,7 @@ public class HealthEndpointDocumentationTests extends AbstractEndpointDocumentat @Bean public HealthEndpoint endpoint(Map healthIndicators) { return new HealthEndpoint(new CompositeHealthIndicator( - new OrderedHealthAggregator(), healthIndicators)); + new OrderedHealthAggregator(), healthIndicators), true); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/StatusEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/StatusEndpointDocumentationTests.java deleted file mode 100644 index 3ce0fdf278..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/StatusEndpointDocumentationTests.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; - -import java.io.File; -import java.util.Map; - -import javax.sql.DataSource; - -import org.junit.Test; - -import org.springframework.boot.actuate.health.CompositeHealthIndicator; -import org.springframework.boot.actuate.health.HealthIndicator; -import org.springframework.boot.actuate.health.OrderedHealthAggregator; -import org.springframework.boot.actuate.health.StatusEndpoint; -import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator; -import org.springframework.boot.actuate.system.DiskSpaceHealthIndicator; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * Tests for generating documentation describing the {@link StatusEndpoint}. - * - * @author Andy Wilkinson - */ -public class StatusEndpointDocumentationTests extends AbstractEndpointDocumentationTests { - - @Test - public void health() throws Exception { - this.mockMvc.perform(get("/application/status")).andExpect(status().isOk()) - .andDo(document("status", responseFields(fieldWithPath("status") - .description("Overall status of the application.")))); - } - - @Configuration - @Import(BaseDocumentationConfiguration.class) - @ImportAutoConfiguration(DataSourceAutoConfiguration.class) - static class TestConfiguration { - - @Bean - public StatusEndpoint endpoint(Map healthIndicators) { - return new StatusEndpoint(new CompositeHealthIndicator( - new OrderedHealthAggregator(), healthIndicators)); - } - - @Bean - public DiskSpaceHealthIndicator diskSpaceHealthIndicator() { - return new DiskSpaceHealthIndicator(new File("."), 1024 * 1024 * 10); - } - - @Bean - public DataSourceHealthIndicator dataSourceHealthIndicator( - DataSource dataSource) { - return new DataSourceHealthIndicator(dataSource); - } - - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java index 74e6eee624..9cbed94aa1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java @@ -24,7 +24,6 @@ import org.springframework.boot.actuate.health.HealthEndpoint; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.ReactiveHealthIndicator; import org.springframework.boot.actuate.health.Status; -import org.springframework.boot.actuate.health.StatusEndpoint; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; @@ -48,9 +47,25 @@ public class HealthEndpointAutoConfigurationTests { .withConfiguration( AutoConfigurations.of(HealthEndpointAutoConfiguration.class)); + @Test + public void healthEndpointShowDetailsDefault() { + this.contextRunner + .withUserConfiguration(ReactiveHealthIndicatorConfiguration.class) + .run((context) -> { + ReactiveHealthIndicator indicator = context.getBean( + "reactiveHealthIndicator", ReactiveHealthIndicator.class); + verify(indicator, times(0)).health(); + Health health = context.getBean(HealthEndpoint.class).health(); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails()).isEmpty(); + verify(indicator, times(1)).health(); + }); + } + @Test public void healthEndpointAdaptReactiveHealthIndicator() { this.contextRunner + .withPropertyValues("management.endpoint.health.show-details=true") .withUserConfiguration(ReactiveHealthIndicatorConfiguration.class) .run((context) -> { ReactiveHealthIndicator indicator = context.getBean( @@ -65,8 +80,11 @@ public class HealthEndpointAutoConfigurationTests { @Test public void healthEndpointMergeRegularAndReactive() { - this.contextRunner.withUserConfiguration(HealthIndicatorConfiguration.class, - ReactiveHealthIndicatorConfiguration.class).run((context) -> { + this.contextRunner + .withPropertyValues("management.endpoint.health.show-details=true") + .withUserConfiguration(HealthIndicatorConfiguration.class, + ReactiveHealthIndicatorConfiguration.class) + .run((context) -> { HealthIndicator indicator = context.getBean("simpleHealthIndicator", HealthIndicator.class); ReactiveHealthIndicator reactiveHealthIndicator = context.getBean( @@ -82,22 +100,6 @@ public class HealthEndpointAutoConfigurationTests { }); } - @Test - public void runShouldHaveStatusEndpointBeanEvenIfDefaultIsDisabled() { - // FIXME - this.contextRunner.withPropertyValues("management.endpoint.default.enabled:false") - .run((context) -> assertThat(context) - .hasSingleBean(StatusEndpoint.class)); - } - - @Test - public void runWhenEnabledPropertyIsFalseShouldNotHaveStatusEndpointBean() - throws Exception { - this.contextRunner.withPropertyValues("management.endpoint.status.enabled:false") - .run((context) -> assertThat(context) - .doesNotHaveBean(StatusEndpoint.class)); - } - @Configuration static class HealthIndicatorConfiguration { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointReactiveManagementContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointReactiveManagementContextConfigurationTests.java index 3e97ec6950..8352fc3114 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointReactiveManagementContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointReactiveManagementContextConfigurationTests.java @@ -22,7 +22,6 @@ import org.junit.Test; import org.springframework.boot.actuate.health.HealthStatusHttpMapper; import org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension; -import org.springframework.boot.actuate.health.ReactiveStatusEndpointWebExtension; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; import org.springframework.test.util.ReflectionTestUtils; @@ -46,7 +45,6 @@ public class HealthWebEndpointReactiveManagementContextConfigurationTests { @Test public void runShouldCreateExtensionBeans() throws Exception { this.contextRunner.run((context) -> assertThat(context) - .hasSingleBean(ReactiveStatusEndpointWebExtension.class) .hasSingleBean(ReactiveHealthEndpointWebExtension.class)); } @@ -58,19 +56,10 @@ public class HealthWebEndpointReactiveManagementContextConfigurationTests { .doesNotHaveBean(ReactiveHealthEndpointWebExtension.class)); } - @Test - public void runWhenStatusEndpointIsDisabledShouldNotCreateExtensionBeans() - throws Exception { - this.contextRunner.withPropertyValues("management.endpoint.status.enabled:false") - .run((context) -> assertThat(context) - .doesNotHaveBean(ReactiveStatusEndpointWebExtension.class)); - } - @Test public void runWithCustomHealthMappingShouldMapStatusCode() throws Exception { this.contextRunner - .withPropertyValues( - "management.health.status.http-mapping.CUSTOM=500") + .withPropertyValues("management.health.status.http-mapping.CUSTOM=500") .run((context) -> { Object extension = context .getBean(ReactiveHealthEndpointWebExtension.class); @@ -83,21 +72,4 @@ public class HealthWebEndpointReactiveManagementContextConfigurationTests { }); } - @Test - public void runWithCustomStatusMappingShouldMapStatusCode() throws Exception { - this.contextRunner - .withPropertyValues( - "management.health.status.http-mapping.CUSTOM=500") - .run((context) -> { - Object extension = context - .getBean(ReactiveStatusEndpointWebExtension.class); - HealthStatusHttpMapper mapper = (HealthStatusHttpMapper) ReflectionTestUtils - .getField(extension, "statusHttpMapper"); - Map statusMappings = mapper.getStatusMapping(); - assertThat(statusMappings).containsEntry("DOWN", 503); - assertThat(statusMappings).containsEntry("OUT_OF_SERVICE", 503); - assertThat(statusMappings).containsEntry("CUSTOM", 500); - }); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointServletManagementContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointServletManagementContextConfigurationTests.java index a8f700061c..1e4cef5221 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointServletManagementContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthWebEndpointServletManagementContextConfigurationTests.java @@ -22,7 +22,6 @@ import org.junit.Test; import org.springframework.boot.actuate.health.HealthEndpointWebExtension; import org.springframework.boot.actuate.health.HealthStatusHttpMapper; -import org.springframework.boot.actuate.health.StatusEndpointWebExtension; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.test.util.ReflectionTestUtils; @@ -46,7 +45,6 @@ public class HealthWebEndpointServletManagementContextConfigurationTests { @Test public void runShouldCreateExtensionBeans() throws Exception { this.contextRunner.run((context) -> assertThat(context) - .hasSingleBean(StatusEndpointWebExtension.class) .hasSingleBean(HealthEndpointWebExtension.class)); } @@ -58,14 +56,6 @@ public class HealthWebEndpointServletManagementContextConfigurationTests { .doesNotHaveBean(HealthEndpointWebExtension.class)); } - @Test - public void runWhenStatusEndpointIsDisabledShouldNotCreateExtensionBeans() - throws Exception { - this.contextRunner.withPropertyValues("management.endpoint.status.enabled:false") - .run((context) -> assertThat(context) - .doesNotHaveBean(StatusEndpointWebExtension.class)); - } - @Test public void runWithCustomHealthMappingShouldMapStatusCode() throws Exception { this.contextRunner @@ -81,19 +71,4 @@ public class HealthWebEndpointServletManagementContextConfigurationTests { }); } - @Test - public void runWithCustomStatusMappingShouldMapStatusCode() throws Exception { - this.contextRunner - .withPropertyValues("management.health.status.http-mapping.CUSTOM=500") - .run((context) -> { - Object extension = context.getBean(StatusEndpointWebExtension.class); - HealthStatusHttpMapper mapper = (HealthStatusHttpMapper) ReflectionTestUtils - .getField(extension, "statusHttpMapper"); - Map statusMappings = mapper.getStatusMapping(); - assertThat(statusMappings).containsEntry("DOWN", 503); - assertThat(statusMappings).containsEntry("OUT_OF_SERVICE", 503); - assertThat(statusMappings).containsEntry("CUSTOM", 500); - }); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java index 6e8d9afd7a..9ddcc39f2a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/JmxEndpointIntegrationTests.java @@ -55,7 +55,7 @@ public class JmxEndpointIntegrationTests { MBeanServer mBeanServer = context.getBean(MBeanServer.class); checkEndpointMBeans(mBeanServer, new String[] { "beans", "conditions", "configprops", "env", "health", - "info", "mappings", "status", "threaddump", "trace" }, + "info", "mappings", "threaddump", "trace" }, new String[] { "shutdown" }); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebEndpointsAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebEndpointsAutoConfigurationIntegrationTests.java index 5085aed7d0..853eff54e0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebEndpointsAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebEndpointsAutoConfigurationIntegrationTests.java @@ -21,8 +21,6 @@ import org.junit.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.actuate.health.HealthEndpointWebExtension; import org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension; -import org.springframework.boot.actuate.health.ReactiveStatusEndpointWebExtension; -import org.springframework.boot.actuate.health.StatusEndpointWebExtension; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; @@ -62,24 +60,12 @@ public class WebEndpointsAutoConfigurationIntegrationTests { .hasSingleBean(HealthEndpointWebExtension.class)); } - @Test - public void statusEndpointWebExtensionIsAutoConfigured() { - servletWebRunner().run((context) -> assertThat(context) - .hasSingleBean(StatusEndpointWebExtension.class)); - } - @Test public void healthEndpointReactiveWebExtensionIsAutoConfigured() { reactiveWebRunner().run((context) -> assertThat(context) .hasSingleBean(ReactiveHealthEndpointWebExtension.class)); } - @Test - public void statusEndpointReactiveWebExtensionIsAutoConfigured() { - reactiveWebRunner().run((context) -> assertThat(context) - .hasSingleBean(ReactiveStatusEndpointWebExtension.class)); - } - private WebApplicationContextRunner servletWebRunner() { return new WebApplicationContextRunner() .withConfiguration( diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java index 8d85b05f4c..d9d2cc403b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointExposureIntegrationTests.java @@ -69,11 +69,10 @@ public class WebMvcEndpointExposureIntegrationTests { assertThat(isExposed(mvc, HttpMethod.GET, "conditions")).isFalse(); assertThat(isExposed(mvc, HttpMethod.GET, "configprops")).isFalse(); assertThat(isExposed(mvc, HttpMethod.GET, "env")).isFalse(); - assertThat(isExposed(mvc, HttpMethod.GET, "health")).isFalse(); + assertThat(isExposed(mvc, HttpMethod.GET, "health")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "info")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "mappings")).isFalse(); assertThat(isExposed(mvc, HttpMethod.POST, "shutdown")).isFalse(); - assertThat(isExposed(mvc, HttpMethod.GET, "status")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "threaddump")).isFalse(); assertThat(isExposed(mvc, HttpMethod.GET, "trace")).isFalse(); }); @@ -93,7 +92,6 @@ public class WebMvcEndpointExposureIntegrationTests { assertThat(isExposed(mvc, HttpMethod.GET, "info")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "mappings")).isTrue(); assertThat(isExposed(mvc, HttpMethod.POST, "shutdown")).isFalse(); - assertThat(isExposed(mvc, HttpMethod.GET, "status")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "threaddump")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "trace")).isTrue(); }); @@ -113,7 +111,6 @@ public class WebMvcEndpointExposureIntegrationTests { assertThat(isExposed(mvc, HttpMethod.GET, "info")).isFalse(); assertThat(isExposed(mvc, HttpMethod.GET, "mappings")).isFalse(); assertThat(isExposed(mvc, HttpMethod.POST, "shutdown")).isFalse(); - assertThat(isExposed(mvc, HttpMethod.GET, "status")).isFalse(); assertThat(isExposed(mvc, HttpMethod.GET, "threaddump")).isFalse(); assertThat(isExposed(mvc, HttpMethod.GET, "trace")).isFalse(); }); @@ -134,7 +131,6 @@ public class WebMvcEndpointExposureIntegrationTests { assertThat(isExposed(mvc, HttpMethod.GET, "info")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "mappings")).isTrue(); assertThat(isExposed(mvc, HttpMethod.POST, "shutdown")).isFalse(); - assertThat(isExposed(mvc, HttpMethod.GET, "status")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "threaddump")).isTrue(); assertThat(isExposed(mvc, HttpMethod.GET, "trace")).isTrue(); }); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpoint.java index 82e08bca3c..e242c43ed2 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpoint.java @@ -20,7 +20,7 @@ import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; /** - * {@link Endpoint} to expose application health. + * {@link Endpoint} to expose application health information. * * @author Dave Syer * @author Christian Dupuis @@ -32,17 +32,25 @@ public class HealthEndpoint { private final HealthIndicator healthIndicator; + private final boolean showDetails; + /** * Create a new {@link HealthEndpoint} instance. * @param healthIndicator the health indicator + * @param showDetails if full details should be returned instead of just the status */ - public HealthEndpoint(HealthIndicator healthIndicator) { + public HealthEndpoint(HealthIndicator healthIndicator, boolean showDetails) { this.healthIndicator = healthIndicator; + this.showDetails = showDetails; } @ReadOperation public Health health() { - return this.healthIndicator.health(); + Health health = this.healthIndicator.health(); + if (this.showDetails) { + return health; + } + return Health.status(health.getStatus()).build(); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthEndpointWebExtension.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthEndpointWebExtension.java index 2d54eb11d4..e025dddd8a 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthEndpointWebExtension.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveHealthEndpointWebExtension.java @@ -35,16 +35,22 @@ public class ReactiveHealthEndpointWebExtension { private final HealthStatusHttpMapper statusHttpMapper; + private final boolean showDetails; + public ReactiveHealthEndpointWebExtension(ReactiveHealthIndicator delegate, - HealthStatusHttpMapper statusHttpMapper) { + HealthStatusHttpMapper statusHttpMapper, boolean showDetails) { this.delegate = delegate; this.statusHttpMapper = statusHttpMapper; + this.showDetails = showDetails; } @ReadOperation public Mono> health() { return this.delegate.health().map((health) -> { Integer status = this.statusHttpMapper.mapStatus(health.getStatus()); + if (!this.showDetails) { + health = Health.status(health.getStatus()).build(); + } return new WebEndpointResponse<>(health, status); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveStatusEndpointWebExtension.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveStatusEndpointWebExtension.java deleted file mode 100644 index 09577b243b..0000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/ReactiveStatusEndpointWebExtension.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import reactor.core.publisher.Mono; - -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; -import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse; -import org.springframework.boot.actuate.endpoint.web.annotation.EndpointWebExtension; - -/** - * Reactive {@link EndpointWebExtension} for the {@link StatusEndpoint}. - * - * @author Stephane Nicoll - * @since 2.0.0 - */ -@EndpointWebExtension(endpoint = StatusEndpoint.class) -public class ReactiveStatusEndpointWebExtension { - - private final ReactiveHealthIndicator delegate; - - private final HealthStatusHttpMapper statusHttpMapper; - - public ReactiveStatusEndpointWebExtension(ReactiveHealthIndicator delegate, - HealthStatusHttpMapper statusHttpMapper) { - this.delegate = delegate; - this.statusHttpMapper = statusHttpMapper; - } - - @ReadOperation - public Mono> health() { - return this.delegate.health().map((health) -> { - Integer status = this.statusHttpMapper.mapStatus(health.getStatus()); - return new WebEndpointResponse<>(Health.status(health.getStatus()).build(), - status); - }); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/StatusEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/StatusEndpoint.java deleted file mode 100644 index b7245761ac..0000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/StatusEndpoint.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - -/** - * {@link Endpoint} to expose application {@link Status}. - * - * @author Stephane Nicoll - * @since 2.0.0 - */ -@Endpoint(id = "status") -public class StatusEndpoint { - - private final HealthIndicator healthIndicator; - - /** - * Create a new {@link StatusEndpoint} instance. - * @param healthIndicator the health indicator - */ - public StatusEndpoint(HealthIndicator healthIndicator) { - this.healthIndicator = healthIndicator; - } - - @ReadOperation - public Health health() { - return Health.status(this.healthIndicator.health().getStatus()).build(); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/StatusEndpointWebExtension.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/StatusEndpointWebExtension.java deleted file mode 100644 index 5b84192248..0000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/StatusEndpointWebExtension.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; -import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse; -import org.springframework.boot.actuate.endpoint.web.annotation.EndpointWebExtension; - -/** - * {@link EndpointWebExtension} for the {@link StatusEndpoint}. - * - * @author Stephane Nicoll - * @since 2.0.0 - */ -@EndpointWebExtension(endpoint = StatusEndpoint.class) -public class StatusEndpointWebExtension { - - private final StatusEndpoint delegate; - - private final HealthStatusHttpMapper statusHttpMapper; - - public StatusEndpointWebExtension(StatusEndpoint delegate, - HealthStatusHttpMapper statusHttpMapper) { - this.delegate = delegate; - this.statusHttpMapper = statusHttpMapper; - } - - @ReadOperation - public WebEndpointResponse getHealth() { - Health health = this.delegate.health(); - Integer status = this.statusHttpMapper.mapStatus(health.getStatus()); - return new WebEndpointResponse<>(health, status); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointTests.java index 66da11d9ae..cf4efbee01 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointTests.java @@ -41,7 +41,7 @@ public class HealthEndpointTests { healthIndicators.put("upAgain", () -> new Health.Builder().status(Status.UP) .withDetail("second", "2").build()); HealthEndpoint endpoint = new HealthEndpoint( - createHealthIndicator(healthIndicators)); + createHealthIndicator(healthIndicators), true); Health health = endpoint.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails()).containsOnlyKeys("up", "upAgain"); @@ -51,6 +51,20 @@ public class HealthEndpointTests { assertThat(upAgainHealth.getDetails()).containsOnly(entry("second", "2")); } + @Test + public void onlyStatusIsExposed() { + Map healthIndicators = new HashMap<>(); + healthIndicators.put("up", () -> new Health.Builder().status(Status.UP) + .withDetail("first", "1").build()); + healthIndicators.put("upAgain", () -> new Health.Builder().status(Status.UP) + .withDetail("second", "2").build()); + HealthEndpoint endpoint = new HealthEndpoint( + createHealthIndicator(healthIndicators), false); + Health health = endpoint.health(); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails()).isEmpty(); + } + private HealthIndicator createHealthIndicator( Map healthIndicators) { return new CompositeHealthIndicatorFactory() diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointWebIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointWebIntegrationTests.java index 40e1dc8aff..f18df378ba 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointWebIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointWebIntegrationTests.java @@ -67,7 +67,8 @@ public class HealthEndpointWebIntegrationTests { Map healthIndicators) { return new HealthEndpoint( new CompositeHealthIndicatorFactory().createHealthIndicator( - new OrderedHealthAggregator(), healthIndicators)); + new OrderedHealthAggregator(), healthIndicators), + true); } @Bean diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/StatusEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/StatusEndpointTests.java deleted file mode 100644 index d58c98c145..0000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/StatusEndpointTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link StatusEndpoint}. - * - * @author Stephane Nicoll - */ -public class StatusEndpointTests { - - @Test - public void onlyStatusIsExposed() { - Map healthIndicators = new HashMap<>(); - healthIndicators.put("up", () -> new Health.Builder().status(Status.UP) - .withDetail("first", "1").build()); - healthIndicators.put("upAgain", () -> new Health.Builder().status(Status.UP) - .withDetail("second", "2").build()); - StatusEndpoint endpoint = new StatusEndpoint( - createHealthIndicator(healthIndicators)); - Health health = endpoint.health(); - assertThat(health.getStatus()).isEqualTo(Status.UP); - assertThat(health.getDetails()).isEmpty(); - } - - private HealthIndicator createHealthIndicator( - Map healthIndicators) { - return new CompositeHealthIndicatorFactory() - .createHealthIndicator(new OrderedHealthAggregator(), healthIndicators); - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/StatusEndpointWebIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/StatusEndpointWebIntegrationTests.java deleted file mode 100644 index 12ccf5bf67..0000000000 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/StatusEndpointWebIntegrationTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.health; - -import java.util.Map; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; -import org.springframework.test.web.reactive.server.WebTestClient; - -/** - * Integration tests for {@link StatusEndpoint} and {@link StatusEndpointWebExtension} - * exposed by Jersey, Spring MVC, and WebFlux. - * - * @author Stephane Nicoll - */ -@RunWith(WebEndpointRunners.class) -public class StatusEndpointWebIntegrationTests { - - private static WebTestClient client; - - private static ConfigurableApplicationContext context; - - @Test - public void whenStatusIsUp200ResponseIsReturned() throws Exception { - client.get().uri("/application/status").exchange().expectStatus().isOk() - .expectBody().json("{\"status\":\"UP\"}"); - } - - @Test - public void whenStatusIsDown503ResponseIsReturned() throws Exception { - context.getBean("alphaHealthIndicator", TestHealthIndicator.class) - .setHealth(Health.down().build()); - client.get().uri("/application/status").exchange().expectStatus() - .isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody() - .json("{\"status\":\"DOWN\"}"); - } - - @Configuration - public static class TestConfiguration { - - @Bean - public StatusEndpoint statusEndpoint( - Map healthIndicators) { - return new StatusEndpoint( - new CompositeHealthIndicatorFactory().createHealthIndicator( - new OrderedHealthAggregator(), healthIndicators)); - } - - @Bean - public StatusEndpointWebExtension statusWebEndpointExtension( - StatusEndpoint delegate) { - return new StatusEndpointWebExtension(delegate, new HealthStatusHttpMapper()); - } - - @Bean - public TestHealthIndicator alphaHealthIndicator() { - return new TestHealthIndicator(); - } - - @Bean - public TestHealthIndicator bravoHealthIndicator() { - return new TestHealthIndicator(); - } - - } - - private static class TestHealthIndicator implements HealthIndicator { - - private Health health = Health.up().build(); - - @Override - public Health health() { - Health result = this.health; - this.health = Health.up().build(); - return result; - } - - void setHealth(Health health) { - this.health = health; - } - - } - -} diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index cffdd2a7c4..42b094d55f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -1165,6 +1165,7 @@ content into your application. Rather, pick only the properties that you need. # HEALTH ENDPOINT ({sc-spring-boot-actuator}/health/HealthEndpoint.{sc-ext}[HealthEndpoint]) management.endpoint.health.cache.time-to-live=0ms # Maximum time that a response can be cached. management.endpoint.health.enabled= # Whether to enable the health endpoint. + management.endpoint.health.show-details= # Whether to show full health details # HEAP DUMP ENDPOINT ({sc-spring-boot-actuator}/management/HeapDumpWebEndpoint.{sc-ext}[HeapDumpWebEndpoint]) management.endpoint.heapdump.cache.time-to-live=0ms # Maximum time that a response can be cached. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index a3d9637852..10298a4a0d 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -111,10 +111,6 @@ The following technology-agnostic endpoints are available: |`shutdown` |Lets the application be gracefully shutdown (not enabled by default). -|`status` -|Shows application status information (that is, `health` status with no additional - details). - |`threaddump` |Performs a thread dump. diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java index f2dec4b150..09e84151d8 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java @@ -41,7 +41,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { // @formatter:off http.authorizeRequests() - .requestMatchers(EndpointRequest.to("status", "info")).permitAll() + .requestMatchers(EndpointRequest.to("health", "info")).permitAll() .requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ACTUATOR") .requestMatchers(StaticResourceRequest.toCommonLocations()).permitAll() .antMatchers("/foo").permitAll() diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/application.properties index 82d76b8103..40495af311 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/application.properties @@ -1 +1,2 @@ management.endpoints.web.expose=* +management.endpoint.health.show-details=true diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java index e3d2ca3355..1e5e39792b 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -57,9 +57,9 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @Test public void testSecureActuator() throws Exception { - ResponseEntity entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.managementPort - + "/management/application/health", String.class); + ResponseEntity entity = new TestRestTemplate().getForEntity( + "http://localhost:" + this.managementPort + "/management/application/env", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @@ -67,7 +67,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { public void testInsecureActuator() throws Exception { ResponseEntity entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.managementPort - + "/management/application/status", String.class); + + "/management/application/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java index e422b417c5..25260a0084 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java @@ -73,7 +73,7 @@ public class SampleActuatorCustomSecurityApplicationTests { @Test public void insecureActuator() throws Exception { ResponseEntity entity = this.restTemplate - .getForEntity("/application/status", String.class); + .getForEntity("/application/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties b/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties index 5731e5dadb..1878d188cc 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties @@ -1,2 +1,3 @@ server.error.path: /oops -management.endpoints.web.base-path: /admin \ No newline at end of file +management.endpoint.health.show-details: true +management.endpoints.web.base-path: /admin diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java index a1e655741d..96797fd9fa 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java @@ -61,7 +61,7 @@ public class SampleJerseyApplicationTests { @Test public void actuatorStatus() { ResponseEntity entity = this.restTemplate - .getForEntity("/application/status", String.class); + .getForEntity("/application/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); } diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java index 1c3b1380f1..d86a7fa478 100644 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java @@ -48,7 +48,7 @@ public class SampleSecureWebFluxApplicationTests { @Test public void actuatorsSecureByDefault() { - this.webClient.get().uri("/application/status").accept(MediaType.APPLICATION_JSON) + this.webClient.get().uri("/application/health").accept(MediaType.APPLICATION_JSON) .exchange().expectStatus().isUnauthorized(); } @@ -61,7 +61,7 @@ public class SampleSecureWebFluxApplicationTests { @Test public void actuatorsAccessibleOnLogin() { - this.webClient.get().uri("/application/status").accept(MediaType.APPLICATION_JSON) + this.webClient.get().uri("/application/health").accept(MediaType.APPLICATION_JSON) .header("Authorization", "basic " + getBasicAuth()).exchange() .expectBody(String.class).isEqualTo("{\"status\":\"UP\"}"); } diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java index 3381a9ff5e..7fcb6f696b 100644 --- a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java @@ -55,7 +55,7 @@ public class SampleWebFluxApplicationTests { @Test public void testActuatorStatus() { - this.webClient.get().uri("/application/status").accept(MediaType.APPLICATION_JSON) + this.webClient.get().uri("/application/health").accept(MediaType.APPLICATION_JSON) .exchange().expectStatus().isOk().expectBody() .json("{\"status\":\"UP\"}"); }