Record account deletion reasons.

This commit is contained in:
Jon Chambers
2020-10-16 15:04:55 -04:00
committed by Jon Chambers
parent d82b3dc429
commit 23ca011ac1
6 changed files with 30 additions and 12 deletions

View File

@@ -604,7 +604,7 @@ public class AccountController {
@DELETE
@Path("/me")
public void deleteAccount(@Auth Account account) {
accounts.delete(account);
accounts.delete(account, AccountsManager.DeletionReason.USER_REQUEST);
}
private boolean shouldAutoBlock(String requester) {

View File

@@ -68,7 +68,7 @@ public class AccountCleaner extends AccountDatabaseCrawlerListener {
expiredAccountsMeter.mark();
if (accountUpdateCount < MAX_ACCOUNT_UPDATES_PER_CHUNK) {
accountsManager.delete(account);
accountsManager.delete(account, AccountsManager.DeletionReason.EXPIRED);
accountUpdateCount++;
}
}

View File

@@ -56,8 +56,9 @@ public class AccountsManager {
private static final Timer redisUuidGetTimer = metricRegistry.timer(name(AccountsManager.class, "redisUuidGet" ));
private static final Timer redisDeleteTimer = metricRegistry.timer(name(AccountsManager.class, "redisDelete" ));
private static final String DELETE_COUNTER_NAME = name(AccountsManager.class, "deleteCounter");
private static final String COUNTRY_CODE_TAG_NAME = "country";
private static final String DELETE_COUNTER_NAME = name(AccountsManager.class, "deleteCounter");
private static final String COUNTRY_CODE_TAG_NAME = "country";
private static final String DELETION_REASON_TAG_NAME = "reason";
private final Logger logger = LoggerFactory.getLogger(AccountsManager.class);
@@ -72,6 +73,18 @@ public class AccountsManager {
private final ProfilesManager profilesManager;
private final ObjectMapper mapper;
public enum DeletionReason {
ADMIN_DELETED("admin"),
EXPIRED ("expired"),
USER_REQUEST ("userRequest");
private final String tagValue;
DeletionReason(final String tagValue) {
this.tagValue = tagValue;
}
}
public AccountsManager(Accounts accounts, DirectoryManager directory, FaultTolerantRedisCluster cacheCluster, final DirectoryQueue directoryQueue, final Keys keys, final MessagesManager messagesManager, final UsernamesManager usernamesManager, final ProfilesManager profilesManager) {
this.accounts = accounts;
this.directory = directory;
@@ -143,7 +156,7 @@ public class AccountsManager {
return accounts.getAllFrom(uuid, length);
}
public void delete(final Account account) {
public void delete(final Account account, final DeletionReason deletionReason) {
try (final Timer.Context ignored = deleteTimer.time()) {
usernamesManager.delete(account.getUuid());
directoryQueue.deleteAccount(account);
@@ -155,7 +168,10 @@ public class AccountsManager {
databaseDelete(account);
}
Metrics.counter(DELETE_COUNTER_NAME, COUNTRY_CODE_TAG_NAME, Util.getCountryCode(account.getNumber())).increment();
Metrics.counter(DELETE_COUNTER_NAME,
COUNTRY_CODE_TAG_NAME, Util.getCountryCode(account.getNumber()),
DELETION_REASON_TAG_NAME, deletionReason.tagValue)
.increment();
}
private void updateDirectory(Account account) {

View File

@@ -106,7 +106,7 @@ public class DeleteUserCommand extends EnvironmentCommand<WhisperServerConfigura
Optional<Account> account = accountsManager.get(user);
if (account.isPresent()) {
accountsManager.delete(account.get());
accountsManager.delete(account.get(), AccountsManager.DeletionReason.ADMIN_DELETED);
logger.warn("Removed " + account.get().getNumber());
} else {
logger.warn("Account not found");