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: allow to host dbt docs on cluster #892

Merged
merged 29 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f82c429
feat: allow to host dbt docs on cluster
Ian2012 Jul 12, 2024
11d5016
chore: remove unnecessary service dependencies
Ian2012 Jul 12, 2024
daa23e1
chore: quality fixes
Ian2012 Jul 12, 2024
285380f
fix: add environment variables for aspects deployment
Ian2012 Jul 12, 2024
0baf65c
refactor: move git initialization to entrypoint
Ian2012 Jul 12, 2024
7365743
build: correct dbt command
Ian2012 Jul 12, 2024
e1f28c8
fix: send right init dbt command
Ian2012 Jul 12, 2024
846c54f
fix: remove jinja interpolation in favor of bash scripts
Ian2012 Aug 8, 2024
3e112f6
fix: allow to disable aspects documentation
Ian2012 Aug 8, 2024
4b0b122
fix: allow to disable aspects documentation
Ian2012 Aug 8, 2024
d964cc7
fix: allow to deploy docs to k8s
Ian2012 Aug 8, 2024
2eb974d
feat: allow to store state in clickhouse
Ian2012 Aug 8, 2024
31e6774
fix: allow to store state
Ian2012 Aug 9, 2024
e44615c
chore: remove unnecessary pvc
Ian2012 Aug 9, 2024
dc9476f
fix: use backslash
Ian2012 Aug 9, 2024
4e9b382
fix: rebase fixes
Ian2012 Aug 9, 2024
fb2a09e
fix: parse dbt files before running dbt
Ian2012 Aug 9, 2024
b5e1ad6
feat: write exposures to ClickHouse
Ian2012 Aug 9, 2024
a2c8d72
perf: only clone dbt repository when needed
Ian2012 Aug 12, 2024
7e26517
refactor: restore original dbt command behavior
Ian2012 Aug 12, 2024
5065b8b
refactor: restore original dbt command behavior
Ian2012 Aug 12, 2024
1c91103
fix: use variables for current branch and repo
Ian2012 Aug 12, 2024
59b727f
fix: use variables for current branch and repo
Ian2012 Aug 12, 2024
e27e167
fix: use variables for current branch and repo
Ian2012 Aug 12, 2024
b119dea
fix: created state directory and their parents
Ian2012 Aug 12, 2024
afea8a9
fix: move to aspects-dbt folder
Ian2012 Aug 12, 2024
70c442a
fix: adjust aspects-docs deployment
Ian2012 Aug 14, 2024
166bb6d
fix: add missing args for documentation deployment
Ian2012 Aug 14, 2024
8dfec3b
fix: use plugin var for dbt profiles dir
Ian2012 Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ ASPECTS_ENABLE_EVENT_BUS_PRODUCER: true
SUPERSET_DASHBOARD_LOCALES:
- en
- fr_CA
RUN_ASPECTS_DOCS: true
6 changes: 6 additions & 0 deletions tutoraspects/patches/caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
import proxy "superset:{{SUPERSET_PORT}}"
}
{% endif %}

{% if RUN_ASPECTS_DOCS %}
{{ DBT_HOST }}{$default_site_port} {
import proxy "aspects-documentation:8090"
}
{% endif%}
83 changes: 83 additions & 0 deletions tutoraspects/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,86 @@ spec:
configMap:
name: openedx-config
{% endif %}

