Skip to content

Commit

Permalink
fix: db locking issue (#1583)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka authored Apr 12, 2022
1 parent 54a1af1 commit fbafdbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
7 changes: 1 addition & 6 deletions internal/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/gin-gonic/gin"
"gopkg.in/segmentio/analytics-go.v3"

"github.com/infrahq/infra/api"
"github.com/infrahq/infra/internal"
Expand Down Expand Up @@ -514,11 +513,7 @@ func (a *API) Login(c *gin.Context, r *api.LoginRequest) (*api.LoginResponse, er

setAuthCookie(c, key, expires)

if a.t != nil {
if err := a.t.Enqueue(analytics.Track{Event: "infra.login.exchange", UserId: identity.ID.String()}); err != nil {
logging.S.Debug(err)
}
}
a.t.Event(c, "login", Properties{"method": "exchange"})

return &api.LoginResponse{PolymorphicID: identity.PolyID(), Name: identity.Name, AccessKey: key, Expires: api.Time(expires)}, nil
case r.PasswordCredentials != nil:
Expand Down
12 changes: 6 additions & 6 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ func New(options Options) (*Server, error) {
return nil, fmt.Errorf("loading certificate provider: %w", err)
}

if options.EnableTelemetry {
if err := configureTelemetry(server); err != nil {
return nil, fmt.Errorf("configuring telemetry: %w", err)
}
}

if err := server.setupInternalInfraIdentityProvider(); err != nil {
return nil, fmt.Errorf("setting up internal identity provider: %w", err)
}
Expand All @@ -162,6 +156,12 @@ func New(options Options) (*Server, error) {
return nil, fmt.Errorf("settings: %w", err)
}

if options.EnableTelemetry {
if err := configureTelemetry(server); err != nil {
return nil, fmt.Errorf("configuring telemetry: %w", err)
}
}

sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetContext("serverId", settings.ID)
})
Expand Down
14 changes: 6 additions & 8 deletions internal/server/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func NewTelemetry(db *gorm.DB) (*Telemetry, error) {
return nil, errors.New("db cannot be nil")
}

var err error
settings, err = data.GetSettings(db)
if err != nil {
return nil, err
}

return &Telemetry{
client: analytics.New(internal.TelemetryWriteKey),
db: db,
Expand All @@ -40,14 +46,6 @@ func (t *Telemetry) Enqueue(track analytics.Message) error {
return nil
}

if settings == nil {
var err error
settings, err = data.GetSettings(t.db)
if err != nil {
return err
}
}

switch track := track.(type) {
case analytics.Track:
if track.Properties == nil {
Expand Down

0 comments on commit fbafdbd

Please sign in to comment.