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-11113pull/11128/head
parent
d99625fa78
commit
31025d9f6c
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<String, HealthIndicator> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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<WebEndpointResponse<Health>> health() {
|
||||
return this.delegate.health().map((health) -> {
|
||||
Integer status = this.statusHttpMapper.mapStatus(health.getStatus());
|
||||
return new WebEndpointResponse<>(Health.status(health.getStatus()).build(),
|
||||
status);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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<Health> getHealth() {
|
||||
Health health = this.delegate.health();
|
||||
Integer status = this.statusHttpMapper.mapStatus(health.getStatus());
|
||||
return new WebEndpointResponse<>(health, status);
|
||||
}
|
||||
|
||||
}
|
@ -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<String, HealthIndicator> 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<String, HealthIndicator> healthIndicators) {
|
||||
return new CompositeHealthIndicatorFactory()
|
||||
.createHealthIndicator(new OrderedHealthAggregator(), healthIndicators);
|
||||
}
|
||||
|
||||
}
|
@ -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<String, HealthIndicator> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1 +1,2 @@
|
||||
management.endpoints.web.expose=*
|
||||
management.endpoint.health.show-details=true
|
||||
|
@ -1,2 +1,3 @@
|
||||
server.error.path: /oops
|
||||
management.endpoints.web.base-path: /admin
|
||||
management.endpoint.health.show-details: true
|
||||
management.endpoints.web.base-path: /admin
|
||||
|
Loading…
Reference in New Issue