From deef167cb247795d13d1ec6ad59d61231272fa91 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Thu, 1 Nov 2018 01:35:13 -0700 Subject: [PATCH] Make hystrix command keys explicit --- .../storage/AccountsManager.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java b/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java index 3bc9a02cf..7ad78d95e 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java +++ b/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java @@ -20,7 +20,9 @@ package org.whispersystems.textsecuregcm.storage; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.netflix.hystrix.HystrixCommand; +import com.netflix.hystrix.HystrixCommand.Setter; import com.netflix.hystrix.HystrixCommandGroupKey; +import com.netflix.hystrix.HystrixCommandKey; import com.netflix.hystrix.exception.HystrixBadRequestException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +36,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Optional; +import java.util.Set; import redis.clients.jedis.Jedis; @@ -91,7 +94,9 @@ public class AccountsManager { } private void updateDirectory(Account account) { - new HystrixCommand(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DIRECTORY_SERVICE)) { + new HystrixCommand(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DIRECTORY_SERVICE)) + .andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".updateDirectory"))) + { @Override protected Void run() { if (account.isActive()) { @@ -112,7 +117,9 @@ public class AccountsManager { } private void redisSet(String number, Account account, boolean optional) { - new HystrixCommand(HystrixCommandGroupKey.Factory.asKey(GroupKeys.REDIS_CACHE)) { + new HystrixCommand(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.REDIS_CACHE)) + .andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".redisSet"))) + { @Override protected Boolean run() { try (Jedis jedis = cacheClient.getWriteResource()) { @@ -133,7 +140,9 @@ public class AccountsManager { } private Optional redisGet(String number) { - return new HystrixCommand>(HystrixCommandGroupKey.Factory.asKey(GroupKeys.REDIS_CACHE)) { + return new HystrixCommand>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.REDIS_CACHE)) + .andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".redisGet"))) + { @Override protected Optional run() { try (Jedis jedis = cacheClient.getReadResource()) { @@ -155,7 +164,9 @@ public class AccountsManager { } private Optional databaseGet(String number) { - return new HystrixCommand>(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS)) { + return new HystrixCommand>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS)) + .andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseGet"))) + { @Override protected Optional run() { return Optional.ofNullable(accounts.get(number)); @@ -164,7 +175,9 @@ public class AccountsManager { } private boolean databaseCreate(Account account) { - return new HystrixCommand(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS)) { + return new HystrixCommand(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS)) + .andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseCreate"))) + { @Override protected Boolean run() { return accounts.create(account); @@ -173,7 +186,9 @@ public class AccountsManager { } private void databaseUpdate(Account account) { - new HystrixCommand(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS)) { + new HystrixCommand(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(GroupKeys.DATABASE_ACCOUNTS)) + .andCommandKey(HystrixCommandKey.Factory.asKey(AccountsManager.class.getSimpleName() + ".databaseUpdate"))) + { @Override protected Void run() { accounts.update(account);