Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sourcegraph): add support to scale worker horizontally #582

Conversation

michaellzc
Copy link
Member

@michaellzc michaellzc commented Nov 20, 2024

ref CLO-1023

https://sourcegraph.com/docs/admin/workers#3-split-jobs-and-scale-independently

worker is not really horizontally scalable, and it requires manually creating additionally worker deployments with the correct WORKER_JOB_ALLOWLIST and WORKER_JOB_BLOCKLIST environment variable.

This PR added native support for managing multiple worker deployment through helm template.

By default, it will work as is to day with a single worker deployment. To enable additional dedicated worker, user can specify the following overrides:

worker:
  replicas:
  - jobs:
    - workspaces-reconciler
  - jobs:
    - codeintel-upload-janitor

This will create 3 distinct worker deployment (worker, worker-0, and worker-1) with the correct WORKER_JOB_* env var. Additinoally, we also support overriding replica specific resources config. See unit test for more information.

Checklist

Test plan

CI, and manual testing with

worker:
  replicas:
  - jobs:
    - workspaces-reconciler
    resources:
      limits:
        cpu: 200m
        memory: 256Mi
      requests:
        cpu: 200m
        memory: 256Mi
 helm upgrade --install --create-namespace -n sourcegraph -f ./override.yaml sourcegraph charts/sourcegraph/.

all pods are healthy

CleanShot 2024-11-20 at 13 33 17

you can also play around with helm template --debug -f ./override.yaml sourcegraph charts/sourcegraph/. and inspect the rendered YAML

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@michaellzc michaellzc force-pushed the 11-20-feat_sourcegraph_add_support_to_scale_worker_horizontally branch 2 times, most recently from 090699e to 99dc046 Compare November 20, 2024 12:03
@michaellzc michaellzc marked this pull request as ready for review November 20, 2024 12:03
@michaellzc michaellzc requested review from jdpleiness and a team November 20, 2024 12:03
@michaellzc michaellzc force-pushed the 11-20-feat_sourcegraph_add_support_to_scale_worker_horizontally branch from 99dc046 to ef05c2b Compare November 20, 2024 12:09
@michaellzc michaellzc requested a review from eseliger November 20, 2024 12:09
Comment on lines +53 to +140
- it: should have the correct worker-0 deployment
template: worker/worker.Deployment.yaml
set:
worker:
resources:
limits:
cpu: "2"
memory: 4G
requests:
cpu: 500m
memory: 2G
replicas:
- jobs: ["job1", "job2"]
- jobs: ["job3", "job4"]
documentIndex: 1
asserts:
- containsDocument:
kind: Deployment
apiVersion: apps/v1
name: worker-0
- contains:
path: spec.template.spec.containers[0].env
content:
name: WORKER_JOB_ALLOWLIST
value: job1,job2
- notContains:
path: spec.template.spec.containers[0].env
content:
name: WORKER_JOB_BLOCKLIST
- equal:
path: spec.selector.matchLabels.worker-replica
value: worker-0
- equal:
path: spec.template.metadata.labels.worker-replica
value: worker-0
- equal:
path: spec.template.spec.containers[0].resources
value:
limits:
cpu: "2"
memory: 4G
requests:
cpu: 500m
memory: 2G
- it: should have the correct worker-1 deployment
template: worker/worker.Deployment.yaml
set:
worker:
replicas:
- jobs: ["job1", "job2"]
- jobs: ["job3", "job4"]
resources:
limits:
cpu: 2000m
memory: 4Gi
requests:
cpu: 2000m
memory: 4Gi
documentIndex: 2
asserts:
- containsDocument:
kind: Deployment
apiVersion: apps/v1
name: worker-1
- contains:
path: spec.template.spec.containers[0].env
content:
name: WORKER_JOB_ALLOWLIST
value: job3,job4
- notContains:
path: spec.template.spec.containers[0].env
content:
name: WORKER_JOB_BLOCKLIST
- equal:
path: spec.selector.matchLabels.worker-replica
value: worker-1
- equal:
path: spec.template.metadata.labels.worker-replica
value: worker-1
- equal:
path: spec.template.spec.containers[0].resources
value:
limits:
cpu: 2000m
memory: 4Gi
requests:
cpu: 2000m
memory: 4Gi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I really like the config format for this.

Copy link
Contributor

@filiphaftek filiphaftek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested and works as expected, awesome 🚀

@michaellzc michaellzc enabled auto-merge (squash) November 20, 2024 14:17
@michaellzc michaellzc force-pushed the 11-20-feat_sourcegraph_add_support_to_scale_worker_horizontally branch from ef05c2b to f8d5e61 Compare November 20, 2024 14:18
@michaellzc michaellzc merged commit f2cf93e into main Nov 20, 2024
6 checks passed
@michaellzc michaellzc deleted the 11-20-feat_sourcegraph_add_support_to_scale_worker_horizontally branch November 20, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants