From 9339823e84a796a4f39cc03788aa3b2b6a1828d0 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Fri, 25 Sep 2020 11:33:40 -0400 Subject: [PATCH] Add temporary metrics to monitor the ratio of enabled/disabled accounts. --- .../textsecuregcm/storage/Account.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java index eb89b4d69..c649ec47f 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java @@ -20,6 +20,8 @@ package org.whispersystems.textsecuregcm.storage; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.annotations.VisibleForTesting; +import io.micrometer.core.instrument.Counter; +import io.micrometer.core.instrument.Metrics; import org.whispersystems.textsecuregcm.auth.AmbiguousIdentifier; import org.whispersystems.textsecuregcm.auth.StoredRegistrationLock; @@ -32,8 +34,14 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; +import static com.codahale.metrics.MetricRegistry.name; + public class Account implements Principal { + // TODO Remove these temporary metrics + private static final Counter ENABLED_ACCOUNT_COUNTER = Metrics.counter(name(Account.class, "isEnabled"), "enabled", "true"); + private static final Counter DISABLED_ACCOUNT_COUNTER = Metrics.counter(name(Account.class, "isEnabled"), "enabled", "false"); + @JsonIgnore private UUID uuid; @@ -152,10 +160,18 @@ public class Account implements Principal { } public boolean isEnabled() { - return + final boolean enabled = getMasterDevice().isPresent() && getMasterDevice().get().isEnabled() && getLastSeen() > (System.currentTimeMillis() - TimeUnit.DAYS.toMillis(365)); + + if (enabled) { + ENABLED_ACCOUNT_COUNTER.increment(); + } else { + DISABLED_ACCOUNT_COUNTER.increment(); + } + + return enabled; } public long getNextDeviceId() {