Page MenuHomePhabricator

Switchover gitlab-replica (gitlab2002 -> gitlab1003) - September 2023
Closed, ResolvedPublic

Description

Docs: https://wikitech.wikimedia.org/wiki/GitLab/Failover
Time: Tuesday, 26th September 2023, 12:15 UTC

Current gitlab-replica: gitlab2002
Current gitlab-replica-old: gitlab1003

This is being done to test the sre.gitlab.failover cookbook ahead of the Gitlab switchover later the same week (tracked in T345531).

Checklist:

Preparations before downtime:

  • prepare change to set profile::gitlab::service_name: 'gitlab-replica.wikimedia.org' on gitlab1003, and profile::gitlab::service_name: gitlab-replica-old.wikimedia.org on gitlab2002
  • Prepare change to point DNS entry for gitlab-replica.wikimedia.org to gitlab1003 gitlab-replica-old.wikimedia.org to gitlab2002
  • Update home_page_url and apply gitlab-settings to gitlab1003 and gitlab2002
  • announce downtime some days ahead on ops/releng list/broadcast message (maybe not needed for the replica switchover)
  • lower TTL for gitlab DNS records to 300s (also PTR) (This was never changed back)

Scheduled downtime:

  • Announce downtime in #wikimedia-gitlab
  • Start gitlab failover cookbook with cookbook sre.gitlab.failover --switch-from gitlab2002 --switch-to gitlab1003 -t T334838
  • _when prompted_ merge change to set profile::gitlab::service_name: 'gitlab-replica.wikimedia.org' on gitlab1003
  • _when prompted_ Merge change to point DNS entry for gitlab-replica.wikimedia.org to gitlab1003 gitlab-replica-old.wikimedia.org to gitlab2002
  • verify installation
  • announce end of downtime
  • Update https://wikitech.wikimedia.org/wiki/GitLab to reflect the new reality

Steps removed from original checklists (marked as complete for clarity)

  • check gitlab1003 and gitlab1004 use the same ssh host keys for ssh-gitlab daemon
  • pause all GitLab Runners (gitlab-settings ./runners active | tee active.txt && ./runners pause < active.txt)
  • downtime gitlab1003 sudo cookbook sre.hosts.downtime -r "Running failover to gitlab1004- T329931" -M 120 'gitlab1004.wikimedia.org'
  • stop puppet on gitlab1003 with sudo disable-puppet "Running failover to gitlab1004 - T329931"
  • stop GitLab on gitlab1003 with gitlab-ctl stop nginx
  • stop ssh-gitlab daemon on gitlab1003 with systemctl stop ssh-gitlab
  • create full backup on gitlab1003 with /usr/bin/gitlab-backup create CRON=1 STRATEGY=copy GZIP_RSYNCABLE="true" GITLAB_BACKUP_MAX_CONCURRENCY="4" GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY="1"
  • sync backup, on gitlab1003 run /usr/bin/rsync -avp /srv/gitlab-backup/ rsync://gitlab1004.wikimedia.org/data-backup
  • trigger restore on gitlab1004 run sudo systemctl start backup-restore.service (for logs, run journalctl -f -u backup-restore.service)
  • enable puppet on gitlab1003 with sudo run-puppet-agent -e "Running failover to gitlab1004 - T329931"
  • start ssh-gitlab daemon on gitlab1003 with systemctl start ssh-gitlab
  • unpause all GitLab Runners (gitlab-settings ./runners unpause < active.txt)

Event Timeline

LSobanski triaged this task as Medium priority.Sep 5 2023, 7:07 AM
LSobanski moved this task from Incoming to Backlog on the Collaboration-Services board.
LSobanski renamed this task from Switchover gitlab-replica (gitlab2002 -> gitlab1003) to Switchover gitlab-replica (gitlab2002 -> gitlab1003) - September 2023.Sep 5 2023, 12:04 PM

Change 960632 had a related patch set uploaded (by AOkoth; author: AOkoth):

[operations/puppet@production] gitlab: change service_name on replica hosts

https://gerrit.wikimedia.org/r/960632

Change 960633 had a related patch set uploaded (by AOkoth; author: AOkoth):

[operations/dns@master] gitlab: swap replica records

https://gerrit.wikimedia.org/r/960633

Cookbook cookbooks.sre.gitlab.failover (Failover of gitlab from gitlab2002.wikimedia.org to gitlab1003.wikimedia.org) started

Cookbook cookbooks.sre.gitlab.failover (Failover of gitlab from gitlab2002.wikimedia.org to gitlab1003.wikimedia.org) encountered errors. Rollback started

Cookbook cookbooks.sre.gitlab.failover (Failover of gitlab from gitlab2002.wikimedia.org to gitlab1003.wikimedia.org) started

Change 960632 merged by AOkoth:

[operations/puppet@production] gitlab: change service_name on replica hosts

https://gerrit.wikimedia.org/r/960632

Change 960633 merged by EoghanGaffney:

