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:
parent
a664eadb9a
commit
d7652e8f14
|
|
@ -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> {
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue