Skip to content

Commit

Permalink
Improve user/wallet metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Oct 19, 2020
1 parent 3f43c3e commit aa8dbe9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 0 additions & 2 deletions app/query/caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ func (c *Caller) Call(req *jsonrpc.RPCRequest) (*jsonrpc.RPCResponse, error) {
}

if res == nil {
t := time.Now()
res, err = c.SendQuery(q)
logger.Log().Infof("time spent sending query: %.4f", time.Since(t).Seconds())
if err != nil {
return nil, rpcerrors.NewSDKError(err)
}
Expand Down
11 changes: 8 additions & 3 deletions app/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ func getOrCreateLocalUser(exec boil.Executor, remoteUserID int, log *logrus.Entr

log.Infof("user not found in the database, creating")

op := metrics.StartOperation("db", "create_user")
u := &models.User{ID: remoteUserID}
err = u.Insert(exec, boil.Infer())
if err == nil {
metrics.LbrytvNewUsers.Inc()
return u, nil
}
op.End()

// Check if we encountered a primary key violation, it would mean another routine fired another
// request managed to create a user before us and we should retrieve that user record.
Expand Down Expand Up @@ -249,9 +251,6 @@ func assignSDKServerToUser(exec boil.Executor, user *models.User, server *models
// It can recover from errors like existing wallets, but if a wallet is known to exist
// (eg. a wallet ID stored in the database already), loadWallet() should be called instead.
func Create(serverAddress string, userID int) error {
op := metrics.StartOperation(opName, "create_or_load")
defer op.End()

err := createWallet(serverAddress, userID)
if err == nil {
return nil
Expand Down Expand Up @@ -292,6 +291,9 @@ func Create(serverAddress string, userID int) error {
// // loadWallet() needs to be called before the wallet can be used
// }
func createWallet(addr string, userID int) error {
op := metrics.StartOperation(opName, "create")
defer op.End()

_, err := ljsonrpc.NewClient(addr).WalletCreate(sdkrouter.WalletID(userID), &ljsonrpc.WalletCreateOpts{
SkipOnStartup: true, CreateAccount: true, SingleKey: true})
if err != nil {
Expand All @@ -306,6 +308,9 @@ func createWallet(addr string, userID int) error {
// WalletAlreadyLoaded - wallet is already loaded and operational
// WalletNotFound - wallet file does not exist and won't be loaded.
func LoadWallet(addr string, userID int) error {
op := metrics.StartOperation(opName, "load")
defer op.End()

_, err := ljsonrpc.NewClient(addr).WalletAdd(sdkrouter.WalletID(userID))
if err != nil {
return lbrynet.NewWalletError(userID, err)
Expand Down

0 comments on commit aa8dbe9

Please sign in to comment.