Adjust metrics in RemoveExpiredUsernameHoldsCommand
This commit is contained in:
parent
85b15fa63b
commit
f9533e016f
|
@ -22,6 +22,7 @@ import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||||
|
|
||||||
|
@ -39,8 +40,8 @@ public class RemoveExpiredUsernameHoldsCommand extends AbstractSinglePassCrawlAc
|
||||||
private static final String DELETED_HOLDS_COUNTER_NAME =
|
private static final String DELETED_HOLDS_COUNTER_NAME =
|
||||||
name(RemoveExpiredUsernameHoldsCommand.class, "expiredHolds");
|
name(RemoveExpiredUsernameHoldsCommand.class, "expiredHolds");
|
||||||
|
|
||||||
private static final String UPDATED_ACCOUNTS_COUNTER_NAME =
|
private static final String INSPECTED_ACCOUNTS_COUNTER_NAME =
|
||||||
name(RemoveExpiredUsernameHoldsCommand.class, "accountsWithExpiredHolds");
|
name(RemoveExpiredUsernameHoldsCommand.class, "inspectedAccounts");
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(RemoveExpiredUsernameHoldsCommand.class);
|
private static final Logger log = LoggerFactory.getLogger(RemoveExpiredUsernameHoldsCommand.class);
|
||||||
|
|
||||||
|
@ -74,28 +75,30 @@ public class RemoveExpiredUsernameHoldsCommand extends AbstractSinglePassCrawlAc
|
||||||
|
|
||||||
final Counter deletedHoldsCounter =
|
final Counter deletedHoldsCounter =
|
||||||
Metrics.counter(DELETED_HOLDS_COUNTER_NAME, "dryRun", String.valueOf(isDryRun));
|
Metrics.counter(DELETED_HOLDS_COUNTER_NAME, "dryRun", String.valueOf(isDryRun));
|
||||||
final Counter updatedAccountsCounter =
|
|
||||||
Metrics.counter(UPDATED_ACCOUNTS_COUNTER_NAME, "dryRun", String.valueOf(isDryRun));
|
|
||||||
|
|
||||||
final AccountsManager accountManager = getCommandDependencies().accountsManager();
|
final AccountsManager accountManager = getCommandDependencies().accountsManager();
|
||||||
|
final AtomicLong accountsInspected = new AtomicLong();
|
||||||
accounts.flatMap(account -> {
|
accounts.flatMap(account -> {
|
||||||
|
accountsInspected.incrementAndGet();
|
||||||
final List<Account.UsernameHold> holds = new ArrayList<>(account.getUsernameHolds());
|
final List<Account.UsernameHold> holds = new ArrayList<>(account.getUsernameHolds());
|
||||||
int holdsToRemove = removeExpired(holds);
|
final int holdsToRemove = removeExpired(holds);
|
||||||
final Mono<Void> purgeMono = isDryRun || holdsToRemove == 0
|
final Mono<Void> purgeMono = isDryRun || holdsToRemove == 0
|
||||||
? Mono.empty()
|
? Mono.empty()
|
||||||
: Mono.fromFuture(() ->
|
: Mono.fromFuture(() ->
|
||||||
accountManager.updateAsync(account, a -> a.setUsernameHolds(holds)).thenRun(Util.NOOP));
|
accountManager.updateAsync(account, a -> a.setUsernameHolds(holds)).thenRun(Util.NOOP));
|
||||||
|
Metrics.counter(INSPECTED_ACCOUNTS_COUNTER_NAME,
|
||||||
|
"dryRun", String.valueOf(isDryRun),
|
||||||
|
"expiredHolds", String.valueOf(holdsToRemove > 0))
|
||||||
|
.increment();
|
||||||
return purgeMono
|
return purgeMono
|
||||||
.doOnSuccess(ignored -> {
|
.doOnSuccess(ignored -> deletedHoldsCounter.increment(holdsToRemove))
|
||||||
deletedHoldsCounter.increment(holdsToRemove);
|
|
||||||
updatedAccountsCounter.increment();
|
|
||||||
})
|
|
||||||
.onErrorResume(throwable -> {
|
.onErrorResume(throwable -> {
|
||||||
log.warn("Failed to purge {} expired holds on account {}", holdsToRemove, account.getUuid());
|
log.warn("Failed to purge {} expired holds on account {}", holdsToRemove, account.getUuid());
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
});
|
});
|
||||||
}, maxConcurrency)
|
}, maxConcurrency)
|
||||||
.then().block();
|
.then().block();
|
||||||
|
log.info("Finished crawl of {} accounts", accountsInspected.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|
Loading…
Reference in New Issue