Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: db locking issue #1583

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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