From 66783c9381189e3742ecedd3b38b1233f0facc73 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Fri, 15 Nov 2024 15:14:09 -0500 Subject: [PATCH] Include new/previous push token types as dimensions on "account created" counter --- .../storage/AccountsManager.java | 36 ++++++++++++++++--- .../storage/AccountsManagerTest.java | 1 + 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java index b803e6e2f..5c46b4934 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java @@ -292,6 +292,18 @@ public class AccountsManager extends RedisPubSubAdapter implemen String accountCreationType = maybeRecentlyDeletedAccountIdentifier.isPresent() ? "recently-deleted" : "new"; + final String pushTokenType; + + if (primaryDeviceSpec.apnRegistrationId().isPresent()) { + pushTokenType = "apns"; + } else if (primaryDeviceSpec.gcmRegistrationId().isPresent()) { + pushTokenType = "fcm"; + } else { + pushTokenType = "none"; + } + + String previousPushTokenType = null; + try { accounts.create(account, keysManager.buildWriteItemsForNewDevice(account.getIdentifier(IdentityType.ACI), account.getIdentifier(IdentityType.PNI), @@ -303,6 +315,14 @@ public class AccountsManager extends RedisPubSubAdapter implemen } catch (final AccountAlreadyExistsException e) { accountCreationType = "re-registration"; + if (StringUtils.isNotBlank(e.getExistingAccount().getPrimaryDevice().getApnId())) { + previousPushTokenType = "apns"; + } else if (StringUtils.isNotBlank(e.getExistingAccount().getPrimaryDevice().getGcmId())) { + previousPushTokenType = "fcm"; + } else { + previousPushTokenType = "none"; + } + final UUID aci = e.getExistingAccount().getIdentifier(IdentityType.ACI); final UUID pni = e.getExistingAccount().getIdentifier(IdentityType.PNI); @@ -352,11 +372,17 @@ public class AccountsManager extends RedisPubSubAdapter implemen redisSet(account); - Metrics.counter(CREATE_COUNTER_NAME, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent), - Tag.of("type", accountCreationType), - Tag.of("hasPushToken", String.valueOf( - primaryDeviceSpec.apnRegistrationId().isPresent() || primaryDeviceSpec.gcmRegistrationId().isPresent())))) - .increment(); + Tags tags = Tags.of(UserAgentTagUtil.getPlatformTag(userAgent), + Tag.of("type", accountCreationType), + Tag.of("hasPushToken", String.valueOf( + primaryDeviceSpec.apnRegistrationId().isPresent() || primaryDeviceSpec.gcmRegistrationId().isPresent())), + Tag.of("pushTokenType", pushTokenType)); + + if (StringUtils.isNotBlank(previousPushTokenType)) { + tags = tags.and(Tag.of("previousPushTokenType", previousPushTokenType)); + } + + Metrics.counter(CREATE_COUNTER_NAME, tags).increment(); accountAttributes.recoveryPassword().ifPresent(registrationRecoveryPassword -> registrationRecoveryPasswordsManager.storeForCurrentNumber(account.getNumber(), registrationRecoveryPassword)); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java index 7e72d8b94..51181d2ba 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java @@ -853,6 +853,7 @@ class AccountsManagerTest { when(existingAccount.getNumber()).thenReturn(e164); when(existingAccount.getPhoneNumberIdentifier()).thenReturn(requestedAccount.getIdentifier(IdentityType.PNI)); when(existingAccount.getIdentifier(IdentityType.PNI)).thenReturn(requestedAccount.getIdentifier(IdentityType.PNI)); + when(existingAccount.getPrimaryDevice()).thenReturn(mock(Device.class)); throw new AccountAlreadyExistsException(existingAccount); });