Skip to content

Commit

Permalink
Merge pull request #597 from openedx/cag/ralph-deployment
Browse files Browse the repository at this point in the history
feat: deploy ralph with uvicorn
  • Loading branch information
Ian2012 authored Feb 8, 2024
2 parents af48614 + f1e005c commit c463432
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 85 deletions.
22 changes: 14 additions & 8 deletions tutoraspects/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ spec:
spec:
containers:
- args:
- python
- -m
- ralph
- -v
- DEBUG
- runserver
- -b
- clickhouse
- "uvicorn"
- "ralph.api:app"
- "--proxy-headers"
- "--log-config"
- "/etc/ralph/logging.yaml"
- "--port"
- "{{ RALPH_PORT }}"
- "--host"
- "0.0.0.0"
env:
- name: RALPH_APP_DIR
value: "/app/.ralph"
Expand Down Expand Up @@ -135,11 +136,16 @@ spec:
volumeMounts:
- mountPath: /app/.ralph
name: auth
- mountPath: /etc/ralph
name: ralph-logging
restartPolicy: Always
volumes:
- name: auth
configMap:
name: ralph-settings
- name: ralph-logging
configMap:
name: ralph-logging
{% endif %}

{% if RUN_SUPERSET %}
Expand Down
69 changes: 0 additions & 69 deletions tutoraspects/patches/k8s-jobs
Original file line number Diff line number Diff line change
Expand Up @@ -78,75 +78,6 @@ spec:
- name: CLICKHOUSE_USER
value: "{{ CLICKHOUSE_ADMIN_USER }}"

{% if RUN_RALPH %}
---
apiVersion: batch/v1
kind: Job
metadata:
name: ralph-job
labels:
app.kubernetes.io/component: job
spec:
template:
spec:
restartPolicy: Never
containers:
- name: ralph
image: {{DOCKER_IMAGE_RALPH}}
args:
- python
- -m
- ralph
- -v
- DEBUG
- runserver
- -b
- clickhouse
env:
- name: RALPH_APP_DIR
value: "/app/.ralph"
- name: RALPH_BACKENDS__LRS__CLICKHOUSE__EVENT_TABLE_NAME
value: "{{ASPECTS_RAW_XAPI_TABLE}}"
- name: RALPH_BACKENDS__LRS__CLICKHOUSE__HOST
value: "{{CLICKHOUSE_HOST}}"
- name: RALPH_BACKENDS__LRS__CLICKHOUSE__PASSWORD
value: "{{CLICKHOUSE_ADMIN_PASSWORD}}"
- name: RALPH_BACKENDS__LRS__CLICKHOUSE__PORT
value: "{{CLICKHOUSE_INTERNAL_HTTP_PORT}}"
- name: RALPH_BACKENDS__LRS__CLICKHOUSE__TEST_HOST
value: "clickhouse"
- name: RALPH_BACKENDS__LRS__CLICKHOUSE__USERNAME
value: "{{CLICKHOUSE_ADMIN_USER}}"
- name: RALPH_BACKENDS__LRS__CLICKHOUSE__DATABASE
value: "{{ASPECTS_XAPI_DATABASE}}"
- name: RALPH_RUNSERVER_BACKEND
value: "clickhouse"
- name: RALPH_RUNSERVER_HOST
value: "0.0.0.0"
- name: RALPH_RUNSERVER_MAX_SEARCH_HITS_COUNT
value: "100"
- name: RALPH_RUNSERVER_POINT_IN_TIME_KEEP_ALIVE
value: "1m"
- name: RALPH_RUNSERVER_PORT
value: "{{RALPH_PORT}}"
- name: RALPH_SENTRY_DSN
value: "{{RALPH_SENTRY_DSN}}"
- name: RALPH_EXECUTION_ENVIRONMENT
value: "{{RALPH_EXECUTION_ENVIRONMENT}}"
- name: RALPH_SENTRY_CLI_TRACES_SAMPLE_RATE
value: "{{RALPH_SENTRY_CLI_TRACES_SAMPLE_RATE}}"
- name: RALPH_SENTRY_LRS_TRACES_SAMPLE_RATE
value: "{{RALPH_SENTRY_LRS_TRACES_SAMPLE_RATE}}"
- name: RALPH_SENTRY_IGNORE_HEALTH_CHECKS
value: "{{RALPH_SENTRY_IGNORE_HEALTH_CHECKS}}"
{% if RALPH_EXTRA_SETTINGS %}
{% for key, value in RALPH_EXTRA_SETTINGS.items() %}
- name: {{key}}
value: "{{value}}"
{% endfor %}
{% endif %}
{% endif %}

{% if RUN_SUPERSET %}
---
apiVersion: batch/v1
Expand Down
7 changes: 7 additions & 0 deletions tutoraspects/patches/kustomization-configmapgenerator
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
options:
labels:
app.kubernetes.io/name: ralph

- name: ralph-logging
files:
- plugins/aspects/apps/ralph/config/logging.yaml
options:
labels:
app.kubernetes.io/name: ralph
{% endif %}

{% if RUN_SUPERSET %}
Expand Down
18 changes: 10 additions & 8 deletions tutoraspects/patches/local-docker-compose-services
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ ralph:
ports:
- "{{ RALPH_PORT }}:{{ RALPH_PORT }}"
command:
- python
- "-m"
- ralph
- "-v"
- DEBUG
- runserver
- "-b"
- "clickhouse"
- "uvicorn"
- "ralph.api:app"
- "--proxy-headers"
- "--log-config"
- "/etc/ralph/logging.yaml"
- "--port"
- "{{ RALPH_PORT }}"
- "--host"
- "0.0.0.0"
volumes:
- ../../env/plugins/aspects/apps/ralph/config/ralph_auth/:/app/.ralph
- ../../env/plugins/aspects/apps/ralph/config/logging.yaml:/etc/ralph/logging.yaml:ro
{% endif %}

{% if RUN_SUPERSET %}
Expand Down
37 changes: 37 additions & 0 deletions tutoraspects/templates/aspects/apps/ralph/config/logging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 1
disable_existing_loggers: false
formatters:
default:
"()": uvicorn.logging.DefaultFormatter
fmt: "%(asctime)s %(levelprefix)s %(message)s"
use_colors:
access:
"()": uvicorn.logging.AccessFormatter
fmt: '%(asctime)s %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s'
handlers:
default:
formatter: default
class: logging.StreamHandler
stream: ext://sys.stderr
access:
formatter: access
class: logging.StreamHandler
stream: ext://sys.stdout
loggers:
uvicorn:
handlers:
- default
level: INFO
propagate: false
uvicorn.error:
level: INFO
uvicorn.access:
handlers:
- access
level: INFO
propagate: false
ralph:
handlers:
- default
level: INFO
propagate: false

0 comments on commit c463432

Please sign in to comment.