Count how many iOS users set the old GV2 capability flag.
This commit is contained in:
		
							parent
							
								
									5986145282
								
							
						
					
					
						commit
						1eacee85ae
					
				| 
						 | 
					@ -17,10 +17,12 @@
 | 
				
			||||||
package org.whispersystems.textsecuregcm.auth;
 | 
					package org.whispersystems.textsecuregcm.auth;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import io.micrometer.core.instrument.Metrics;
 | 
					import io.micrometer.core.instrument.Metrics;
 | 
				
			||||||
 | 
					import io.micrometer.core.instrument.Tag;
 | 
				
			||||||
import org.apache.http.auth.AUTH;
 | 
					import org.apache.http.auth.AUTH;
 | 
				
			||||||
import org.whispersystems.textsecuregcm.storage.Account;
 | 
					import org.whispersystems.textsecuregcm.storage.Account;
 | 
				
			||||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
 | 
					import org.whispersystems.textsecuregcm.storage.AccountsManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Optional;
 | 
					import java.util.Optional;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import io.dropwizard.auth.Authenticator;
 | 
					import io.dropwizard.auth.Authenticator;
 | 
				
			||||||
| 
						 | 
					@ -30,8 +32,9 @@ import static com.codahale.metrics.MetricRegistry.name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AccountAuthenticator extends BaseAccountAuthenticator implements Authenticator<BasicCredentials, Account> {
 | 
					public class AccountAuthenticator extends BaseAccountAuthenticator implements Authenticator<BasicCredentials, Account> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private static final String AUTHENTICATION_COUNTER_NAME = name(AccountAuthenticator.class, "authenticate");
 | 
					  private static final String AUTHENTICATION_COUNTER_NAME     = name(AccountAuthenticator.class, "authenticate");
 | 
				
			||||||
  private static final String GV2_CAPABLE_TAG_NAME        = "gv2";
 | 
					  private static final String GV2_CAPABLE_TAG_NAME            = "gv2";
 | 
				
			||||||
 | 
					  private static final String IOS_OLD_GV2_CAPABILITY_TAG_NAME = "ios_old_gv2";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public AccountAuthenticator(AccountsManager accountsManager) {
 | 
					  public AccountAuthenticator(AccountsManager accountsManager) {
 | 
				
			||||||
    super(accountsManager);
 | 
					    super(accountsManager);
 | 
				
			||||||
| 
						 | 
					@ -42,7 +45,16 @@ public class AccountAuthenticator extends BaseAccountAuthenticator implements Au
 | 
				
			||||||
    final Optional<Account> maybeAccount = super.authenticate(basicCredentials, true);
 | 
					    final Optional<Account> maybeAccount = super.authenticate(basicCredentials, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO Remove this temporary counter after the GV2 rollout is underway
 | 
					    // TODO Remove this temporary counter after the GV2 rollout is underway
 | 
				
			||||||
    maybeAccount.ifPresent(account -> Metrics.counter(AUTHENTICATION_COUNTER_NAME, GV2_CAPABLE_TAG_NAME, String.valueOf(account.isGroupsV2Supported())).increment());
 | 
					    maybeAccount.ifPresent(account -> {
 | 
				
			||||||
 | 
					      final boolean iosDeviceHasOldGv2Capability = account.getDevices().stream().anyMatch(device ->
 | 
				
			||||||
 | 
					              (device.getApnId() != null || device.getVoipApnId() != null) &&
 | 
				
			||||||
 | 
					              (device.getCapabilities() != null && device.getCapabilities().isGv2()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      final Tag gv2CapableTag = Tag.of(GV2_CAPABLE_TAG_NAME, String.valueOf(account.isGroupsV2Supported()));
 | 
				
			||||||
 | 
					      final Tag iosOldGv2CapabilityTag = Tag.of(IOS_OLD_GV2_CAPABILITY_TAG_NAME, String.valueOf(iosDeviceHasOldGv2Capability));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Metrics.counter(AUTHENTICATION_COUNTER_NAME, List.of(gv2CapableTag, iosOldGv2CapabilityTag)).increment();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return maybeAccount;
 | 
					    return maybeAccount;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue