Add migration to create hosted runner records based on created by admin bot
What does this MR do and why?
This merge request introduces a migration specifically for GitLab Dedicated instances. It marks runners created by the admin bot as hosted runners. The migration only runs on Dedicated instances and not on .com or self-hosted setups. It finds the admin bot, then iterates through all runners created by this bot, marking each as a hosted runner. The migration is designed to be safe to re-run if it fails midway. A down migration is not implemented as it's unnecessary. The code also includes safeguards to allow cross-database modifications within a transaction, which is typically prevented.
Do not merge until https://gitlab.com/gitlab-com/gl-infra/gitlab-dedicated/instrumentor/-/merge_requests/5021 is merged.
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
NA
How to set up and validate locally
- Migration should be successful and if any records created by admin bot, should be created and associated with
ci_hosted_runnertable. Follow below steps for testing. - Create some dummy runner records with -
Ci::Runner.create!(creator: Users::Internal.admin_bot, runner_type: 1)
- Check that
Ci::HostedRunnertable is empty by runningCi::HostedRunner.all - Run the migration -
Gitlab::BackgroundMigration::MarkAdminBotRunnersAsHosted.new(start_id: Ci::Runner.minimum(:id), end_id: Ci::Runner.maximum(:id), batch_table: :ci_runners, batch_column: :id, pause_ms: 0, connection: ::Ci::ApplicationRecord.connection, sub_batch_size: 100).perform
- Check the HostedRunner table now with
Ci::HostedRunner.alland you should see the records that you created in step 2.