Polish "Mark Redis as down when cluster_state is fail"

See gh-27300
This commit is contained in:
Andy Wilkinson
2021-07-13 14:36:39 +01:00
parent f31141de09
commit 49baacbc1c
5 changed files with 93 additions and 94 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -38,14 +38,15 @@ final class RedisHealth {
return builder.up();
}
static Builder info(Health.Builder builder, ClusterInfo clusterInfo) {
static Builder fromClusterInfo(Health.Builder builder, ClusterInfo clusterInfo) {
builder.withDetail("cluster_size", clusterInfo.getClusterSize());
builder.withDetail("slots_up", clusterInfo.getSlotsOk());
builder.withDetail("slots_fail", clusterInfo.getSlotsFail());
if ("fail".equalsIgnoreCase(clusterInfo.getState())) {
return builder.down();
} else {
}
else {
return builder.up();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -57,7 +57,7 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
private void doHealthCheck(Health.Builder builder, RedisConnection connection) {
if (connection instanceof RedisClusterConnection) {
RedisHealth.info(builder, ((RedisClusterConnection) connection).clusterGetClusterInfo());
RedisHealth.fromClusterInfo(builder, ((RedisClusterConnection) connection).clusterGetClusterInfo());
}
else {
RedisHealth.up(builder, connection.info("server"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -65,7 +65,7 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
private Mono<Health> getHealth(Health.Builder builder, ReactiveRedisConnection connection) {
if (connection instanceof ReactiveRedisClusterConnection) {
return ((ReactiveRedisClusterConnection) connection).clusterGetClusterInfo()
.map(info -> info(builder, info));
.map((info) -> fromClusterInfo(builder, info));
}
return connection.serverCommands().info("server").map((info) -> up(builder, info));
}
@@ -74,8 +74,8 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
return RedisHealth.up(builder, info).build();
}
private Health info(Health.Builder builder, ClusterInfo clusterInfo) {
return RedisHealth.info(builder, clusterInfo).build();
private Health fromClusterInfo(Health.Builder builder, ClusterInfo clusterInfo) {
return RedisHealth.fromClusterInfo(builder, clusterInfo).build();
}
}