Skip to content

Add Sidekiq routing_rules configuration

What does this MR do?

gitlab!59604 (merged) introduced Sidekiq's routing_queues configuration that allow use re-route a sidekiq job into a particular queue based on a set of routing rules tuples. This is an example for routing_rules configuration:

  sidekiq:
    log_format: json # (default is the original format)
    routing_rules:
      - ["resource_boundary=cpu", "cpu_boundary"]
      - ["feature_category=pages", null]
      - ["*", "default"]

This MR is to add that configuration. That configuration is a part of gitlab.yml, hence this MR is just to tweak the gitlab-rails recipe that generates gitlab.yml

Link to equivalent change to k8s chart: gitlab-org/charts/gitlab!1968 (merged)

Documentation: gitlab!60479 (merged)

Testing

This MR affects the gitlab.yml configuration, which then leads to the restructuring of job queues. I design a small test in my local environment. My setup is as following:

Scenario 1

After installing a fresh nightly build, the routing rules are not configured. As a result, all the jobs are sent to the queues generated from the worker names. For examples, in this case, PagesWorker is sent to pages queue.

PagesWorker.perform_async

Visiting http://localhost:3000/admin/sidekiq/queues/pages we got:

Screen_Shot_2021-04-30_at_20.45.51

Scenario 2

In gitlab-com/gl-infra/scalability#1018 (closed), we introduced worker_name predicate allowing us to re-route a particular worker. I updated /etc/gitlab/gitlab.rb as following:

sidekiq['routing_rules'] = [
  ['worker_name=PagesWorker', 'hello']
]

Screen_Shot_2021-04-30_at_20.47.46

  • Any new jobs related to PagesWorker are not routed to hello queue, as expected:
PagesWorker.perform_async

Screen_Shot_2021-04-30_at_20.48.21

Scenario 3

Let's try a more complicated configuration:

sidekiq['routing_rules'] = [
  ['worker_name=PagesWorker', 'hello'],
  ['resource_boundary=memory', 'memory-bound'],
  ['resource_boundary=cpu', nil],
  ['*', 'default']
]

Screen_Shot_2021-04-30_at_21.03.09

I tested some workers representative for each shard. The result looks like this:

  • PagesWorker jobs are still routed to hello.
PagesWorker.perform_async

Visiting http://localhost:3000/admin/sidekiq/queues/hello we got:

Screen_Shot_2021-04-30_at_20.48.21

  • ProjectExportWorker (worker_boundary=memory) is routed to memory-bound
ProjectExportWorker.perform_async

Visiting http://localhost:3000/admin/sidekiq/queues/memory-bound we got:

Screen_Shot_2021-04-30_at_20.51.17

  • ExpirePipelineCacheWorker (worker_boundary=cpu) matches the nil queue, equivalent to queue generated from worker name.
ExpirePipelineCacheWorker.perform_async

Visiting http://localhost:3000/admin/sidekiq/queues/pipeline_cache%3Aexpire_pipeline_cache we got:

Screen_Shot_2021-04-30_at_20.51.55

  • Other jobs from random workers are routed to default
ImportSoftwareLicensesWorker.perform_async
MigrateExternalDiffsWorker.perform_async
MergeWorker.perform_async

Visiting http://localhost:3000/admin/sidekiq/queues/default we got:

Screen_Shot_2021-04-30_at_20.53.03

  • When looking at /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml, the routing_rules configuration is set in the Sidekiq section:

Screen_Shot_2021-04-30_at_20.55.41

Related issues

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion

Required

  • Merge Request Title, and Description are up to date, accurate, and descriptive
  • MR targeting the appropriate branch
  • MR has a green pipeline on GitLab.com
  • Pipeline is green on dev.gitlab.org if the change is touching anything besides documentation or internal cookbooks
  • trigger-package has a green pipeline running against latest commit

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes
  • Documentation created/updated
  • Tests added
  • Integration tests added to GitLab QA
  • Equivalent MR/issue for the GitLab Chart opened
Edited by Quang-Minh Nguyen

Merge request reports

Loading