{% if RUN_ASPECTS_DOCS %}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: aspects-docs
labels:
app.kubernetes.io/name: aspects-docs
spec:
selector:
matchLabels:
app.kubernetes.io/name: aspects-docs
template:
metadata:
labels:
app.kubernetes.io/name: aspects-docs
spec:
containers:
- name: aspects-docs
args:
- bash
- /app/aspects/scripts/docs.sh
env:
- name: VENV_DIR
value: /opt/venv
- name: ASPECTS_EVENT_SINK_DATABASE
value: {{ASPECTS_EVENT_SINK_DATABASE}}
- name: ASPECTS_XAPI_DATABASE
value: {{ASPECTS_XAPI_DATABASE}}
- name: CLICKHOUSE_CLUSTER_NAME
value: {{CLICKHOUSE_CLUSTER_NAME}}
- name: DBT_STATE
value: {{ DBT_STATE_DIR }}
- name: ASPECTS_DATA_TTL_EXPRESSION
value: "{{ ASPECTS_DATA_TTL_EXPRESSION }}"
- name: DBT_PROFILE_TARGET_DATABASE
value: "{{ DBT_PROFILE_TARGET_DATABASE }}"
- name: DBT_PROFILES_DIR
value: {{ DBT_PROFILES_DIR }}
- name: DBT_BRANCH
value: "{{ DBT_BRANCH }}"
- name: DBT_REPOSITORY
value: "{{ DBT_REPOSITORY }}"
- name: DBT_SSH_KEY
value: "{{ DBT_SSH_KEY }}"
image: {{ DOCKER_IMAGE_ASPECTS }}
securityContext:
allowPrivilegeEscalation: false
runAsUser: 0
volumeMounts:
- mountPath: /app
name: app
- mountPath: /app/aspects/dbt
name: dbt
- mountPath: /app/aspects/scripts
name: scripts
- mountPath: /app/aspects/migrations/
name: migrations
- mountPath: /app/aspects/migrations/alembic
name: alembic
- mountPath: /app/aspects/migrations/alembic/versions
name: versions
volumes:
- name: scripts
configMap:
name: aspects-scripts
defaultMode: 0777
- name: dbt
configMap:
name: aspects-dbt
- name: app
emptyDir: {}
- name: migrations
configMap:
name: aspects-migrations
- name: alembic
configMap:
name: aspects-migrations-alembic
- name: versions
configMap:
name: aspects-migrations-alembic-versions
{% endif %}
25 changes: 18 additions & 7 deletions tutoraspects/patches/k8s-jobs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@ spec:
env:
- name: VENV_DIR
value: /opt/venv
- name: XAPI_SCHEMA
value: {{ ASPECTS_XAPI_DATABASE }}
- name: ASPECTS_EVENT_SINK_DATABASE
value: {{ASPECTS_EVENT_SINK_DATABASE}}
- name: ASPECTS_XAPI_DATABASE
value: {{ASPECTS_XAPI_DATABASE}}
- name: CLICKHOUSE_CLUSTER_NAME
value: {{CLICKHOUSE_CLUSTER_NAME}}
- name: DBT_STATE
value: {{ DBT_STATE_DIR }}
- name: ASPECTS_DATA_TTL_EXPRESSION
value: "{{ ASPECTS_DATA_TTL_EXPRESSION }}"
- name: DBT_PROFILE_TARGET_DATABASE
value: "{{ DBT_PROFILE_TARGET_DATABASE }}"
- name: DBT_PROFILES_DIR
value: {{ DBT_PROFILES_DIR }}
- name: DBT_BRANCH
value: "{{ DBT_BRANCH }}"
- name: DBT_REPOSITORY
value: "{{ DBT_REPOSITORY }}"
- name: DBT_SSH_KEY
value: "{{ DBT_SSH_KEY }}"
image: {{ DOCKER_IMAGE_ASPECTS }}
securityContext:
allowPrivilegeEscalation: false
Expand All @@ -35,12 +51,7 @@ spec:
name: alembic
- mountPath: /app/aspects/migrations/alembic/versions
name: versions
- mountPath: {{ DBT_STATE_DIR }}
name: dbt-state
volumes:
- name: dbt-state
persistentVolumeClaim:
claimName: aspects-dbt
- name: scripts
configMap:
name: aspects-scripts
Expand Down
19 changes: 18 additions & 1 deletion tutoraspects/patches/k8s-services
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,21 @@ spec:
protocol: TCP
selector:
app.kubernetes.io/name: superset
{% endif %}
{% endif %}

{% if RUN_ASPECTS_DOCS %}
---
apiVersion: v1
kind: Service
metadata:
name: aspects
labels:
app.kubernetes.io/name: aspects-docs
spec:
type: ClusterIP
ports:
- port: 7000
protocol: TCP
selector:
app.kubernetes.io/name: aspects-docs
{% endif %}
15 changes: 0 additions & 15 deletions tutoraspects/patches/k8s-volumes
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: aspects-dbt
labels:
app.kubernetes.io/component: volume
app.kubernetes.io/name: aspects-dbt
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10M

{% if RUN_CLICKHOUSE %}
---
apiVersion: v1
Expand Down
21 changes: 14 additions & 7 deletions tutoraspects/patches/local-docker-compose-jobs-services
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ aspects-job:
user: root
image: {{ DOCKER_IMAGE_ASPECTS }}
environment:
- XAPI_SCHEMA={{ ASPECTS_XAPI_DATABASE }}
VENV_DIR: /opt/venv
ASPECTS_EVENT_SINK_DATABASE: {{ASPECTS_EVENT_SINK_DATABASE}}
ASPECTS_XAPI_DATABASE: {{ASPECTS_XAPI_DATABASE}}
CLICKHOUSE_CLUSTER_NAME: {{CLICKHOUSE_CLUSTER_NAME}}
DBT_STATE: {{ DBT_STATE_DIR }}
ASPECTS_DATA_TTL_EXPRESSION: "{{ ASPECTS_DATA_TTL_EXPRESSION }}"
DBT_PROFILE_TARGET_DATABASE: "{{ DBT_PROFILE_TARGET_DATABASE }}"
DBT_PROFILES_DIR: {{ DBT_PROFILES_DIR }}
DBT_BRANCH: "{{ DBT_BRANCH }}"
DBT_REPOSITORY: "{{ DBT_REPOSITORY }}"
DBT_SSH_KEY: "{{ DBT_SSH_KEY }}"
volumes:
- ../../env/plugins/aspects/apps/aspects:/app/aspects
- ../../env/plugins/aspects/apps/aspects/scripts/:/app/aspects/scripts:ro
- ../../data/aspects-dbt:{{ DBT_STATE_DIR }}
{% if RUN_SUPERSET or RUN_CLICKHOUSE or RUN_RALPH %}depends_on:{% if RUN_SUPERSET %}
- superset{% endif %}{% if RUN_CLICKHOUSE%}
- clickhouse{% endif %}{% if RUN_RALPH %}
- ralph{% endif %}
{% if RUN_CLICKHOUSE %}
depends_on:
- clickhouse
{% endif %}
clickhouse-job:
image: {{DOCKER_IMAGE_CLICKHOUSE}}
Expand All @@ -26,5 +34,4 @@ superset-job:
depends_on:
- mysql
- redis
- superset
{% endif %}
29 changes: 27 additions & 2 deletions tutoraspects/patches/local-docker-compose-services
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ superset:
depends_on:
- mysql
- redis
- superset-worker
- superset-worker-beat

superset-worker:
{% include 'base-docker-compose-services' %}
Expand Down Expand Up @@ -123,3 +121,30 @@ aspects-consumer:
{% if RUN_MONGODB %}- mongodb{% endif %}
{% if RUN_REDIS %}- redis{% endif %}
{% endif %}

{% if RUN_ASPECTS_DOCS %}
aspects-docs:
user: root
image: {{ DOCKER_IMAGE_ASPECTS }}
environment:
VENV_DIR: /opt/venv
ASPECTS_EVENT_SINK_DATABASE: {{ASPECTS_EVENT_SINK_DATABASE}}
ASPECTS_XAPI_DATABASE: {{ASPECTS_XAPI_DATABASE}}
CLICKHOUSE_CLUSTER_NAME: {{CLICKHOUSE_CLUSTER_NAME}}
DBT_STATE: {{ DBT_STATE_DIR }}
ASPECTS_DATA_TTL_EXPRESSION: "{{ ASPECTS_DATA_TTL_EXPRESSION }}"
DBT_PROFILE_TARGET_DATABASE: "{{ DBT_PROFILE_TARGET_DATABASE }}"
DBT_PROFILES_DIR: {{ DBT_PROFILES_DIR }}
DBT_BRANCH: "{{ DBT_BRANCH }}"
DBT_REPOSITORY: "{{ DBT_REPOSITORY }}"
DBT_SSH_KEY: "{{ DBT_SSH_KEY }}"
command: |
bash /app/aspects/scripts/docs.sh
ports:
- 7000:7000
volumes:
- ../../env/plugins/aspects/apps/aspects/dbt:/app/aspects/dbt
- ../../env/plugins/aspects/apps/aspects/scripts/:/app/aspects/scripts:ro
depends_on:
{% if RUN_CLICKHOUSE %} - clickhouse{% endif %}
{% endif %}
5 changes: 4 additions & 1 deletion tutoraspects/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,12 @@
("DBT_REPOSITORY", "https://github.com/openedx/aspects-dbt"),
("DBT_BRANCH", "v3.30.0"),
("DBT_SSH_KEY", ""),
("DBT_STATE_DIR", "/app/aspects/dbt_state/"),
("DBT_STATE_DIR", "/app/aspects-dbt/state"),
("DBT_PROFILES_DIR", "/app/aspects/dbt/"),
# This is the name of the database dbt will write to
("DBT_PROFILE_TARGET_DATABASE", "reporting"),
("RUN_ASPECTS_DOCS", False),
("DBT_HOST", "dbt.{{LMS_HOST}}"),
]
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from alembic import op
import sqlalchemy as sa

revision = "0038"
down_revision = "0037"
branch_labels = None
depends_on = None
on_cluster = " ON CLUSTER '{{CLICKHOUSE_CLUSTER_NAME}}' " if "{{CLICKHOUSE_CLUSTER_NAME}}" else ""
engine = (
"ReplicatedReplacingMergeTree"
if "{{CLICKHOUSE_CLUSTER_NAME}}"
else "ReplacingMergeTree"
)


def upgrade():
op.execute(
f"""
CREATE TABLE IF NOT EXISTS {{ ASPECTS_EVENT_SINK_DATABASE }}.aspects_data
{on_cluster}
(
path String NOT NULL,
content String NOT NULL,
) ENGINE {engine}
PRIMARY KEY (path);
"""
)


def downgrade():
op.execute(
"DROP TABLE IF EXISTS {{ ASPECTS_EVENT_SINK_DATABASE }}.aspects_data"
f"{on_cluster};"
)
42 changes: 42 additions & 0 deletions tutoraspects/templates/aspects/apps/aspects/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash


set -eo pipefail

if [ -z "${DBT_SSH_KEY+x}" ]
then
mkdir -p /root/.ssh
echo "${DBT_SSH_KEY}" | tr -d '\r' > /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa
eval `ssh-agent -s`

ssh -o StrictHostKeyChecking=no [email protected] || true
ssh-add /root/.ssh/id_rsa
fi

export branch=$(git -C aspects-dbt/ branch --show-current)
export repo=$(git -C aspects-dbt/ config --get remote.origin.url)
if [ "$DBT_BRANCH" != "$branch" ] && [ "$DBT_REPOSITORY" != "$repo" ];
then
rm -rf aspects-dbt

echo "Installing aspects-dbt"
echo "git clone -b ${DBT_BRANCH} ${DBT_REPOSITORY}"
git clone -b ${DBT_BRANCH} ${DBT_REPOSITORY} aspects-dbt

cd aspects-dbt

if [ -e "./requirements.txt" ]
then
echo "Installing dbt python requirements"
pip install -r ./requirements.txt
else
echo "No requirements.txt file found; skipping"
fi

echo "Installing dbt dependencies"
dbt deps

fi

mkdir -p $DBT_STATE
Loading