diff --git a/pkg/instance/migrate/migrate.go b/pkg/instance/migrate/migrate.go index 6e8810af..c22b5ea8 100644 --- a/pkg/instance/migrate/migrate.go +++ b/pkg/instance/migrate/migrate.go @@ -11,6 +11,7 @@ import ( "beryju.io/gravity/pkg/roles" "beryju.io/gravity/pkg/storage" "github.com/Masterminds/semver/v3" + "github.com/getsentry/sentry-go" clientv3 "go.etcd.io/etcd/client/v3" "go.uber.org/zap" ) @@ -77,15 +78,17 @@ func (mi *Migrator) Run(ctx context.Context) (*storage.Client, error) { } mi.log.Debug("Checking migrations to activate for cluster version", zap.String("clusterVersion", cv.String())) cli := mi.ri.KV() + span := sentry.TransactionFromContext(ctx).StartChild("gravity.instance.migrate") + defer span.Finish() for _, m := range mi.migrations { mi.log.Debug("Checking if migration needs to be run", zap.String("migration", m.Name())) - enabled, err := m.Check(cv, ctx) + enabled, err := m.Check(cv, span.Context()) if err != nil { mi.log.Warn("failed to check if migration should be enabled", zap.String("migration", m.Name()), zap.Error(err)) return nil, err } if enabled { - _cli, err := m.Hook(ctx) + _cli, err := m.Hook(span.Context()) if err != nil { mi.log.Warn("failed to hook for migration", zap.String("migration", m.Name()), zap.Error(err)) return nil, err @@ -94,7 +97,7 @@ func (mi *Migrator) Run(ctx context.Context) (*storage.Client, error) { cli = _cli } else { mi.log.Info("Running cleanup for migration", zap.String("migration", m.Name())) - err := m.Cleanup(ctx) + err := m.Cleanup(span.Context()) if err != nil { mi.log.Warn("failed to cleanup migration", zap.String("migration", m.Name()), zap.Error(err)) continue diff --git a/pkg/roles/dhcp/role_migrations.go b/pkg/roles/dhcp/role_migrations.go index b4796a4d..c5e99f12 100644 --- a/pkg/roles/dhcp/role_migrations.go +++ b/pkg/roles/dhcp/role_migrations.go @@ -12,13 +12,10 @@ import ( "go.uber.org/zap" ) -func (r *Role) migrateMoveInitial() { +func (r *Role) migrateMoveInitial(ctx context.Context) { r.log.Info("Running initial move migration") - res, err := r.i.KV().Get( - r.ctx, - r.i.KV().Key(types.KeyRole, types.KeyLegacyLeases).Prefix(true).String(), - clientv3.WithPrefix(), - ) + pfx := r.i.KV().Key(types.KeyRole, types.KeyLegacyLeases).Prefix(true).String() + res, err := r.i.KV().Get(ctx, pfx, clientv3.WithPrefix()) if err != nil { r.log.Warn("failed to get legacy leases", zap.Error(err)) return @@ -26,14 +23,15 @@ func (r *Role) migrateMoveInitial() { // Copy from legacy prefix (global scope) to new prefix (scope-scoped) for _, kv := range res.Kvs { l := &Lease{} + ident := strings.TrimPrefix(string(kv.Key), pfx) err = json.Unmarshal(kv.Value, &l) if err != nil { r.log.Warn("failed to parse lease", zap.Error(err)) continue } _, err = r.i.KV().Put( - r.ctx, - r.i.KV().Key(types.KeyRole, types.KeyScopes, l.ScopeKey, l.Identifier).String(), + ctx, + r.i.KV().Key(types.KeyRole, types.KeyScopes, l.ScopeKey, ident).String(), string(kv.Value), ) if err != nil { @@ -67,7 +65,7 @@ func (r *Role) RegisterMigrations() { pureKV := r.i.KV() leasePrefix := r.i.KV().Key(types.KeyRole, types.KeyScopes).Prefix(true).String() - r.migrateMoveInitial() + r.migrateMoveInitial(ctx) return r.i.KV().WithHooks(storage.StorageHook{ PutPost: func(ctx context.Context, key, val string, res *clientv3.PutResponse, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) {