Skip to content

Reduce queries when ticking runner queue [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Fabio Pitino requested to merge fp-reduce-queries-when-ticking-runner-queue into master

What does this MR do?

Related to #322618 (closed)

Any time a job is enqueued for the Runner we execute BuildQueueWorker which in turn executes UpdateBuildQueueService. This service iterates over the runners allowed for a specific project (build.project.all_runners) in order to run tick_runner_queue which tell runners that they can now pick up new builds.

While iterating through each runner we were calling can_pick? which runs again the check assignable_for?. This check ensures that the runner picking the build comes from a list that can pick builds for the given project, which is redundant given that the runner comes from project.all_runners.

In addition to that, assignable_for? is an expensive query given that it consists in a UNION of 3 queries: shared runners + project-specific runners + recursive query finding group-level runners.

This MR refactors can_pick? to extract the logic that can be used by UpdateBuildQueueService without the need to run assignable_for?.

Feature Flag

This change is deployed with a feature flag ci_reduce_queries_when_ticking_runner_queue that is default_enabled: true.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Kamil Trzciński

Merge request reports