CloudMigration: Add user uid to on prem event collection (#94804)
* add useruid to report events * test
This commit is contained in:
@@ -394,7 +394,7 @@ func (s *Service) GetSessionList(ctx context.Context, orgID int64) (*cloudmigrat
|
||||
return &cloudmigration.CloudMigrationSessionListResponse{Sessions: migrations}, nil
|
||||
}
|
||||
|
||||
func (s *Service) CreateSession(ctx context.Context, cmd cloudmigration.CloudMigrationSessionRequest) (*cloudmigration.CloudMigrationSessionResponse, error) {
|
||||
func (s *Service) CreateSession(ctx context.Context, signedInUser *user.SignedInUser, cmd cloudmigration.CloudMigrationSessionRequest) (*cloudmigration.CloudMigrationSessionResponse, error) {
|
||||
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.CreateSession")
|
||||
defer span.End()
|
||||
|
||||
@@ -419,7 +419,7 @@ func (s *Service) CreateSession(ctx context.Context, cmd cloudmigration.CloudMig
|
||||
return nil, cloudmigration.ErrSessionCreationFailure.Errorf("error creating migration")
|
||||
}
|
||||
|
||||
s.report(ctx, &migration, gmsclient.EventConnect, 0, nil)
|
||||
s.report(ctx, &migration, gmsclient.EventConnect, 0, nil, signedInUser.UserUID)
|
||||
|
||||
return &cloudmigration.CloudMigrationSessionResponse{
|
||||
UID: cm.UID,
|
||||
@@ -429,18 +429,18 @@ func (s *Service) CreateSession(ctx context.Context, cmd cloudmigration.CloudMig
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) DeleteSession(ctx context.Context, orgID int64, sessionUID string) (*cloudmigration.CloudMigrationSession, error) {
|
||||
func (s *Service) DeleteSession(ctx context.Context, orgID int64, signedInUser *user.SignedInUser, sessionUID string) (*cloudmigration.CloudMigrationSession, error) {
|
||||
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.DeleteSession")
|
||||
defer span.End()
|
||||
|
||||
session, snapshots, err := s.store.DeleteMigrationSessionByUID(ctx, orgID, sessionUID)
|
||||
if err != nil {
|
||||
s.report(ctx, session, gmsclient.EventDisconnect, 0, err)
|
||||
s.report(ctx, session, gmsclient.EventDisconnect, 0, err, signedInUser.UserUID)
|
||||
return nil, fmt.Errorf("deleting migration from db for session %v: %w", sessionUID, err)
|
||||
}
|
||||
|
||||
err = s.deleteLocalFiles(snapshots)
|
||||
s.report(ctx, session, gmsclient.EventDisconnect, 0, err)
|
||||
s.report(ctx, session, gmsclient.EventDisconnect, 0, err, signedInUser.UserUID)
|
||||
return session, nil
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ func (s *Service) CreateSnapshot(ctx context.Context, signedInUser *user.SignedI
|
||||
asyncCtx, cancelFunc := context.WithCancel(asyncCtx)
|
||||
s.cancelFunc = cancelFunc
|
||||
|
||||
s.report(asyncCtx, session, gmsclient.EventStartBuildingSnapshot, 0, nil)
|
||||
s.report(asyncCtx, session, gmsclient.EventStartBuildingSnapshot, 0, nil, signedInUser.UserUID)
|
||||
|
||||
start := time.Now()
|
||||
err := s.buildSnapshot(asyncCtx, signedInUser, initResp.MaxItemsPerPartition, initResp.Metadata, snapshot)
|
||||
@@ -527,7 +527,7 @@ func (s *Service) CreateSnapshot(ctx context.Context, signedInUser *user.SignedI
|
||||
}
|
||||
|
||||
span.SetStatus(codes.Ok, "snapshot built")
|
||||
s.report(asyncCtx, session, gmsclient.EventDoneBuildingSnapshot, time.Since(start), err)
|
||||
s.report(asyncCtx, session, gmsclient.EventDoneBuildingSnapshot, time.Since(start), err, signedInUser.UserUID)
|
||||
}()
|
||||
|
||||
return &snapshot, nil
|
||||
@@ -685,7 +685,7 @@ func (s *Service) GetSnapshotList(ctx context.Context, query cloudmigration.List
|
||||
return snapshotList, nil
|
||||
}
|
||||
|
||||
func (s *Service) UploadSnapshot(ctx context.Context, orgID int64, sessionUid string, snapshotUid string) error {
|
||||
func (s *Service) UploadSnapshot(ctx context.Context, orgID int64, signedInUser *user.SignedInUser, sessionUid string, snapshotUid string) error {
|
||||
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.UploadSnapshot",
|
||||
trace.WithAttributes(
|
||||
attribute.String("sessionUid", sessionUid),
|
||||
@@ -740,7 +740,7 @@ func (s *Service) UploadSnapshot(ctx context.Context, orgID int64, sessionUid st
|
||||
|
||||
asyncCtx, s.cancelFunc = context.WithCancel(asyncCtx)
|
||||
|
||||
s.report(asyncCtx, session, gmsclient.EventStartUploadingSnapshot, 0, nil)
|
||||
s.report(asyncCtx, session, gmsclient.EventStartUploadingSnapshot, 0, nil, signedInUser.UserUID)
|
||||
|
||||
start := time.Now()
|
||||
err := s.uploadSnapshot(asyncCtx, session, snapshot, uploadUrl)
|
||||
@@ -760,7 +760,7 @@ func (s *Service) UploadSnapshot(ctx context.Context, orgID int64, sessionUid st
|
||||
}
|
||||
}
|
||||
|
||||
s.report(asyncCtx, session, gmsclient.EventDoneUploadingSnapshot, time.Since(start), err)
|
||||
s.report(asyncCtx, session, gmsclient.EventDoneUploadingSnapshot, time.Since(start), err, signedInUser.UserUID)
|
||||
}()
|
||||
|
||||
return nil
|
||||
@@ -808,6 +808,7 @@ func (s *Service) report(
|
||||
t gmsclient.LocalEventType,
|
||||
d time.Duration,
|
||||
evtErr error,
|
||||
userUID string,
|
||||
) {
|
||||
ctx, span := s.tracer.Start(ctx, "CloudMigrationService.report")
|
||||
defer span.End()
|
||||
@@ -832,6 +833,7 @@ func (s *Service) report(
|
||||
e := gmsclient.EventRequestDTO{
|
||||
Event: t,
|
||||
LocalID: id,
|
||||
UserUID: userUID,
|
||||
}
|
||||
|
||||
if d != 0 {
|
||||
|
||||
Reference in New Issue
Block a user