Make sure Reactive health indicators take precedence

This commit restores the highest precedence of reactive
HealthContributor over imperative one. Previously, both would be
registered, leading to duplicate entries in health output.

Closes gh-18748
This commit is contained in:
Stephane Nicoll 2019-10-28 12:24:09 +01:00
parent a664eadb9a
commit d7652e8f14
12 changed files with 57 additions and 24 deletions

View File

@ -47,7 +47,8 @@ import org.springframework.data.cassandra.core.CassandraOperations;
@ConditionalOnClass({ Cluster.class, CassandraOperations.class })
@ConditionalOnBean(CassandraOperations.class)
@ConditionalOnEnabledHealthIndicator("cassandra")
@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class })
@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
CassandraReactiveHealthContributorAutoConfiguration.class })
public class CassandraHealthContributorAutoConfiguration
extends CompositeHealthContributorConfiguration<CassandraHealthIndicator, CassandraOperations> {

View File

@ -51,8 +51,8 @@ public class CassandraReactiveHealthContributorAutoConfiguration extends
CompositeReactiveHealthContributorConfiguration<CassandraReactiveHealthIndicator, ReactiveCassandraOperations> {
@Bean
@ConditionalOnMissingBean(name = { "cassandraReactiveHealthIndicator", "cassandraReactiveHealthContributor" })
public ReactiveHealthContributor cassandraReactiveHealthContributor(
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
public ReactiveHealthContributor cassandraHealthContributor(
Map<String, ReactiveCassandraOperations> reactiveCassandraOperations) {
return createContributor(reactiveCassandraOperations);
}

View File

@ -45,12 +45,12 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnClass(Cluster.class)
@ConditionalOnBean(Cluster.class)
@ConditionalOnEnabledHealthIndicator("couchbase")
@AutoConfigureAfter({ CouchbaseAutoConfiguration.class })
@AutoConfigureAfter({ CouchbaseAutoConfiguration.class, CouchbaseReactiveHealthContributorAutoConfiguration.class })
public class CouchbaseHealthContributorAutoConfiguration
extends CompositeHealthContributorConfiguration<CouchbaseHealthIndicator, Cluster> {
@Bean
@ConditionalOnMissingBean(name = { "couchbaseHealthContributor", "couchbaseHealthContributor" })
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
public HealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
return createContributor(clusters);
}

View File

@ -50,8 +50,8 @@ public class CouchbaseReactiveHealthContributorAutoConfiguration
extends CompositeReactiveHealthContributorConfiguration<CouchbaseReactiveHealthIndicator, Cluster> {
@Bean
@ConditionalOnMissingBean(name = { "couchbaseReactiveHealthIndicator", "couchbaseReactiveHealthContributor" })
public ReactiveHealthContributor couchbaseReactiveHealthContributor(Map<String, Cluster> clusters) {
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
public ReactiveHealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
return createContributor(clusters);
}

View File

@ -43,7 +43,8 @@ import org.springframework.data.mongodb.core.MongoTemplate;
@ConditionalOnClass(MongoTemplate.class)
@ConditionalOnBean(MongoTemplate.class)
@ConditionalOnEnabledHealthIndicator("mongo")
@AutoConfigureAfter({ MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
@AutoConfigureAfter({ MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
MongoReactiveHealthContributorAutoConfiguration.class })
public class MongoHealthContributorAutoConfiguration
extends CompositeHealthContributorConfiguration<MongoHealthIndicator, MongoTemplate> {

View File

@ -50,9 +50,8 @@ public class MongoReactiveHealthContributorAutoConfiguration
extends CompositeReactiveHealthContributorConfiguration<MongoReactiveHealthIndicator, ReactiveMongoTemplate> {
@Bean
@ConditionalOnMissingBean(name = { "mongoReactiveHealthIndicator", "mongoReactiveHealthContributor" })
public ReactiveHealthContributor mongoReactiveHealthContributor(
Map<String, ReactiveMongoTemplate> reactiveMongoTemplates) {
@ConditionalOnMissingBean(name = { "mongoHealthIndicator", "mongoHealthContributor" })
public ReactiveHealthContributor mongoHealthContributor(Map<String, ReactiveMongoTemplate> reactiveMongoTemplates) {
return createContributor(reactiveMongoTemplates);
}

View File

@ -45,7 +45,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
@ConditionalOnClass(RedisConnectionFactory.class)
@ConditionalOnBean(RedisConnectionFactory.class)
@ConditionalOnEnabledHealthIndicator("redis")
@AutoConfigureAfter(RedisAutoConfiguration.class)
@AutoConfigureAfter({ RedisAutoConfiguration.class, RedisReactiveHealthContributorAutoConfiguration.class })
public class RedisHealthContributorAutoConfiguration
extends CompositeHealthContributorConfiguration<RedisHealthIndicator, RedisConnectionFactory> {

View File

@ -60,8 +60,8 @@ public class RedisReactiveHealthContributorAutoConfiguration extends
}
@Bean
@ConditionalOnMissingBean(name = { "redisReactiveHealthIndicator", "redisReactiveHealthContributor" })
public ReactiveHealthContributor redisReactiveHealthContributor() {
@ConditionalOnMissingBean(name = { "redisHealthIndicator", "redisHealthContributor" })
public ReactiveHealthContributor redisHealthContributor() {
return createContributor(this.redisConnectionFactories);
}

View File

@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.cassandra;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorAutoConfigurationTests.CassandraConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
@ -44,13 +45,23 @@ class CassandraReactiveHealthContributorAutoConfigurationTests {
@Test
void runShouldCreateIndicator() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class)
.doesNotHaveBean(CassandraHealthIndicator.class));
.hasBean("cassandraHealthContributor"));
}
@Test
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
this.contextRunner
.withConfiguration(AutoConfigurations.of(CassandraConfiguration.class,
CassandraHealthContributorAutoConfiguration.class))
.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class)
.hasBean("cassandraHealthContributor").doesNotHaveBean(CassandraHealthIndicator.class));
}
@Test
void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class));
.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class)
.doesNotHaveBean("cassandraHealthContributor"));
}
}