[operations/dns@master] gitlab: swap replica records

https://gerrit.wikimedia.org/r/960633

Cookbook cookbooks.sre.gitlab.failover (Failover of gitlab from gitlab2002.wikimedia.org to gitlab1003.wikimedia.org) finished

The failover between the two replicas took 3 hours and 10 minutes. We discussed that we want to do some more research and find ways to reduce the downtime a bit (if possible).

I've done some more research regarding backup creation time (which is the biggest part of the failover). The usage of object storage for CI artifacts and packages would reduce the time dramatically (see T336234). But the migration to object storage needs a bit more time and evaluation.

The failover cookbook has some ways to optimize the backup creation time slightly. We are using the following command to create a full backup:

/usr/bin/gitlab-backup create CRON=1 STRATEGY=copy GZIP_RSYNCABLE="true" GITLAB_BACKUP_MAX_CONCURRENCY="4" GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY="2"

We don't need the STRATEGY=copy, as GitLab is read-only. Furthermore we can use more concurrency. According to the docs GITLAB_BACKUP_MAX_CONCURRENCY defaults to the number of logical CPUs. This config tweaks give us roughly 10 minutes less runtime.

Furthermore the option GZIP_RSYNCABLE="true" is not used properly. Rsyncable archives work only with the same filename. So we either have to reuse the name of a existing archive or remove the option. Also the correct parameter is yes instead of true. When a backup with GZIP_RSYNCABLE=yes and BACKUP=somename is used, the sync to the other host is significantly faster and only the diff is transmitted.

sudo /usr/bin/rsync -avp /srv/gitlab-backup/failover_gitlab_backup.tar rsync://gitlab2002.wikimedia.org/data-backup
sending incremental file list
failover_gitlab_backup.tar

sent 108,347,281 bytes  received 7,229,570 bytes  197,736.27 bytes/sec
total size is 105,281,085,440  speedup is 910.92

It's also possible cleanup old artifacts and packages. I've used the recommended gitlab-rake gitlab:cleanup:orphan_job_artifact_files command to clean old artifacts (thanks @eoghan ). Furthermore I went over the biggest project and removed old big artifacts (older than 6 month). That saves roughly 20GB of space which does not have to saved, synced and restored.

So to summarize the needed changes:

  • don't use COPY strategy
  • increase CONCURRENCY
  • use proper rsyncable archives and a fixed name
  • run cleanup job for old artifacts
  • manual cleanup of some old packages

I'll upload a patch for using the updated settings in the cookbook. Then I'll run a full restore between the replicas again and test the total runtime reduction.

Change 961418 had a related patch set uploaded (by Jelto; author: Jelto):

[operations/cookbooks@master] gitlab failover: tweak settings for gitlab-backup command

https://gerrit.wikimedia.org/r/961418

Change 961694 had a related patch set uploaded (by Jelto; author: Jelto):

[operations/puppet@production] gitlab: use static name in failover backup, increase concurrency

https://gerrit.wikimedia.org/r/961694

Change 961694 merged by Jelto:

[operations/puppet@production] gitlab: use static name in failover backup, increase concurrency

https://gerrit.wikimedia.org/r/961694

Change 961418 merged by jenkins-bot:

[operations/cookbooks@master] gitlab failover: use puppet-managed backup script

https://gerrit.wikimedia.org/r/961418

I have some concerns the GZIP_RSYNCABLE=yes might be slower in our use-case. It's a bit hard to replicate the production behavior with the replicas, because there is no data changes between them. Most of the time both replicas stay quite similar during the 24 hours. So I tried to sync the backup after one replica was restored during mid-da (so roughly 12 hours of new data).

I've done a test on Thursday and the rsync job took almost 3 hours: https://grafana.wikimedia.org/d/000000377/host-overview?orgId=1&var-server=gitlab1003&var-datasource=thanos&var-cluster=misc&from=1695917021544&to=1695940760033&viewPanel=8. Syncing the full backup without rsyncbale takes roughly 20 minutes.

I'll do another test from production to one replica and check the rsync run time. But we might want to drop the GZIP_RSYNCABLE=yes option again.

I've created a full "failover" backup on gitlab1004 and synced it to gitlab2002.

The backup took 85 minutes. The sync with GZIP_RSYNCABLE took 8 minutes. So the sync took less than half of the time compared to non-rsynable gzip.

Last time I just renamed the last full backup to failover_gitlab_backup.tar. So I assume that's causing issues with GZIP_RSYNCABLE diffing the backup. The log also states that the full backup was transmitted last time. This time only 4GB were sent.

So I'll leave the failover_gitlab_backup.tar on the hosts and we can try another full failover between the replicas with the GZIP_RSYNCABLE setting.

Last restore took 2 hours and 22 minutes, roughly 1 hour less than before.

So we are good to go for the Thursday production switchover.

Switchover and switchback of replicas happened. I'm closing this task. Switchover of production will happen in T345531.