Reuse docker volumes for jobs in the same autoscaler slot
With the docker autoscaler, a job on the same instance got a new cache volume on most runs, and volumes filled the disk. The volume and builds directory names used a number that counts jobs across the whole fleet. This MR uses the instance slot instead. A slot is unique on its instance and the same for every job that runs in it.
Closes #37906 (closed)
Build.UseSlotForStoragesets a slot thatProjectRealUniqueNameandProjectUniqueDiruse in place ofProjectRunnerID. The docker executor calls it inPreparewhen the build has an acquisition, and again after a retry on a replaced instance.ProjectRunnerID,CI_CONCURRENT_PROJECT_IDand the container labels do not change, so the variable stays unique across the jobs of a project. Docker-machine, plain docker and the other autoscaler executors are not affected.- Docs describe the slot in the volume and builds directory names.
- Integration tests run jobs through the real taskscaler, the static fleeting plugin and Docker, and check which volumes the jobs use.
How this was verified
The tests in executors/docker/autoscaler/cache_reuse_integration_test.go ran on a local Docker daemon, first on main without this change and then on this branch. Six jobs of one project run one after another in one slot. Their project runner IDs are 3, 0, 2, 1, 3, 0, which is what the runner assigns when other jobs of the project run on other instances. The real allocator in commands/builds_helper.go gave 1 1 0 0 to sequential jobs on one instance while another job held 0.
| Test | Without this change | With this change |
|---|---|---|
| Six sequential jobs, cache volume | 4 cache misses, 4 volumes | 1 miss, 5 hits, 1 volume |
Six sequential jobs, /builds as a volume |
4 misses, 4 volumes | 1 miss, 5 hits, 1 volume |
| Two concurrent jobs with the same project runner ID | Share one volume | Separate volumes |
To run them locally, install fleeting-plugin-static as the test jobs in .gitlab/ci/test.gitlab-ci.yml do, then run go test -tags integration ./executors/docker/autoscaler/ -run 'TestSequentialJobsInSameSlot|TestConcurrentJobsInOneInstance'. The tests skip when the plugin is missing.
Limits:
- The tests use one local instance, not a cloud fleet.
- Cache volumes are still kept after jobs. Their number is now about one per slot, project and instance, not one per fleet-wide ID.
- With
capacity_per_instanceabove 1, a job reuses the volume of its own slot only. - Volumes with the old names stay on long-lived instances. Instances that the autoscaler removes take them away.
- On docker-autoscaler, the concurrent ID in the builds path and in the volume name hash is now the slot. It no longer equals
CI_CONCURRENT_PROJECT_IDthere. The docs say so. make lintreports no issues. Inmake test,TestEnvVariablesCleanedand twoTestSetupCredentialstests fail on a cleanmainas well, on the machine I ran them on.