Record the number of authentications for users with/without GV2 support.

This commit is contained in:
Jon Chambers 2020-09-21 15:10:24 -04:00 committed by Jon Chambers
parent 83f9eacac4
commit b134a69a28
1 changed files with 13 additions and 1 deletions

View File

@ -16,6 +16,8 @@
*/ */
package org.whispersystems.textsecuregcm.auth; package org.whispersystems.textsecuregcm.auth;
import io.micrometer.core.instrument.Metrics;
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;
@ -24,15 +26,25 @@ import java.util.Optional;
import io.dropwizard.auth.Authenticator; import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.basic.BasicCredentials; import io.dropwizard.auth.basic.BasicCredentials;
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 GV2_CAPABLE_TAG_NAME = "gv2";
public AccountAuthenticator(AccountsManager accountsManager) { public AccountAuthenticator(AccountsManager accountsManager) {
super(accountsManager); super(accountsManager);
} }
@Override @Override
public Optional<Account> authenticate(BasicCredentials basicCredentials) { public Optional<Account> authenticate(BasicCredentials basicCredentials) {
return super.authenticate(basicCredentials, true); final Optional<Account> maybeAccount = super.authenticate(basicCredentials, true);
// 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());
return maybeAccount;
} }
} }