Skip to content

Commit

Permalink
Don't track latest installed node as a separate event. (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang authored Jan 2, 2025
1 parent d6aa70b commit 2c46dc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 17 additions & 14 deletions server/implementation/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ func (s *DripStrictServerImplementation) InstallNode(

// Install node version
if request.Params.Version == nil {
s.MixpanelService.Track(ctx, []*mixpanel.Event{
s.MixpanelService.NewEvent("Install Node", "", map[string]any{
"Node ID": request.NodeId,
"Version": "latest",
}),
})
nodeVersion, err := s.RegistryService.GetLatestNodeVersion(ctx, s.Client, request.NodeId)
if err == nil && nodeVersion == nil {
log.Ctx(ctx).Error().Msgf("Latest node version not found")
Expand All @@ -736,22 +742,19 @@ func (s *DripStrictServerImplementation) InstallNode(
log.Ctx(ctx).Error().Msgf("Error retrieving latest node version w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}
_, err = s.RegistryService.RecordNodeInstalation(ctx, s.Client, node)

_, err = s.RegistryService.RecordNodeInstallation(ctx, s.Client, node)
if err != nil {
errMessage := "Failed to get increment number of node version install: " + err.Error()
log.Ctx(ctx).Error().Msgf("Error incrementing number of latest node version install w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}
s.MixpanelService.Track(ctx, []*mixpanel.Event{
s.MixpanelService.NewEvent("Install Node Latest", "", map[string]any{
"Node ID": request.NodeId,
"Version": nodeVersion.Version,
}),
})

return drip.InstallNode200JSONResponse(
*mapper.DbNodeVersionToApiNodeVersion(nodeVersion),
), nil
} else {

nodeVersion, err := s.RegistryService.GetNodeVersionByVersion(ctx, s.Client, request.NodeId, *request.Params.Version)
if ent.IsNotFound(err) {
log.Ctx(ctx).Error().Msgf("Error retrieving node version w/ err: %v", err)
Expand All @@ -762,18 +765,18 @@ func (s *DripStrictServerImplementation) InstallNode(
log.Ctx(ctx).Error().Msgf("Error retrieving node version w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}
_, err = s.RegistryService.RecordNodeInstalation(ctx, s.Client, node)
if err != nil {
errMessage := "Failed to get increment number of node version install: " + err.Error()
log.Ctx(ctx).Error().Msgf("Error incrementing number of latest node version install w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}
s.MixpanelService.Track(ctx, []*mixpanel.Event{
s.MixpanelService.NewEvent("Install Node", "", map[string]any{
"Node ID": request.NodeId,
"Version": nodeVersion.Version,
"Version": request.Params.Version,
}),
})
_, err = s.RegistryService.RecordNodeInstallation(ctx, s.Client, node)
if err != nil {
errMessage := "Failed to get increment number of node version install: " + err.Error()
log.Ctx(ctx).Error().Msgf("Error incrementing number of latest node version install w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}
return drip.InstallNode200JSONResponse(
*mapper.DbNodeVersionToApiNodeVersion(nodeVersion),
), nil
Expand Down
2 changes: 1 addition & 1 deletion services/registry/registry_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func (s *RegistryService) UpdateNodeVersion(ctx context.Context, client *ent.Cli
})
}

func (s *RegistryService) RecordNodeInstalation(ctx context.Context, client *ent.Client, node *ent.Node) (*ent.Node, error) {
func (s *RegistryService) RecordNodeInstallation(ctx context.Context, client *ent.Client, node *ent.Node) (*ent.Node, error) {
var n *ent.Node
err := db.WithTx(ctx, client, func(tx *ent.Tx) (err error) {
node, err = tx.Node.UpdateOne(node).AddTotalInstall(1).Save(ctx)
Expand Down

0 comments on commit 2c46dc8

Please sign in to comment.