Skip to content

Commit

Permalink
Add platform and push token presence dimensions to account creation m…
Browse files Browse the repository at this point in the history
…etrics
  • Loading branch information
jon-signal authored and eager-signal committed Sep 6, 2024
1 parent e160025 commit 556eec6
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public AccountIdentityResponse register(
registrationRequest.deviceActivationRequest().aciSignedPreKey(),
registrationRequest.deviceActivationRequest().pniSignedPreKey(),
registrationRequest.deviceActivationRequest().aciPqLastResortPreKey(),
registrationRequest.deviceActivationRequest().pniPqLastResortPreKey()));
registrationRequest.deviceActivationRequest().pniPqLastResortPreKey()),
userAgent);

Metrics.counter(ACCOUNT_CREATED_COUNTER_NAME, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent),
Tag.of(COUNTRY_CODE_TAG_NAME, Util.getCountryCode(number)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import io.lettuce.core.RedisException;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.Timer;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -52,6 +54,7 @@
import org.whispersystems.textsecuregcm.entities.KEMSignedPreKey;
import org.whispersystems.textsecuregcm.identity.IdentityType;
import org.whispersystems.textsecuregcm.identity.ServiceIdentifier;
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
import org.whispersystems.textsecuregcm.push.ClientPresenceManager;
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster;
import org.whispersystems.textsecuregcm.redis.RedisOperation;
Expand Down Expand Up @@ -167,7 +170,8 @@ public Account create(final String number,
final List<AccountBadge> accountBadges,
final IdentityKey aciIdentityKey,
final IdentityKey pniIdentityKey,
final DeviceSpec primaryDeviceSpec) throws InterruptedException {
final DeviceSpec primaryDeviceSpec,
@Nullable final String userAgent) throws InterruptedException {

final Account account = new Account();

Expand Down Expand Up @@ -251,7 +255,11 @@ public Account create(final String number,

redisSet(account);

Metrics.counter(CREATE_COUNTER_NAME, "type", accountCreationType).increment();
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();

accountAttributes.recoveryPassword().ifPresent(registrationRecoveryPassword ->
registrationRecoveryPasswordsManager.storeForCurrentNumber(account.getNumber(), registrationRecoveryPassword));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void invalidRegistrationId(Optional<Integer> registrationId, Optional<Integer> p
final Account account = mock(Account.class);
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));

when(accountsManager.create(any(), any(), any(), any(), any(), any()))
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(account);

final String json = requestJson("sessionId", new byte[0], true, registrationId.orElse(0), pniRegistrationId.orElse(0));
Expand Down Expand Up @@ -295,7 +295,7 @@ void recoveryPasswordManagerVerificationTrue() throws InterruptedException {
final Account account = mock(Account.class);
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));

when(accountsManager.create(any(), any(), any(), any(), any(), any()))
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(account);

final Invocation.Builder request = resources.getJerseyTest()
Expand Down Expand Up @@ -331,7 +331,7 @@ void registrationRecoveryCheckerAllowsAttempt() throws InterruptedException {
final Account account = mock(Account.class);
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));

when(accountsManager.create(any(), any(), any(), any(), any(), any()))
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(account);

final Invocation.Builder request = resources.getJerseyTest()
Expand All @@ -353,7 +353,7 @@ void registrationRecoveryCheckerDisallowsAttempt() throws InterruptedException {
final Account account = mock(Account.class);
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));

when(accountsManager.create(any(), any(), any(), any(), any(), any()))
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(account);

final Invocation.Builder request = resources.getJerseyTest()
Expand Down Expand Up @@ -397,7 +397,7 @@ void registrationLockAndDeviceTransfer(
final Account createdAccount = mock(Account.class);
when(createdAccount.getPrimaryDevice()).thenReturn(mock(Device.class));

when(accountsManager.create(any(), any(), any(), any(), any(), any()))
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(createdAccount);

expectedStatus = 200;
Expand Down Expand Up @@ -451,7 +451,7 @@ void deviceTransferAvailable(final boolean existingAccount, final boolean transf
final Account account = mock(Account.class);
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));

when(accountsManager.create(any(), any(), any(), any(), any(), any()))
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(account);

final Invocation.Builder request = resources.getJerseyTest()
Expand All @@ -475,7 +475,7 @@ void registrationSuccess() throws Exception {
final Account account = mock(Account.class);
when(account.getPrimaryDevice()).thenReturn(mock(Device.class));

when(accountsManager.create(any(), any(), any(), any(), any(), any()))
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(account);

final Invocation.Builder request = resources.getJerseyTest()
Expand Down Expand Up @@ -728,7 +728,7 @@ void atomicAccountCreationSuccess(final RegistrationRequest registrationRequest,
when(a.getPrimaryDevice()).thenReturn(device);
});

when(accountsManager.create(any(), any(), any(), any(), any(), any()))
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(account);

final Invocation.Builder request = resources.getJerseyTest()
Expand All @@ -746,7 +746,8 @@ void atomicAccountCreationSuccess(final RegistrationRequest registrationRequest,
eq(Collections.emptyList()),
eq(expectedAciIdentityKey),
eq(expectedPniIdentityKey),
eq(expectedDeviceSpec));
eq(expectedDeviceSpec),
any());
}

private static boolean accountAttributesEqual(final AccountAttributes a, final AccountAttributes b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ void createAccount(final DeliveryChannels deliveryChannels,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey));
pniPqLastResortPreKey),
null);

assertExpectedStoredAccount(account,
number,
Expand Down Expand Up @@ -315,7 +316,8 @@ void reregisterAccount(final DeliveryChannels deliveryChannels,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey));
pniPqLastResortPreKey),
null);

existingAccountUuid = originalAccount.getUuid();
}
Expand Down Expand Up @@ -381,7 +383,8 @@ void reregisterAccount(final DeliveryChannels deliveryChannels,
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey));
pniPqLastResortPreKey),
null);

assertExpectedStoredAccount(reregisteredAccount,
number,
Expand Down Expand Up @@ -464,7 +467,8 @@ void deleteAccount() throws InterruptedException {
aciSignedPreKey,
pniSignedPreKey,
aciPqLastResortPreKey,
pniPqLastResortPreKey));
pniPqLastResortPreKey),
null);

clientPublicKeysManager.setPublicKey(account, Device.PRIMARY_ID, Curve.generateKeyPair().getPublicKey()).join();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ void testConcurrentUpdate() throws IOException, InterruptedException {
KeysHelper.signedECPreKey(1, aciKeyPair),
KeysHelper.signedECPreKey(2, pniKeyPair),
KeysHelper.signedKEMPreKey(3, aciKeyPair),
KeysHelper.signedKEMPreKey(4, pniKeyPair))),
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
null),
a -> {
a.setUnidentifiedAccessKey(new byte[UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH]);
a.removeDevice(Device.PRIMARY_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ private Account createAccount(final String e164, final AccountAttributes account
KeysHelper.signedECPreKey(1, aciKeyPair),
KeysHelper.signedECPreKey(2, pniKeyPair),
KeysHelper.signedKEMPreKey(3, aciKeyPair),
KeysHelper.signedKEMPreKey(4, pniKeyPair)));
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public static Account createAccount(final AccountsManager accountsManager,
KeysHelper.signedECPreKey(1, aciKeyPair),
KeysHelper.signedECPreKey(2, pniKeyPair),
KeysHelper.signedKEMPreKey(3, aciKeyPair),
KeysHelper.signedKEMPreKey(4, pniKeyPair)));
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
null);
}
}

0 comments on commit 556eec6

Please sign in to comment.