Added a Redis cluster health check.

This commit is contained in:
Jon Chambers 2020-06-07 16:14:57 -04:00 committed by Jon Chambers
parent 52310b5dd9
commit 47ece983d2
2 changed files with 25 additions and 0 deletions

View File

@ -91,6 +91,7 @@ import org.whispersystems.textsecuregcm.metrics.NetworkReceivedGauge;
import org.whispersystems.textsecuregcm.metrics.NetworkSentGauge;
import org.whispersystems.textsecuregcm.metrics.TrafficSource;
import org.whispersystems.textsecuregcm.providers.RedisClientFactory;
import org.whispersystems.textsecuregcm.providers.RedisClusterHealthCheck;
import org.whispersystems.textsecuregcm.providers.RedisHealthCheck;
import org.whispersystems.textsecuregcm.push.APNSender;
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
@ -391,6 +392,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
environment.healthChecks().register("directory", new RedisHealthCheck(directoryClient));
environment.healthChecks().register("cache", new RedisHealthCheck(cacheClient));
environment.healthChecks().register("cacheCluster", new RedisClusterHealthCheck(cacheCluster));
environment.metrics().register(name(CpuUsageGauge.class, "cpu"), new CpuUsageGauge());
environment.metrics().register(name(FreeMemoryGauge.class, "free_memory"), new FreeMemoryGauge());

View File

@ -0,0 +1,23 @@
package org.whispersystems.textsecuregcm.providers;
import com.codahale.metrics.health.HealthCheck;
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster;
import java.util.concurrent.CompletableFuture;
public class RedisClusterHealthCheck extends HealthCheck {
private final FaultTolerantRedisCluster redisCluster;
public RedisClusterHealthCheck(final FaultTolerantRedisCluster redisCluster) {
this.redisCluster = redisCluster;
}
@Override
protected Result check() throws Exception {
return CompletableFuture.allOf(redisCluster.withReadCluster(connection -> connection.async().masters().commands().ping()).futures())
.thenApply(v -> Result.healthy())
.exceptionally(Result::unhealthy)
.get();
}
}