|
24 | 24 | import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
|
25 | 25 | import org.springframework.boot.actuate.health.Health;
|
26 | 26 | import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
| 27 | +import org.springframework.data.redis.connection.ClusterInfo; |
27 | 28 | import org.springframework.data.redis.connection.ReactiveRedisClusterConnection;
|
28 | 29 | import org.springframework.data.redis.connection.ReactiveRedisConnection;
|
29 | 30 | import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
@@ -52,32 +53,33 @@ protected Mono<Health> doHealthCheck(Health.Builder builder) {
|
52 | 53 | }
|
53 | 54 |
|
54 | 55 | private Mono<Health> doHealthCheck(Health.Builder builder, ReactiveRedisConnection connection) {
|
55 |
| - return connection.serverCommands().info() |
56 |
| - .map((info) -> up(builder, info, (connection instanceof ReactiveRedisClusterConnection))) |
57 |
| - .onErrorResume((ex) -> Mono.just(down(builder, ex))) |
58 |
| - .flatMap((health) -> connection.closeLater().thenReturn(health)); |
| 56 | + if (connection instanceof ReactiveRedisClusterConnection) { |
| 57 | + ReactiveRedisClusterConnection clusterConnection = (ReactiveRedisClusterConnection) connection; |
| 58 | + return clusterConnection.clusterGetClusterInfo().map((info) -> up(builder, info)) |
| 59 | + .onErrorResume((ex) -> Mono.just(down(builder, ex))) |
| 60 | + .flatMap((health) -> clusterConnection.closeLater().thenReturn(health)); |
| 61 | + } |
| 62 | + else { |
| 63 | + return connection.serverCommands().info().map((info) -> up(builder, info)) |
| 64 | + .onErrorResume((ex) -> Mono.just(down(builder, ex))) |
| 65 | + .flatMap((health) -> connection.closeLater().thenReturn(health)); |
| 66 | + } |
59 | 67 | }
|
60 | 68 |
|
61 | 69 | private Mono<ReactiveRedisConnection> getConnection() {
|
62 | 70 | return Mono.fromSupplier(this.connectionFactory::getReactiveConnection)
|
63 | 71 | .subscribeOn(Schedulers.boundedElastic());
|
64 | 72 | }
|
65 | 73 |
|
66 |
| - private Health up(Health.Builder builder, Properties info, boolean isClusterConnection) { |
67 |
| - if (isClusterConnection) { |
68 |
| - return builder.up().withDetail(RedisHealthIndicator.VERSION, getClusterVersionProperty(info)).build(); |
69 |
| - } |
70 |
| - else { |
71 |
| - return builder.up() |
72 |
| - .withDetail(RedisHealthIndicator.VERSION, info.getProperty(RedisHealthIndicator.REDIS_VERSION)) |
73 |
| - .build(); |
74 |
| - } |
| 74 | + private Health up(Health.Builder builder, Properties info) { |
| 75 | + return builder.up() |
| 76 | + .withDetail(RedisHealthIndicator.VERSION, info.getProperty(RedisHealthIndicator.REDIS_VERSION)).build(); |
75 | 77 | }
|
76 | 78 |
|
77 |
| - private Object getClusterVersionProperty(Properties info) { |
78 |
| - return info.keySet().stream().map(String.class::cast) |
79 |
| - .filter((key) -> key.endsWith(RedisHealthIndicator.REDIS_VERSION)).findFirst().map(info::get) |
80 |
| - .orElse(""); |
| 79 | + private Health up(Health.Builder builder, ClusterInfo clusterInfo) { |
| 80 | + return builder.up().withDetail(RedisHealthIndicator.CLUSTER_SIZE, clusterInfo.getClusterSize()) |
| 81 | + .withDetail(RedisHealthIndicator.SLOTS_UP, clusterInfo.getSlotsOk()) |
| 82 | + .withDetail(RedisHealthIndicator.SLOTS_FAIL, clusterInfo.getSlotsFail()).build(); |
81 | 83 | }
|
82 | 84 |
|
83 | 85 | private Health down(Health.Builder builder, Throwable cause) {
|
|
0 commit comments