|
|
|
@ -24,6 +24,7 @@ import reactor.core.scheduler.Schedulers;
|
|
|
|
|
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
|
|
|
|
|
import org.springframework.boot.actuate.health.Health;
|
|
|
|
|
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
|
|
|
|
import org.springframework.data.redis.connection.ReactiveRedisClusterConnection;
|
|
|
|
|
import org.springframework.data.redis.connection.ReactiveRedisConnection;
|
|
|
|
|
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
|
|
|
|
|
|
|
|
@ -33,6 +34,7 @@ import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
* @author Mark Paluch
|
|
|
|
|
* @author Artsiom Yudovin
|
|
|
|
|
* @author Scott Frederick
|
|
|
|
|
* @since 2.0.0
|
|
|
|
|
*/
|
|
|
|
|
public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
|
|
|
|
@ -50,7 +52,8 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Mono<Health> doHealthCheck(Health.Builder builder, ReactiveRedisConnection connection) {
|
|
|
|
|
return connection.serverCommands().info().map((info) -> up(builder, info))
|
|
|
|
|
return connection.serverCommands().info()
|
|
|
|
|
.map((info) -> up(builder, info, (connection instanceof ReactiveRedisClusterConnection)))
|
|
|
|
|
.onErrorResume((ex) -> Mono.just(down(builder, ex)))
|
|
|
|
|
.flatMap((health) -> connection.closeLater().thenReturn(health));
|
|
|
|
|
}
|
|
|
|
@ -60,9 +63,21 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
|
|
|
|
|
.subscribeOn(Schedulers.boundedElastic());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Health up(Health.Builder builder, Properties info) {
|
|
|
|
|
return builder.up()
|
|
|
|
|
.withDetail(RedisHealthIndicator.VERSION, info.getProperty(RedisHealthIndicator.REDIS_VERSION)).build();
|
|
|
|
|
private Health up(Health.Builder builder, Properties info, boolean isClusterConnection) {
|
|
|
|
|
if (isClusterConnection) {
|
|
|
|
|
return builder.up().withDetail(RedisHealthIndicator.VERSION, getClusterVersionProperty(info)).build();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return builder.up()
|
|
|
|
|
.withDetail(RedisHealthIndicator.VERSION, info.getProperty(RedisHealthIndicator.REDIS_VERSION))
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Object getClusterVersionProperty(Properties info) {
|
|
|
|
|
return info.keySet().stream().map(String.class::cast)
|
|
|
|
|
.filter((key) -> key.endsWith(RedisHealthIndicator.REDIS_VERSION)).findFirst().map(info::get)
|
|
|
|
|
.orElse("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Health down(Health.Builder builder, Throwable cause) {
|
|
|
|
|