Metric for fresh user vs reregistration

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2016-04-13 21:03:34 -07:00
parent 76bf89dda3
commit 804d4320d7
3 changed files with 25 additions and 10 deletions

View File

@ -16,6 +16,10 @@
*/
package org.whispersystems.textsecuregcm.controllers;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.SharedMetricRegistries;
import com.codahale.metrics.Timer;
import com.codahale.metrics.annotation.Timed;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
@ -38,8 +42,10 @@ import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.storage.MessagesManager;
import org.whispersystems.textsecuregcm.storage.PendingAccountsManager;
import org.whispersystems.textsecuregcm.util.Constants;
import org.whispersystems.textsecuregcm.util.Util;
import org.whispersystems.textsecuregcm.util.VerificationCode;
import org.whispersystems.textsecuregcm.websocket.WebSocketConnection;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
@ -60,12 +66,15 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Map;
import static com.codahale.metrics.MetricRegistry.name;
import io.dropwizard.auth.Auth;
@Path("/v1/accounts")
public class AccountController {
private final Logger logger = LoggerFactory.getLogger(AccountController.class);
private final Logger logger = LoggerFactory.getLogger(AccountController.class);
private final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
private final Meter newUserMeter = metricRegistry.meter(name(AccountController.class, "brand_new_user"));
private final PendingAccountsManager pendingAccounts;
private final AccountsManager accounts;
@ -318,7 +327,10 @@ public class AccountController {
account.setNumber(number);
account.addDevice(device);
accounts.create(account);
if (accounts.create(account)) {
newUserMeter.mark();
}
messagesManager.clear(number);
pendingAccounts.remove(number);
}

View File

@ -53,11 +53,10 @@ public abstract class Accounts {
private static final ObjectMapper mapper = SystemMapper.getMapper();
@SqlUpdate("INSERT INTO accounts (" + NUMBER + ", " + DATA + ") VALUES (:number, CAST(:data AS json))")
@GetGeneratedKeys
abstract long insertStep(@AccountBinder Account account);
abstract void insertStep(@AccountBinder Account account);
@SqlUpdate("DELETE FROM accounts WHERE " + NUMBER + " = :number")
abstract void removeAccount(@Bind("number") String number);
abstract int removeAccount(@Bind("number") String number);
@SqlUpdate("UPDATE accounts SET " + DATA + " = CAST(:data AS json) WHERE " + NUMBER + " = :number")
abstract void update(@AccountBinder Account account);
@ -87,9 +86,11 @@ public abstract class Accounts {
public abstract int getUnsignedKeysCount(@Bind("since") long since);
@Transaction(TransactionIsolationLevel.SERIALIZABLE)
public long create(Account account) {
removeAccount(account.getNumber());
return insertStep(account);
public boolean create(Account account) {
int rows = removeAccount(account.getNumber());
insertStep(account);
return rows == 0;
}
@SqlUpdate("VACUUM accounts")

View File

@ -64,10 +64,12 @@ public class AccountsManager {
return accounts.getAll();
}
public void create(Account account) {
accounts.create(account);
public boolean create(Account account) {
boolean freshUser = accounts.create(account);
memcacheSet(account.getNumber(), account);
updateDirectory(account);
return freshUser;
}
public void update(Account account) {