Move Redis health and metrics auto-config into spring-boot-data-redis
This commit is contained in:
committed by
Phillip Webb
parent
3e72525828
commit
5d131754cc
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.data.redis.actuate.health.autoconfigure;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.HealthContributor;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.data.redis.actuate.health.RedisHealthIndicator;
|
||||
import org.springframework.boot.data.redis.autoconfigure.RedisAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for {@link RedisHealthIndicator}.
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
* @author Richard Santana
|
||||
* @author Stephane Nicoll
|
||||
* @author Mark Paluch
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@AutoConfiguration(after = { RedisAutoConfiguration.class, RedisReactiveHealthContributorAutoConfiguration.class })
|
||||
@ConditionalOnClass({ RedisConnectionFactory.class, HealthIndicator.class, ConditionalOnEnabledHealthIndicator.class })
|
||||
@ConditionalOnBean(RedisConnectionFactory.class)
|
||||
@ConditionalOnEnabledHealthIndicator("redis")
|
||||
public class RedisHealthContributorAutoConfiguration
|
||||
extends CompositeHealthContributorConfiguration<RedisHealthIndicator, RedisConnectionFactory> {
|
||||
|
||||
RedisHealthContributorAutoConfiguration() {
|
||||
super(RedisHealthIndicator::new);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "redisHealthIndicator", "redisHealthContributor" })
|
||||
public HealthContributor redisHealthContributor(ConfigurableListableBeanFactory beanFactory) {
|
||||
return createContributor(beanFactory, RedisConnectionFactory.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.data.redis.actuate.health.autoconfigure;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.ReactiveHealthContributor;
|
||||
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.data.redis.actuate.health.RedisReactiveHealthIndicator;
|
||||
import org.springframework.boot.data.redis.autoconfigure.RedisReactiveAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for
|
||||
* {@link RedisReactiveHealthIndicator}.
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
* @author Richard Santana
|
||||
* @author Stephane Nicoll
|
||||
* @author Mark Paluch
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@AutoConfiguration(after = RedisReactiveAutoConfiguration.class)
|
||||
@ConditionalOnClass({ ReactiveRedisConnectionFactory.class, Flux.class, ReactiveHealthIndicator.class,
|
||||
ConditionalOnEnabledHealthIndicator.class })
|
||||
@ConditionalOnBean(ReactiveRedisConnectionFactory.class)
|
||||
@ConditionalOnEnabledHealthIndicator("redis")
|
||||
public class RedisReactiveHealthContributorAutoConfiguration extends
|
||||
CompositeReactiveHealthContributorConfiguration<RedisReactiveHealthIndicator, ReactiveRedisConnectionFactory> {
|
||||
|
||||
RedisReactiveHealthContributorAutoConfiguration() {
|
||||
super(RedisReactiveHealthIndicator::new);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "redisHealthIndicator", "redisHealthContributor" })
|
||||
public ReactiveHealthContributor redisHealthContributor(ConfigurableListableBeanFactory beanFactory) {
|
||||
return createContributor(beanFactory, ReactiveRedisConnectionFactory.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for Redis health integration using Spring Data Redis.
|
||||
*/
|
||||
package org.springframework.boot.data.redis.actuate.health.autoconfigure;
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.data.redis.actuate.metrics.autoconfigure;
|
||||
|
||||
import io.lettuce.core.RedisClient;
|
||||
import io.lettuce.core.metrics.MicrometerCommandLatencyRecorder;
|
||||
import io.lettuce.core.metrics.MicrometerOptions;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.data.redis.autoconfigure.ClientResourcesBuilderCustomizer;
|
||||
import org.springframework.boot.data.redis.autoconfigure.RedisAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* Auto-configuration for Lettuce metrics.
|
||||
*
|
||||
* @author Antonin Arquey
|
||||
* @author Yanming Zhou
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@AutoConfiguration(before = RedisAutoConfiguration.class,
|
||||
afterName = "org.springframework.boot.metrics.autoconfigure.CompositeMeterRegistryAutoConfiguration")
|
||||
@ConditionalOnClass({ RedisClient.class, MicrometerCommandLatencyRecorder.class, MeterRegistry.class })
|
||||
@ConditionalOnBean(MeterRegistry.class)
|
||||
public class LettuceMetricsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
MicrometerOptions micrometerOptions() {
|
||||
return MicrometerOptions.create();
|
||||
}
|
||||
|
||||
@Bean
|
||||
ClientResourcesBuilderCustomizer lettuceMetrics(MeterRegistry meterRegistry, MicrometerOptions options) {
|
||||
return (client) -> client.commandLatencyRecorder(new MicrometerCommandLatencyRecorder(meterRegistry, options));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for Redis metrics.
|
||||
*/
|
||||
package org.springframework.boot.data.redis.actuate.metrics.autoconfigure;
|
||||
@@ -1,6 +1,12 @@
|
||||
{
|
||||
"groups": [],
|
||||
"properties": [
|
||||
{
|
||||
"name": "management.health.redis.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether to enable Redis health check.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "spring.data.redis.repositories.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
org.springframework.boot.data.redis.actuate.health.autoconfigure.RedisHealthContributorAutoConfiguration
|
||||
org.springframework.boot.data.redis.actuate.health.autoconfigure.RedisReactiveHealthContributorAutoConfiguration
|
||||
org.springframework.boot.data.redis.actuate.metrics.autoconfigure.LettuceMetricsAutoConfiguration
|
||||
org.springframework.boot.data.redis.autoconfigure.RedisAutoConfiguration
|
||||
org.springframework.boot.data.redis.autoconfigure.RedisReactiveAutoConfiguration
|
||||
org.springframework.boot.data.redis.autoconfigure.RedisRepositoriesAutoConfiguration
|
||||
|
||||
Reference in New Issue
Block a user