From df9dc82de5129901b3c33e89121990b355ec7bbb Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Fri, 26 Feb 2021 16:59:12 -0500 Subject: [PATCH] Record days since last seen when somebody's "last seen" date changes. --- .../auth/BaseAccountAuthenticator.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java index 06f1b227a..c0359f44e 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java @@ -5,11 +5,14 @@ package org.whispersystems.textsecuregcm.auth; +import com.codahale.metrics.Histogram; import com.codahale.metrics.Meter; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.SharedMetricRegistries; import com.google.common.annotations.VisibleForTesting; import io.dropwizard.auth.basic.BasicCredentials; +import io.micrometer.core.instrument.DistributionSummary; +import io.micrometer.core.instrument.Metrics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.whispersystems.textsecuregcm.storage.Account; @@ -36,6 +39,10 @@ public class BaseAccountAuthenticator { private final Meter deviceDisabledMeter = metricRegistry.meter(name(getClass(), "authentication", "deviceDisabled" )); private final Meter invalidAuthHeaderMeter = metricRegistry.meter(name(getClass(), "authentication", "invalidHeader" )); + private final String daysSinceLastSeenDistributionName = name(getClass(), "authentication", "daysSinceLastSeen"); + + private static final String IS_PRIMARY_DEVICE_TAG = "isPrimary"; + private final Logger logger = LoggerFactory.getLogger(AccountAuthenticator.class); private final AccountsManager accountsManager; @@ -101,6 +108,12 @@ public class BaseAccountAuthenticator { final long todayInMillisWithOffset = Util.todayInMillisGivenOffsetFromNow(clock, Duration.ofSeconds(lastSeenOffsetSeconds).negated()); if (device.getLastSeen() < todayInMillisWithOffset) { + DistributionSummary.builder(daysSinceLastSeenDistributionName) + .tags(IS_PRIMARY_DEVICE_TAG, String.valueOf(device.isMaster())) + .publishPercentileHistogram() + .register(Metrics.globalRegistry) + .record(Duration.ofMillis(todayInMillisWithOffset - device.getLastSeen()).toDays()); + device.setLastSeen(Util.todayInMillis(clock)); accountsManager.update(account); }