[v11.2.x] CloudMigrations: improve nil handling (#93382)

CloudMigrations: improve nil handling (#93257)

* CloudMigrations: fail token decryption if session is not found or without a token

* CloudMigrations: do not report event if session is nil

(cherry picked from commit 4f21ecf982)

Co-authored-by: Matheus Macabu <macabu@users.noreply.github.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-09-17 11:52:45 +03:00
committed by GitHub
co-authored by Matheus Macabu
parent a1b8d25f79
commit fa8f24152b
4 changed files with 172 additions and 10 deletions
@@ -351,10 +351,10 @@ func (s *Service) GetSession(ctx context.Context, uid string) (*cloudmigration.C
func (s *Service) GetSessionList(ctx context.Context) (*cloudmigration.CloudMigrationSessionListResponse, error) {
values, err := s.store.GetCloudMigrationSessionList(ctx)
if err != nil {
return nil, err
return nil, fmt.Errorf("retrieving session list from store: %w", err)
}
migrations := make([]cloudmigration.CloudMigrationSessionResponse, 0)
migrations := make([]cloudmigration.CloudMigrationSessionResponse, 0, len(values))
for _, v := range values {
migrations = append(migrations, cloudmigration.CloudMigrationSessionResponse{
UID: v.UID,
@@ -473,7 +473,7 @@ func (s *Service) DeleteSession(ctx context.Context, sessionUID string) (*cloudm
session, snapshots, err := s.store.DeleteMigrationSessionByUID(ctx, sessionUID)
if err != nil {
s.report(ctx, session, gmsclient.EventDisconnect, 0, err)
return nil, fmt.Errorf("deleting migration from db: %w", err)
return nil, fmt.Errorf("deleting migration from db for session %v: %w", sessionUID, err)
}
err = s.deleteLocalFiles(snapshots)
@@ -755,6 +755,17 @@ func (s *Service) report(
return
}
if sess == nil {
errMessage := "session not found"
if evtErr != nil {
errMessage = evtErr.Error()
}
s.log.Error("failed to report event", "type", t, "error", errMessage)
return
}
e := gmsclient.EventRequestDTO{
Event: t,
LocalID: id,