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:
@@ -47,7 +47,8 @@ import org.springframework.data.cassandra.core.CassandraOperations;
|
|||||||
@ConditionalOnClass({ Cluster.class, CassandraOperations.class })
|
@ConditionalOnClass({ Cluster.class, CassandraOperations.class })
|
||||||
@ConditionalOnBean(CassandraOperations.class)
|
@ConditionalOnBean(CassandraOperations.class)
|
||||||
@ConditionalOnEnabledHealthIndicator("cassandra")
|
@ConditionalOnEnabledHealthIndicator("cassandra")
|
||||||
@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class })
|
@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
|
||||||
|
CassandraReactiveHealthContributorAutoConfiguration.class })
|
||||||
public class CassandraHealthContributorAutoConfiguration
|
public class CassandraHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<CassandraHealthIndicator, CassandraOperations> {
|
extends CompositeHealthContributorConfiguration<CassandraHealthIndicator, CassandraOperations> {
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class CassandraReactiveHealthContributorAutoConfiguration extends
|
|||||||
CompositeReactiveHealthContributorConfiguration<CassandraReactiveHealthIndicator, ReactiveCassandraOperations> {
|
CompositeReactiveHealthContributorConfiguration<CassandraReactiveHealthIndicator, ReactiveCassandraOperations> {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "cassandraReactiveHealthIndicator", "cassandraReactiveHealthContributor" })
|
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||||
public ReactiveHealthContributor cassandraReactiveHealthContributor(
|
public ReactiveHealthContributor cassandraHealthContributor(
|
||||||
Map<String, ReactiveCassandraOperations> reactiveCassandraOperations) {
|
Map<String, ReactiveCassandraOperations> reactiveCassandraOperations) {
|
||||||
return createContributor(reactiveCassandraOperations);
|
return createContributor(reactiveCassandraOperations);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,12 +45,12 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@ConditionalOnClass(Cluster.class)
|
@ConditionalOnClass(Cluster.class)
|
||||||
@ConditionalOnBean(Cluster.class)
|
@ConditionalOnBean(Cluster.class)
|
||||||
@ConditionalOnEnabledHealthIndicator("couchbase")
|
@ConditionalOnEnabledHealthIndicator("couchbase")
|
||||||
@AutoConfigureAfter({ CouchbaseAutoConfiguration.class })
|
@AutoConfigureAfter({ CouchbaseAutoConfiguration.class, CouchbaseReactiveHealthContributorAutoConfiguration.class })
|
||||||
public class CouchbaseHealthContributorAutoConfiguration
|
public class CouchbaseHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<CouchbaseHealthIndicator, Cluster> {
|
extends CompositeHealthContributorConfiguration<CouchbaseHealthIndicator, Cluster> {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "couchbaseHealthContributor", "couchbaseHealthContributor" })
|
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
|
||||||
public HealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
|
public HealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
|
||||||
return createContributor(clusters);
|
return createContributor(clusters);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ public class CouchbaseReactiveHealthContributorAutoConfiguration
|
|||||||
extends CompositeReactiveHealthContributorConfiguration<CouchbaseReactiveHealthIndicator, Cluster> {
|
extends CompositeReactiveHealthContributorConfiguration<CouchbaseReactiveHealthIndicator, Cluster> {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "couchbaseReactiveHealthIndicator", "couchbaseReactiveHealthContributor" })
|
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
|
||||||
public ReactiveHealthContributor couchbaseReactiveHealthContributor(Map<String, Cluster> clusters) {
|
public ReactiveHealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
|
||||||
return createContributor(clusters);
|
return createContributor(clusters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
|||||||
@ConditionalOnClass(MongoTemplate.class)
|
@ConditionalOnClass(MongoTemplate.class)
|
||||||
@ConditionalOnBean(MongoTemplate.class)
|
@ConditionalOnBean(MongoTemplate.class)
|
||||||
@ConditionalOnEnabledHealthIndicator("mongo")
|
@ConditionalOnEnabledHealthIndicator("mongo")
|
||||||
@AutoConfigureAfter({ MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
|
@AutoConfigureAfter({ MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
|
||||||
|
MongoReactiveHealthContributorAutoConfiguration.class })
|
||||||
public class MongoHealthContributorAutoConfiguration
|
public class MongoHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<MongoHealthIndicator, MongoTemplate> {
|
extends CompositeHealthContributorConfiguration<MongoHealthIndicator, MongoTemplate> {
|
||||||
|
|
||||||
|
|||||||
@@ -50,9 +50,8 @@ public class MongoReactiveHealthContributorAutoConfiguration
|
|||||||
extends CompositeReactiveHealthContributorConfiguration<MongoReactiveHealthIndicator, ReactiveMongoTemplate> {
|
extends CompositeReactiveHealthContributorConfiguration<MongoReactiveHealthIndicator, ReactiveMongoTemplate> {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "mongoReactiveHealthIndicator", "mongoReactiveHealthContributor" })
|
@ConditionalOnMissingBean(name = { "mongoHealthIndicator", "mongoHealthContributor" })
|
||||||
public ReactiveHealthContributor mongoReactiveHealthContributor(
|
public ReactiveHealthContributor mongoHealthContributor(Map<String, ReactiveMongoTemplate> reactiveMongoTemplates) {
|
||||||
Map<String, ReactiveMongoTemplate> reactiveMongoTemplates) {
|
|
||||||
return createContributor(reactiveMongoTemplates);
|
return createContributor(reactiveMongoTemplates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|||||||
@ConditionalOnClass(RedisConnectionFactory.class)
|
@ConditionalOnClass(RedisConnectionFactory.class)
|
||||||
@ConditionalOnBean(RedisConnectionFactory.class)
|
@ConditionalOnBean(RedisConnectionFactory.class)
|
||||||
@ConditionalOnEnabledHealthIndicator("redis")
|
@ConditionalOnEnabledHealthIndicator("redis")
|
||||||
@AutoConfigureAfter(RedisAutoConfiguration.class)
|
@AutoConfigureAfter({ RedisAutoConfiguration.class, RedisReactiveHealthContributorAutoConfiguration.class })
|
||||||
public class RedisHealthContributorAutoConfiguration
|
public class RedisHealthContributorAutoConfiguration
|
||||||
extends CompositeHealthContributorConfiguration<RedisHealthIndicator, RedisConnectionFactory> {
|
extends CompositeHealthContributorConfiguration<RedisHealthIndicator, RedisConnectionFactory> {
|
||||||
|
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ public class RedisReactiveHealthContributorAutoConfiguration extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = { "redisReactiveHealthIndicator", "redisReactiveHealthContributor" })
|
@ConditionalOnMissingBean(name = { "redisHealthIndicator", "redisHealthContributor" })
|
||||||
public ReactiveHealthContributor redisReactiveHealthContributor() {
|
public ReactiveHealthContributor redisHealthContributor() {
|
||||||
return createContributor(this.redisConnectionFactories);
|
return createContributor(this.redisConnectionFactories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.cassandra;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
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.autoconfigure.health.HealthContributorAutoConfiguration;
|
||||||
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
|
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
|
||||||
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
|
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
|
||||||
@@ -44,13 +45,23 @@ class CassandraReactiveHealthContributorAutoConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void runShouldCreateIndicator() {
|
void runShouldCreateIndicator() {
|
||||||
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class)
|
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
|
@Test
|
||||||
void runWhenDisabledShouldNotCreateIndicator() {
|
void runWhenDisabledShouldNotCreateIndicator() {
|
||||||
this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false")
|
this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false")
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class));
|
.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class)
|
||||||
|
.doesNotHaveBean("cassandraHealthContributor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,13 +43,21 @@ class CouchbaseReactiveHealthContributorAutoConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void runShouldCreateIndicator() {
|
void runShouldCreateIndicator() {
|
||||||
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CouchbaseReactiveHealthIndicator.class)
|
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
|
@Test
|
||||||
void runWhenDisabledShouldNotCreateIndicator() {
|
void runWhenDisabledShouldNotCreateIndicator() {
|
||||||
this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false")
|
this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false")
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(CouchbaseReactiveHealthIndicator.class));
|
.run((context) -> assertThat(context).doesNotHaveBean(CouchbaseReactiveHealthIndicator.class)
|
||||||
|
.doesNotHaveBean("couchbaseHealthContributor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,14 +45,21 @@ class MongoReactiveHealthContributorAutoConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void runShouldCreateIndicator() {
|
void runShouldCreateIndicator() {
|
||||||
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(MongoReactiveHealthIndicator.class)
|
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
|
@Test
|
||||||
void runWhenDisabledShouldNotCreateIndicator() {
|
void runWhenDisabledShouldNotCreateIndicator() {
|
||||||
this.contextRunner.withPropertyValues("management.health.mongo.enabled:false")
|
this.contextRunner.withPropertyValues("management.health.mongo.enabled:false")
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(MongoReactiveHealthIndicator.class)
|
.run((context) -> assertThat(context).doesNotHaveBean(MongoReactiveHealthIndicator.class)
|
||||||
.doesNotHaveBean(MongoHealthIndicator.class));
|
.doesNotHaveBean("mongoHealthContributor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,16 +40,22 @@ class RedisReactiveHealthContributorAutoConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void runShouldCreateIndicator() {
|
void runShouldCreateIndicator() {
|
||||||
this.contextRunner.run(
|
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(RedisReactiveHealthIndicator.class)
|
||||||
(context) -> assertThat(context).hasSingleBean(RedisReactiveHealthContributorAutoConfiguration.class)
|
.hasBean("redisHealthContributor"));
|
||||||
.doesNotHaveBean(RedisHealthIndicator.class));
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
|
||||||
|
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisHealthContributorAutoConfiguration.class))
|
||||||
|
.run((context) -> assertThat(context).hasSingleBean(RedisReactiveHealthIndicator.class)
|
||||||
|
.hasBean("redisHealthContributor").doesNotHaveBean(RedisHealthIndicator.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void runWhenDisabledShouldNotCreateIndicator() {
|
void runWhenDisabledShouldNotCreateIndicator() {
|
||||||
this.contextRunner.withPropertyValues("management.health.redis.enabled:false")
|
this.contextRunner.withPropertyValues("management.health.redis.enabled:false")
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(RedisReactiveHealthIndicator.class)
|
.run((context) -> assertThat(context).doesNotHaveBean(RedisReactiveHealthIndicator.class)
|
||||||
.doesNotHaveBean(RedisHealthIndicator.class));
|
.doesNotHaveBean("redisHealthContributor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user