Skip to content

Commit

Permalink
feat: create aspects-consumer deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Apr 2, 2024
1 parent f8fe607 commit e17ae39
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .ci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@ SUPERSET_XAPI_DASHBOARD_SLUG: openedx-xapi
ASPECTS_VERSION: 0.91.0
DOCKER_IMAGE_OPENEDX: edunext/openedx-aspects:{{ASPECTS_VERSION}}
DOCKER_IMAGE_OPENEDX_DEV: edunext/openedx-aspects-dev:{{ASPECTS_VERSION}}
ASPECTS_ENABLE_EVENT_BUS_CONSUMER: true
ASPECTS_ENABLE_EVENT_BUS_PRODUCER: true
54 changes: 54 additions & 0 deletions tutoraspects/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,57 @@ spec:
hostPath:
path: /var/log/
{% endif %}

{% if ASPECTS_ENABLE_EVENT_BUS_CONSUMER %}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: aspects-consumer
labels:
app.kubernetes.io/name: aspects-consumer
spec:
selector:
matchLabels:
app.kubernetes.io/name: aspects-consumer
template:
metadata:
labels:
app.kubernetes.io/name: aspects-consumer
spec:
securityContext:
runAsUser: 1000
runAsGroup: 1000
containers:
- name: aspects-consumer
image: {{ DOCKER_IMAGE_OPENEDX }}
env:
- name: SERVICE_VARIANT
value: lms
- name: DJANGO_SETTINGS_MODULE
value: lms.envs.tutor.production
volumeMounts:
- mountPath: /openedx/edx-platform/lms/envs/tutor/
name: settings-lms
- mountPath: /openedx/edx-platform/cms/envs/tutor/
name: settings-cms
- mountPath: /openedx/config
name: config
- mountPath: /openedx/edx-platform/uwsgi.ini
name: uwsgi-config
subPath: uwsgi.ini
securityContext:
allowPrivilegeEscalation: false
command: |
./manage.py lms consume_events -t analytics -g event_routing_backends --extra '{"consumer_name": "aspects"}'
volumes:
- name: settings-lms
configMap:
name: openedx-settings-lms
- name: settings-cms
configMap:
name: openedx-settings-cms
- name: config
configMap:
name: openedx-config
{% endif %}
9 changes: 9 additions & 0 deletions tutoraspects/patches/local-docker-compose-dev-services
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ clickhouse:
- ../../env/plugins/aspects/apps/clickhouse/dev_config:/etc/clickhouse-server/config.d/
- ../../env/plugins/aspects/apps/clickhouse/users:/etc/clickhouse-server/users.d/
{% endif %}

{% if ASPECTS_ENABLE_EVENT_BUS_CONSUMER %}
aspects-consumer:
<<: *openedx-service
environment:
DJANGO_SETTINGS_MODULE: lms.envs.tutor.development
command: |
./manage.py lms consume_events -t analytics -g event_routing_backends --extra '{"consumer_name": "aspects"}'
{% endif %}
28 changes: 28 additions & 0 deletions tutoraspects/patches/local-docker-compose-services
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,31 @@ vector:
- VECTOR_LOG=warn
restart: unless-stopped
{% endif %}

{% if ASPECTS_ENABLE_EVENT_BUS_CONSUMER %}
aspects-consumer:
image: {{ DOCKER_IMAGE_OPENEDX }}
stdin_open: true
tty: true
volumes:
# Settings & config
- ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro
- ../apps/openedx/settings/cms:/openedx/edx-platform/cms/envs/tutor:ro
- ../apps/openedx/config:/openedx/config:ro
{%- for mount in iter_mounts(MOUNTS, "openedx", "lms") %}
- {{ mount }}
{%- endfor %}
environment:
SERVICE_VARIANT: lms
DJANGO_SETTINGS_MODULE: lms.envs.tutor.production
restart: unless-stopped
command: |
./manage.py lms consume_events -t analytics -g event_routing_backends --extra '{"consumer_name": "aspects"}'
deploy:
mode: replicated
replicas: {{ ASPECTS_EVENT_BUS_CONSUMER_REPLICAS }}
depends_on:
{% if RUN_MYSQL %}- mysql{% endif %}
{% if RUN_MONGODB %}- mongodb{% endif %}
{% if RUN_REDIS %}- redis{% endif %}
{% endif %}
23 changes: 23 additions & 0 deletions tutoraspects/patches/openedx-common-settings
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,26 @@ if not OPEN_EDX_FILTERS_CONFIG.get("org.openedx.learning.instructor.dashboard.re
}
OPEN_EDX_FILTERS_CONFIG["org.openedx.learning.instructor.dashboard.render.started.v1"]["pipeline"].append("platform_plugin_aspects.extensions.filters.AddSupersetTab")
{% endif %}

{% if ASPECTS_ENABLE_EVENT_BUS_PRODUCER %}
# Update the backends to use the event bus
EVENT_TRACKING_BACKENDS["xapi"]["ENGINE"] = "eventtracking.backends.event_bus.EventBusRoutingBackend"
EVENT_TRACKING_BACKENDS["caliper"]["ENGINE"] = "eventtracking.backends.event_bus.EventBusRoutingBackend"
# Update backend to send events in sync mode
EVENT_TRACKING_BACKENDS["xapi"]["OPTIONS"]["backends"]["xapi"]["ENGINE"] = "event_routing_backends.backends.sync_events_router.SyncEventsRouter"
EVENT_TRACKING_BACKENDS["caliper"]["OPTIONS"]["backends"]["caliper"]["ENGINE"] = "event_routing_backends.backends.sync_events_router.SyncEventsRouter"
# Enable the event bus producer
SEND_TRACKING_EVENT_EMITTED_SIGNAL = True
# Update the event bus producer config
EVENT_BUS_PRODUCER_CONFIG.update(
{
"org.openedx.analytics.tracking.event.emitted.v1": {
"analytics": {
"event_key_field": "tracking_log.name", "enabled": True
}
}
}
)

INSTALLED_APPS.append("openedx_events")
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "platform-plugin-aspects==v0.5.0"
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "edx-event-routing-backends==v8.3.1"
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
pip install "event-tracking>=2.3.1"
3 changes: 3 additions & 0 deletions tutoraspects/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
# in the ClickHouse database. Make sure that you understand the legal
# consequences of data storage and privacy before turning this on!
("ASPECTS_ENABLE_PII", False),
("ASPECTS_ENABLE_EVENT_BUS_CONSUMER", False),
("ASPECTS_ENABLE_EVENT_BUS_PRODUCER", False),
("ASPECTS_EVENT_BUS_CONSUMER_REPLICAS", 1),
# User PII is cached in an in-memory dictionary for this many seconds.
("ASPECTS_PII_CACHE_LIFETIME", 900),
# Markdown comprising the Help tab for the Operator and Instructor dashboards.
Expand Down

0 comments on commit e17ae39

Please sign in to comment.