Skip to content

Commit

Permalink
make metering package
Browse files Browse the repository at this point in the history
  • Loading branch information
rybit committed Feb 13, 2018
1 parent f87207c commit 381f218
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
12 changes: 2 additions & 10 deletions api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

jwt "github.com/dgrijalva/jwt-go"
"github.com/netlify/gotrue/conf"
"github.com/netlify/gotrue/metering"
"github.com/netlify/gotrue/models"
"github.com/netlify/gotrue/storage"
"github.com/sirupsen/logrus"
)

type GoTrueClaims struct {
Expand Down Expand Up @@ -98,15 +98,7 @@ func (a *API) ResourceOwnerPasswordGrant(ctx context.Context, w http.ResponseWri
if err != nil {
return err
}

// This is a load bearing log - it is used in metering.
log := getLogEntry(r)
log.WithFields(logrus.Fields{
"metering": true,
"action": "login",
"user_id": user.ID.String(),
}).Info("Login Completed")

metering.RecordLogin(r, user.ID, instanceID)
return sendJSON(w, http.StatusOK, token)
}

Expand Down
19 changes: 19 additions & 0 deletions metering/record.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package metering

import (
"net/http"

uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
)

var logger = logrus.StandardLogger().WithField("metering", true)

func RecordLogin(r *http.Request, userID, instanceID uuid.UUID) {
logger.WithFields(logrus.Fields{
"action": "login",
"domain": r.Host,
"instance_id": instanceID.String(),
"user_id": userID.String(),
}).Info("Login")
}

0 comments on commit 381f218

Please sign in to comment.