Merge branch '2.7.x' into main

pull/29592/head
Madhura Bhave 3 years ago
commit 8125b46ed5

@ -54,7 +54,7 @@ public class CachesEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnBean(CachesEndpoint.class) @ConditionalOnBean(CachesEndpoint.class)
@ConditionalOnAvailableEndpoint(exposure = EndpointExposure.WEB) @ConditionalOnAvailableEndpoint(exposure = { EndpointExposure.WEB, EndpointExposure.CLOUD_FOUNDRY })
public CachesEndpointWebExtension cachesEndpointWebExtension(CachesEndpoint cachesEndpoint) { public CachesEndpointWebExtension cachesEndpointWebExtension(CachesEndpoint cachesEndpoint) {
return new CachesEndpointWebExtension(cachesEndpoint); return new CachesEndpointWebExtension(cachesEndpoint);
} }

@ -63,7 +63,7 @@ public class ConfigurationPropertiesReportEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnBean(ConfigurationPropertiesReportEndpoint.class) @ConditionalOnBean(ConfigurationPropertiesReportEndpoint.class)
@ConditionalOnAvailableEndpoint(exposure = EndpointExposure.WEB) @ConditionalOnAvailableEndpoint(exposure = { EndpointExposure.WEB, EndpointExposure.CLOUD_FOUNDRY })
public ConfigurationPropertiesReportEndpointWebExtension configurationPropertiesReportEndpointWebExtension( public ConfigurationPropertiesReportEndpointWebExtension configurationPropertiesReportEndpointWebExtension(
ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint) { ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint) {
return new ConfigurationPropertiesReportEndpointWebExtension(configurationPropertiesReportEndpoint); return new ConfigurationPropertiesReportEndpointWebExtension(configurationPropertiesReportEndpoint);

@ -113,9 +113,6 @@ class OnAvailableEndpointCondition extends SpringBootCondition {
if (!enablementOutcome.isMatch()) { if (!enablementOutcome.isMatch()) {
return enablementOutcome; return enablementOutcome;
} }
if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
return ConditionOutcome.match(message.because("application is running on Cloud Foundry"));
}
Set<EndpointExposure> exposuresToCheck = getExposuresToCheck(conditionAnnotation); Set<EndpointExposure> exposuresToCheck = getExposuresToCheck(conditionAnnotation);
Set<ExposureFilter> exposureFilters = getExposureFilters(environment); Set<ExposureFilter> exposureFilters = getExposureFilters(environment);
for (ExposureFilter exposureFilter : exposureFilters) { for (ExposureFilter exposureFilter : exposureFilters) {
@ -168,6 +165,9 @@ class OnAvailableEndpointCondition extends SpringBootCondition {
if (environment.getProperty(JMX_ENABLED_KEY, Boolean.class, false)) { if (environment.getProperty(JMX_ENABLED_KEY, Boolean.class, false)) {
exposureFilters.add(new ExposureFilter(environment, EndpointExposure.JMX)); exposureFilters.add(new ExposureFilter(environment, EndpointExposure.JMX));
} }
if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
exposureFilters.add(new ExposureFilter(environment, EndpointExposure.CLOUD_FOUNDRY));
}
exposureFilters.add(new ExposureFilter(environment, EndpointExposure.WEB)); exposureFilters.add(new ExposureFilter(environment, EndpointExposure.WEB));
exposureFiltersCache.put(environment, exposureFilters); exposureFiltersCache.put(environment, exposureFilters);
} }
@ -181,9 +181,16 @@ class OnAvailableEndpointCondition extends SpringBootCondition {
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
private ExposureFilter(Environment environment, EndpointExposure exposure) { private ExposureFilter(Environment environment, EndpointExposure exposure) {
super((Class) ExposableEndpoint.class, environment, super((Class) ExposableEndpoint.class, environment,
"management.endpoints." + exposure.name().toLowerCase() + ".exposure", "management.endpoints." + getCanonicalName(exposure) + ".exposure", exposure.getDefaultIncludes());
exposure.getDefaultIncludes());
this.exposure = exposure; this.exposure = exposure;
}
private static String getCanonicalName(EndpointExposure exposure) {
if (EndpointExposure.CLOUD_FOUNDRY.equals(exposure)) {
return "cloud-foundry";
}
return exposure.name().toLowerCase();
} }
EndpointExposure getExposure() { EndpointExposure getExposure() {

@ -32,7 +32,13 @@ public enum EndpointExposure {
/** /**
* Exposed via a web endpoint. * Exposed via a web endpoint.
*/ */
WEB("health"); WEB("health"),
/**
* Exposed on Cloud Foundry via `/cloudfoundryapplication`.
* @since 2.6.4
*/
CLOUD_FOUNDRY("*");
private final String[] defaultIncludes; private final String[] defaultIncludes;

@ -61,7 +61,7 @@ public class EnvironmentEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnBean(EnvironmentEndpoint.class) @ConditionalOnBean(EnvironmentEndpoint.class)
@ConditionalOnAvailableEndpoint(exposure = EndpointExposure.WEB) @ConditionalOnAvailableEndpoint(exposure = { EndpointExposure.WEB, EndpointExposure.CLOUD_FOUNDRY })
public EnvironmentEndpointWebExtension environmentEndpointWebExtension(EnvironmentEndpoint environmentEndpoint) { public EnvironmentEndpointWebExtension environmentEndpointWebExtension(EnvironmentEndpoint environmentEndpoint) {
return new EnvironmentEndpointWebExtension(environmentEndpoint); return new EnvironmentEndpointWebExtension(environmentEndpoint);
} }

@ -45,7 +45,8 @@ import org.springframework.context.annotation.Configuration;
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.REACTIVE) @ConditionalOnWebApplication(type = Type.REACTIVE)
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB) @ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class,
exposure = { EndpointExposure.WEB, EndpointExposure.CLOUD_FOUNDRY })
class HealthEndpointReactiveWebExtensionConfiguration { class HealthEndpointReactiveWebExtensionConfiguration {
@Bean @Bean
@ -57,6 +58,7 @@ class HealthEndpointReactiveWebExtensionConfiguration {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB)
static class WebFluxAdditionalHealthEndpointPathsConfiguration { static class WebFluxAdditionalHealthEndpointPathsConfiguration {
@Bean @Bean

@ -46,7 +46,8 @@ import org.springframework.web.servlet.DispatcherServlet;
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnBean(HealthEndpoint.class) @ConditionalOnBean(HealthEndpoint.class)
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB) @ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class,
exposure = { EndpointExposure.WEB, EndpointExposure.CLOUD_FOUNDRY })
class HealthEndpointWebExtensionConfiguration { class HealthEndpointWebExtensionConfiguration {
@Bean @Bean
@ -63,6 +64,7 @@ class HealthEndpointWebExtensionConfiguration {
} }
@ConditionalOnBean(DispatcherServlet.class) @ConditionalOnBean(DispatcherServlet.class)
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class, exposure = EndpointExposure.WEB)
static class MvcAdditionalHealthEndpointPathsConfiguration { static class MvcAdditionalHealthEndpointPathsConfiguration {
@Bean @Bean

@ -54,7 +54,7 @@ public class QuartzEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnBean(QuartzEndpoint.class) @ConditionalOnBean(QuartzEndpoint.class)
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnAvailableEndpoint(exposure = EndpointExposure.WEB) @ConditionalOnAvailableEndpoint(exposure = { EndpointExposure.WEB, EndpointExposure.CLOUD_FOUNDRY })
public QuartzEndpointWebExtension quartzEndpointWebExtension(QuartzEndpoint endpoint) { public QuartzEndpointWebExtension quartzEndpointWebExtension(QuartzEndpoint endpoint) {
return new QuartzEndpointWebExtension(endpoint); return new QuartzEndpointWebExtension(endpoint);
} }

@ -327,7 +327,8 @@ class ConditionalOnAvailableEndpointTests {
static class ExposureEndpointConfiguration { static class ExposureEndpointConfiguration {
@Bean @Bean
@ConditionalOnAvailableEndpoint(endpoint = TestEndpoint.class, exposure = EndpointExposure.WEB) @ConditionalOnAvailableEndpoint(endpoint = TestEndpoint.class,
exposure = { EndpointExposure.WEB, EndpointExposure.CLOUD_FOUNDRY })
String unexposed() { String unexposed() {
return "unexposed"; return "unexposed";
} }

@ -91,6 +91,30 @@ abstract class AbstractHealthEndpointAdditionalPathIntegrationTests<T extends Ab
.exchange().expectStatus().isNotFound(), "local.server.port")); .exchange().expectStatus().isNotFound(), "local.server.port"));
} }
@Test
void groupsAreNotConfiguredWhenHealthEndpointIsNotExposedAndCloudFoundryPlatform() {
this.runner.withPropertyValues("spring.jmx.enabled=true", "management.endpoints.web.exposure.exclude=health",
"spring.main.cloud-platform=cloud_foundry", "management.endpoint.health.group.live.include=diskSpace",
"management.endpoint.health.group.live.additional-path=server:healthz",
"management.endpoint.health.group.live.show-components=always")
.withInitializer(new ConditionEvaluationReportLoggingListener())
.run(withWebTestClient((client) -> client.get().uri("/healthz").accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isNotFound(), "local.server.port"));
}
@Test
void groupsAreNotConfiguredWhenHealthEndpointIsNotExposedWithDifferentManagementPortAndCloudFoundryPlatform() {
this.runner
.withPropertyValues("spring.jmx.enabled=true", "management.endpoints.web.exposure.exclude=health",
"spring.main.cloud-platform=cloud_foundry", "management.server.port=0",
"management.endpoint.health.group.live.include=diskSpace",
"management.endpoint.health.group.live.additional-path=server:healthz",
"management.endpoint.health.group.live.show-components=always")
.withInitializer(new ConditionEvaluationReportLoggingListener())
.run(withWebTestClient((client) -> client.get().uri("/healthz").accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isNotFound(), "local.server.port"));
}
private void testResponse(WebTestClient client) { private void testResponse(WebTestClient client) {
client.get().uri("/healthz").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody() client.get().uri("/healthz").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("status").isEqualTo("UP").jsonPath("components.diskSpace").exists(); .jsonPath("status").isEqualTo("UP").jsonPath("components.diskSpace").exists();

Loading…
Cancel
Save