View File

@ -43,13 +43,21 @@ class CouchbaseReactiveHealthContributorAutoConfigurationTests {
@Test
void runShouldCreateIndicator() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CouchbaseReactiveHealthIndicator.class)
.doesNotHaveBean(CouchbaseHealthIndicator.class));
.hasBean("couchbaseHealthContributor"));
}
@Test
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
this.contextRunner.withConfiguration(AutoConfigurations.of(CouchbaseHealthContributorAutoConfiguration.class))
.run((context) -> assertThat(context).hasSingleBean(CouchbaseReactiveHealthIndicator.class)
.hasBean("couchbaseHealthContributor").doesNotHaveBean(CouchbaseHealthIndicator.class));
}
@Test
void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(CouchbaseReactiveHealthIndicator.class));
.run((context) -> assertThat(context).doesNotHaveBean(CouchbaseReactiveHealthIndicator.class)
.doesNotHaveBean("couchbaseHealthContributor"));
}
}

View File

@ -45,14 +45,21 @@ class MongoReactiveHealthContributorAutoConfigurationTests {
@Test
void runShouldCreateIndicator() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(MongoReactiveHealthIndicator.class)
.doesNotHaveBean(MongoHealthIndicator.class));
.hasBean("mongoHealthContributor"));
}
@Test
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoHealthContributorAutoConfiguration.class))
.run((context) -> assertThat(context).hasSingleBean(MongoReactiveHealthIndicator.class)
.hasBean("mongoHealthContributor").doesNotHaveBean(MongoHealthIndicator.class));
}
@Test
void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.mongo.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(MongoReactiveHealthIndicator.class)
.doesNotHaveBean(MongoHealthIndicator.class));
.doesNotHaveBean("mongoHealthContributor"));
}
}

View File

@ -40,16 +40,22 @@ class RedisReactiveHealthContributorAutoConfigurationTests {
@Test
void runShouldCreateIndicator() {
this.contextRunner.run(
(context) -> assertThat(context).hasSingleBean(RedisReactiveHealthContributorAutoConfiguration.class)
.doesNotHaveBean(RedisHealthIndicator.class));
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(RedisReactiveHealthIndicator.class)
.hasBean("redisHealthContributor"));
}
@Test
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisHealthContributorAutoConfiguration.class))
.run((context) -> assertThat(context).hasSingleBean(RedisReactiveHealthIndicator.class)
.hasBean("redisHealthContributor").doesNotHaveBean(RedisHealthIndicator.class));
}
@Test
void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.redis.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(RedisReactiveHealthIndicator.class)
.doesNotHaveBean(RedisHealthIndicator.class));
.doesNotHaveBean("redisHealthContributor"));
}
}