Tag account-creation metrics with whether the number is fictitious

This commit is contained in:
Alan Liu authored and Chris Eager committed 2026-10-15 18:04:03 -04:00
1 parent 7238d00f4d
commit db6f370575
3 files changed
+26 -2

No files matched your search

@@ -98,6 +98,7 @@ public class RegistrationController {
private static final String COUNTRY_CODE_TAG_NAME = "countryCode";
private static final String REGION_CODE_TAG_NAME = "regionCode";
private static final String VERIFICATION_TYPE_TAG_NAME = "verification";
private static final String FICTITIOUS_NUMBER_TAG_NAME = "fictitiousNumber";
private final AccountsManager accounts;
private final PhoneVerificationTokenManager phoneVerificationTokenManager;
@@ -320,7 +321,8 @@ public class RegistrationController {
Metrics.counter(ACCOUNT_CREATED_COUNTER_NAME, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent),
Tag.of(COUNTRY_CODE_TAG_NAME, Util.getCountryCode(number)),
Tag.of(REGION_CODE_TAG_NAME, Util.getRegion(number)),
Tag.of(VERIFICATION_TYPE_TAG_NAME, verificationType.name())))
Tag.of(VERIFICATION_TYPE_TAG_NAME, verificationType.name()),
Tag.of(FICTITIOUS_NUMBER_TAG_NAME, String.valueOf(Util.isFictitiousNumber(number)))))
.increment();
final AccountIdentityResponse identityResponse = new AccountIdentityResponseBuilder(account)
@@ -740,7 +740,8 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
Tags tags = Tags.of(UserAgentTagUtil.getPlatformTag(userAgent),
Tag.of("type", accountCreationType.getTagValue()),
Tag.of("pushTokenType", pushTokenType.getTagValue()),
Tag.of("hasRecoveryPassword", String.valueOf(hasRecoveryPassword)));
Tag.of("hasRecoveryPassword", String.valueOf(hasRecoveryPassword)),
Tag.of("fictitiousNumber", String.valueOf(account.getNumber().map(Util::isFictitiousNumber).orElse(false))));
if (previousPushTokenType != null) {
tags = tags.and(Tag.of("previousPushTokenType", previousPushTokenType.getTagValue()));
@@ -24,6 +24,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.whispersystems.textsecuregcm.storage.Account;
@@ -37,6 +38,19 @@ public class Util {
public static final String COUNTRY_CODE_NOT_APPLICABLE = "n/a";
public static final String REGION_NOT_APPLICABLE = "n/a";
// Keep in sync with registration-service's FictitiousNumberVerificationCodeSender, which sends verification codes
// for these numbers to a datastore instead of an SMS/voice provider
private static final List<Pattern> FICTITIOUS_NUMBER_PATTERNS = List.of(
// NANPA fictitious numbers
Pattern.compile("\\+1[0-9]{3}55501[0-9]{2}"),
// UK "numbers for drama"
Pattern.compile("\\+447700900[0-9]{3}"),
// French numbers "for use in audiovisual productions"
Pattern.compile("\\+3363998[0-9]{4}")
);
// We use a `HashMap` because `HashMap` allows for null keys at query time, and `PhoneNumberUtil` may return a null
// region code for some phone numbers
private static final Map<String, AlternatePhoneNumberFormGenerator> ALTERNATE_FORM_GENERATORS_BY_REGION =
@@ -226,6 +240,13 @@ public class Util {
PHONE_NUMBER_UTIL.getNationalSignificantNumber(phoneNumber).length() == 8;
}
/**
* @return whether the E164-formatted {@code number} is in a range that registration-service treats as fictitious
*/
public static boolean isFictitiousNumber(final String number) {
return FICTITIOUS_NUMBER_PATTERNS.stream().anyMatch(pattern -> pattern.matcher(number).matches());
}
/**
* If applicable, return the canonical form of the provided phone number.
* This is relevant in cases where a numbering authority has changed the numbering format for a region.