-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add keda autoscaling support (#10)
* feat: add keda autoscaling support * refactor: use a hook to extend celery config * docs: update documentation with new filter * fix: use not required validation * fix: use listLength as string * docs: add pod-autoscaling notes * fix: allow to scale default workers * chore: quality fixes (cherry picked from commit b529b0c) * refactor: use enable_keda key per variant (cherry picked from commit b52f142) * fix: only apply overrides if default variant is set * fix: add missing enable_keda to typed dict * feat: removing CELERY_MULTIQUEUE_ENABLED * docs: clarify key entries for workers config (cherry picked from commit 70aae3b) --------- Co-authored-by: jfavellar90 <[email protected]>
- Loading branch information
1 parent
317d8ae
commit d2c2f84
Showing
9 changed files
with
211 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
These hooks are stored in a separate module. If they were included in plugin.py, then | ||
the pod-autoscaling hooks would be created in the context of some other plugin that imports | ||
them. | ||
""" | ||
|
||
from __future__ import annotations | ||
import sys | ||
|
||
if sys.version_info < (3, 11): | ||
from typing_extensions import TypedDict, NotRequired | ||
else: | ||
from typing import TypedDict, NotRequired | ||
|
||
from tutor.core.hooks import Filter | ||
|
||
|
||
class CELERY_WORKERS_ATTRS_TYPE(TypedDict): | ||
min_replicas: NotRequired[int] | ||
max_replicas: NotRequired[int] | ||
list_length: NotRequired[int] | ||
enable_keda: bool | ||
|
||
|
||
CELERY_WORKERS_CONFIG: Filter[dict[str, dict[str, CELERY_WORKERS_ATTRS_TYPE]], []] = ( | ||
Filter() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- plugins/celery/k8s/keda.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
{% if CELERY_MULTIQUEUE_ENABLED %} | ||
try: | ||
EXPLICIT_QUEUES.update({{CELERY_CMS_EXPLICIT_QUEUES}}) | ||
except NameError: | ||
EXPLICIT_QUEUES = {{CELERY_CMS_EXPLICIT_QUEUES}} | ||
{% endif %} | ||
# Prevents losing tasks when workers are shutdown | ||
CELERY_ACKS_LATE = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{% if CELERY_MULTIQUEUE_ENABLED %} | ||
try: | ||
EXPLICIT_QUEUES.update({{CELERY_LMS_EXPLICIT_QUEUES}}) | ||
except NameError: | ||
EXPLICIT_QUEUES = {{CELERY_LMS_EXPLICIT_QUEUES}} | ||
{% endif %} | ||
|
||
# Prevents losing tasks when workers are shutdown | ||
CELERY_ACKS_LATE = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% for service, variants in iter_celery_workers_config().items() %} | ||
{% for variant, config in variants.items() if config.get('enable_keda') %} | ||
{% set deployment = service + "-" + "worker" + "-" + variant.replace("_", "-")%} | ||
--- | ||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: {% if variant != 'default' %}{{ deployment }}{% else %}{{service}}-worker{% endif %}-scaledobject | ||
spec: | ||
minReplicaCount: {{ config.get("min_replicas", 0) }} | ||
maxReplicaCount: {{ config.get("max_replicas", 30) }} | ||
scaleTargetRef: | ||
kind: Deployment | ||
name: {% if variant != 'default' %}{{ deployment }}{% else %}{{service}}-worker{% endif %} | ||
triggers: | ||
- metadata: | ||
{% if REDIS_HOST == 'redis' -%} | ||
address: redis.{{K8S_NAMESPACE}}:{{REDIS_PORT}} | ||
{% else -%} | ||
address: {{REDIS_HOST}}:{{REDIS_PORT}} | ||
{% endif -%} | ||
listLength: "{{ config.get("list_length", 40)}}" | ||
listName: edx.{{service}}.core.{{variant}} | ||
type: redis | ||
{% endfor %} | ||
{% endfor %} |