From 99cc3f4bfc30019108090e0775ac62fe11f0af35 Mon Sep 17 00:00:00 2001 From: xJoeWoo Date: Thu, 19 Nov 2020 13:57:40 +0800 Subject: [PATCH] Reduce redis health indicator info command result size See gh-24208 --- .../boot/actuate/redis/RedisHealthIndicator.java | 2 +- .../boot/actuate/redis/RedisReactiveHealthIndicator.java | 2 +- .../boot/actuate/redis/RedisHealthIndicatorTests.java | 5 +++-- .../actuate/redis/RedisReactiveHealthIndicatorTests.java | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java index 45eaff9619..a0a8aea7c4 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisHealthIndicator.java @@ -65,7 +65,7 @@ public class RedisHealthIndicator extends AbstractHealthIndicator { .withDetail("slots_fail", clusterInfo.getSlotsFail()); } else { - String version = connection.info().getProperty(REDIS_VERSION_PROPERTY); + String version = connection.info("server").getProperty(REDIS_VERSION_PROPERTY); builder.up().withDetail("version", version); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java index 386700d568..4bbdb3b3be 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicator.java @@ -55,7 +55,7 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato private Mono doHealthCheck(Health.Builder builder, ReactiveRedisConnection connection) { boolean isClusterConnection = connection instanceof ReactiveRedisClusterConnection; - return connection.serverCommands().info().map((info) -> up(builder, info, isClusterConnection)) + return connection.serverCommands().info("server").map((info) -> up(builder, info, isClusterConnection)) .onErrorResume((ex) -> Mono.just(down(builder, ex))) .flatMap((health) -> connection.closeLater().thenReturn(health)); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java index 78c47a063a..0a90724f5a 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java @@ -32,6 +32,7 @@ import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; @@ -51,7 +52,7 @@ class RedisHealthIndicatorTests { Properties info = new Properties(); info.put("redis_version", "2.8.9"); RedisConnection redisConnection = mock(RedisConnection.class); - given(redisConnection.info()).willReturn(info); + given(redisConnection.info("server")).willReturn(info); RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection); Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); @@ -61,7 +62,7 @@ class RedisHealthIndicatorTests { @Test void redisIsDown() { RedisConnection redisConnection = mock(RedisConnection.class); - given(redisConnection.info()).willThrow(new RedisConnectionFailureException("Connection failed")); + given(redisConnection.info(anyString())).willThrow(new RedisConnectionFailureException("Connection failed")); RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection); Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java index 1717c2e60e..0bedc8cadb 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java @@ -33,6 +33,7 @@ import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory; import org.springframework.data.redis.connection.ReactiveServerCommands; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -55,7 +56,7 @@ class RedisReactiveHealthIndicatorTests { ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class); given(redisConnection.closeLater()).willReturn(Mono.empty()); ReactiveServerCommands commands = mock(ReactiveServerCommands.class); - given(commands.info()).willReturn(Mono.just(info)); + given(commands.info("server")).willReturn(Mono.just(info)); RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands); Mono health = healthIndicator.health(); StepVerifier.create(health).consumeNextWith((h) -> { @@ -87,7 +88,7 @@ class RedisReactiveHealthIndicatorTests { @Test void redisCommandIsDown() { ReactiveServerCommands commands = mock(ReactiveServerCommands.class); - given(commands.info()).willReturn(Mono.error(new RedisConnectionFailureException("Connection failed"))); + given(commands.info(anyString())).willReturn(Mono.error(new RedisConnectionFailureException("Connection failed"))); ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class); given(redisConnection.closeLater()).willReturn(Mono.empty()); RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);