-
Notifications
You must be signed in to change notification settings - Fork 214
432 lines (381 loc) · 18 KB
/
test-warehouse.yml
File metadata and controls
432 lines (381 loc) · 18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
name: Test warehouse platform
on:
workflow_dispatch:
inputs:
warehouse-type:
type: choice
required: true
description: Type of warehouse platform
options:
- postgres
- snowflake
- bigquery
- redshift
- databricks_catalog
- spark
- athena
- clickhouse
- duckdb
- trino
- dremio
- fabric
- sqlserver
- vertica
elementary-ref:
type: string
required: false
description: Branch or tag to checkout for 'elementary' repository
dbt-data-reliability-ref:
type: string
required: false
description: Branch or tag to checkout for 'dbt-data-reliability' repository
dbt-version:
type: string
required: false
description: dbt's version to test with
generate-data:
type: boolean
required: false
default: false
description: Whether to generate new data
workflow_call:
inputs:
warehouse-type:
type: string
required: true
elementary-ref:
type: string
required: false
dbt-data-reliability-ref:
type: string
required: false
dbt-version:
type: string
required: false
generate-data:
type: boolean
required: false
default: false
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
ELEMENTARY_DBT_PACKAGE_PATH: ${{ github.workspace }}/dbt-data-reliability
CLI_INTERNAL_DBT_PKG_DIR: ${{ github.workspace }}/elementary/elementary/monitor/dbt_project
E2E_DBT_PROJECT_DIR: ${{ github.workspace }}/elementary/tests/e2e_dbt_project
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: elementary
concurrency:
# Serialises runs for the same warehouse × dbt-version × branch.
# The schema name is derived from a hash of this group (see "Write dbt profiles").
group: tests_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}_${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
steps:
- name: Checkout Elementary
uses: actions/checkout@v6
with:
path: elementary
ref: ${{ inputs.elementary-ref }}
- name: Checkout dbt package
uses: actions/checkout@v6
with:
repository: elementary-data/dbt-data-reliability
path: dbt-data-reliability
ref: ${{ inputs.dbt-data-reliability-ref }}
# ── Seed cache: compute key & restore volumes BEFORE starting services ──
# This ensures Docker volumes are populated before containers initialize.
- name: Compute seed cache key
id: seed-cache-key
if: inputs.warehouse-type == 'postgres' || inputs.warehouse-type == 'clickhouse' || inputs.warehouse-type == 'duckdb'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: |
# Cache key is a hash of seed-related files so that cache busts when
# the data generation script, dbt project config, or seed schemas change.
SEED_HASH=$(
{
cat generate_data.py \
dbt_project.yml \
docker-compose.yml \
${{ github.workspace }}/elementary/tests/profiles/profiles.yml.j2
echo "dbt_version=${{ inputs.dbt-version || '' }}"
} | sha256sum | head -c 16
)
echo "seed-hash=$SEED_HASH" >> "$GITHUB_OUTPUT"
- name: Restore seed cache
id: seed-cache
if: steps.seed-cache-key.outputs.seed-hash
uses: actions/cache@v5
with:
path: /tmp/seed-cache-${{ inputs.warehouse-type }}
key: seed-${{ inputs.warehouse-type }}-${{ steps.seed-cache-key.outputs.seed-hash }}
- name: Restore cached seed data into Docker volumes
if: steps.seed-cache.outputs.cache-hit == 'true' && inputs.warehouse-type != 'duckdb'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: bash ci/restore_seed_cache.sh "${{ inputs.warehouse-type }}"
- name: Restore cached DuckDB seed
if: steps.seed-cache.outputs.cache-hit == 'true' && inputs.warehouse-type == 'duckdb'
run: |
cp /tmp/seed-cache-duckdb/elementary_test.duckdb /tmp/elementary_test.duckdb
echo "DuckDB seed cache restored."
# ── Start warehouse services ──────────────────────────────────────────
- name: Start Postgres
if: inputs.warehouse-type == 'postgres'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: docker compose up -d postgres
- name: Start Clickhouse
if: inputs.warehouse-type == 'clickhouse'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: docker compose up -d clickhouse
- name: Start Trino
if: inputs.warehouse-type == 'trino'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: |
docker compose up -d --wait trino
- name: Start Dremio
if: inputs.warehouse-type == 'dremio'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: |
# Start Dremio services in detached mode with healthchecks, then
# run the setup container separately. Using --exit-code-from would
# imply --abort-on-container-exit, killing all services when the
# setup container finishes.
docker compose up -d --wait dremio dremio-minio nessie
docker compose run --rm dremio-setup
- name: Start Spark
if: inputs.warehouse-type == 'spark'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: |
docker compose up -d --build --wait spark-thrift
- name: Start SQL Server
if: inputs.warehouse-type == 'sqlserver'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: |
docker compose up -d --wait sqlserver
- name: Start Vertica
if: inputs.warehouse-type == 'vertica'
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: |
docker compose up -d --wait vertica
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Install Spark requirements
if: inputs.warehouse-type == 'spark'
run: sudo apt-get install -y python3-dev libsasl2-dev gcc
- name: Install ODBC driver for SQL Server
if: inputs.warehouse-type == 'fabric' || inputs.warehouse-type == 'sqlserver'
run: |
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc > /dev/null
curl -fsSL https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list > /dev/null
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 unixodbc-dev
- name: Install dbt
if: inputs.warehouse-type != 'vertica'
run: >
pip install
"dbt-core${{ inputs.dbt-version && format('=={0}', inputs.dbt-version) }}"
"dbt-${{ (inputs.warehouse-type == 'databricks_catalog' && 'databricks') || (inputs.warehouse-type == 'athena' && 'athena-community') || (inputs.warehouse-type == 'dremio' && 'dremio') || inputs.warehouse-type }}${{ (inputs.warehouse-type == 'spark' && '[PyHive]') || '' }}${{ inputs.dbt-version && format('~={0}', inputs.dbt-version) }}"
# dbt-vertica pins dbt-core~=1.8 which lacks the 'arguments' attribute
# used by newer dbt-core. Install dbt-vertica without deps first, then
# install the latest compatible dbt-core separately. We also install
# vertica-python (dbt-vertica's runtime dep) explicitly.
- name: Install dbt (Vertica)
if: inputs.warehouse-type == 'vertica'
run: |
pip install --no-deps dbt-vertica
pip install vertica-python
pip install "dbt-core${{ inputs.dbt-version && format('=={0}', inputs.dbt-version) }}"
- name: Install Elementary
run: |
pip install -r dev-requirements.txt
# For Vertica, dbt-vertica is already installed with --no-deps above;
# using ".[vertica]" would re-resolve dbt-vertica's deps and downgrade
# dbt-core to ~=1.8. Install elementary without the adapter extra.
if [ "${{ inputs.warehouse-type }}" = "vertica" ]; then
pip install "."
else
pip install ".[${{ (inputs.warehouse-type == 'databricks_catalog' && 'databricks') || inputs.warehouse-type }}]"
fi
- name: Write dbt profiles
env:
CI_WAREHOUSE_SECRETS: ${{ secrets.CI_WAREHOUSE_SECRETS || '' }}
run: |
# Docker-based adapters use ephemeral containers, so a fixed schema
# name is safe (the concurrency group prevents parallel collisions).
# This enables caching the seeded database state between runs.
IS_DOCKER=false
case "${{ inputs.warehouse-type }}" in
postgres|clickhouse|trino|dremio|duckdb|spark|sqlserver|vertica) IS_DOCKER=true ;;
esac
if [ "$IS_DOCKER" = "true" ]; then
SCHEMA_NAME="elementary_tests"
echo "Schema name: $SCHEMA_NAME (fixed for Docker adapter '${{ inputs.warehouse-type }}')"
else
# Cloud adapters: unique schema per run to avoid collisions.
# Schema name = py_<YYMMDD_HHMMSS>_<branch≤19>_<8-char hash>
CONCURRENCY_GROUP="tests_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}_${BRANCH_NAME}"
SHORT_HASH=$(echo -n "$CONCURRENCY_GROUP" | sha256sum | head -c 8)
SAFE_BRANCH=$(echo "${BRANCH_NAME}" | awk '{print tolower($0)}' | sed "s/[^a-z0-9]/_/g; s/__*/_/g" | head -c 19)
DATE_STAMP=$(date -u +%y%m%d_%H%M%S)
SCHEMA_NAME="py_${DATE_STAMP}_${SAFE_BRANCH}_${SHORT_HASH}"
echo "Schema name: $SCHEMA_NAME (branch='${BRANCH_NAME}', timestamp=${DATE_STAMP}, hash of concurrency group)"
fi
echo "SCHEMA_NAME=$SCHEMA_NAME" >> "$GITHUB_ENV"
python "${{ github.workspace }}/elementary/tests/profiles/generate_profiles.py" \
--template "${{ github.workspace }}/elementary/tests/profiles/profiles.yml.j2" \
--output ~/.dbt/profiles.yml \
--schema-name "$SCHEMA_NAME"
- name: Run Python package unit tests
run: pytest -vv tests/unit --warehouse-type ${{ inputs.warehouse-type }}
- name: Run Python package integration tests
run: pytest -vv tests/integration --warehouse-type ${{ inputs.warehouse-type }}
- name: Install dbt package
run: |
ELEMENTARY_PKG_LOCATION=$(pip show elementary-data | grep -i location | awk '{print $2}')
DBT_PROJECT_PATH="$ELEMENTARY_PKG_LOCATION/elementary/monitor/dbt_project"
DBT_PKGS_PATH="$DBT_PROJECT_PATH/dbt_packages"
dbt deps --project-dir "$DBT_PROJECT_PATH"
rm -rf "$DBT_PKGS_PATH/elementary"
ln -vs "$GITHUB_WORKSPACE/dbt-data-reliability" "$DBT_PKGS_PATH/elementary"
- name: Run deps for E2E dbt project
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
env:
ELEMENTARY_DBT_PACKAGE_PATH: ${{ env.ELEMENTARY_DBT_PACKAGE_PATH }}
run: |
dbt deps
- name: Generate seed data
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
if: steps.seed-cache.outputs.cache-hit != 'true'
run: python generate_data.py
- name: Seed e2e dbt project (external)
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
if: steps.seed-cache.outputs.cache-hit != 'true' && (inputs.warehouse-type == 'dremio' || inputs.warehouse-type == 'spark')
run: python load_seeds_external.py "${{ inputs.warehouse-type }}" "$SCHEMA_NAME" data
- name: Seed e2e dbt project
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
if: steps.seed-cache.outputs.cache-hit != 'true' && inputs.warehouse-type != 'dremio' && inputs.warehouse-type != 'spark'
run: dbt seed -f --target "${{ inputs.warehouse-type }}"
- name: Save seed cache from Docker volumes
if: steps.seed-cache.outputs.cache-hit != 'true' && (inputs.warehouse-type == 'postgres' || inputs.warehouse-type == 'clickhouse')
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: bash ci/save_seed_cache.sh "${{ inputs.warehouse-type }}"
- name: Save DuckDB seed cache
if: steps.seed-cache.outputs.cache-hit != 'true' && inputs.warehouse-type == 'duckdb'
run: |
mkdir -p /tmp/seed-cache-duckdb
cp /tmp/elementary_test.duckdb /tmp/seed-cache-duckdb/elementary_test.duckdb
echo "DuckDB seed cache saved."
- name: Run e2e dbt project
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
run: |
# Dremio needs single-threaded execution to avoid Nessie catalog race conditions
EXTRA_ARGS=()
if [ "${{ inputs.warehouse-type }}" = "dremio" ]; then
EXTRA_ARGS+=(--threads 1)
fi
dbt run --target "${{ inputs.warehouse-type }}" "${EXTRA_ARGS[@]}" || true
# Validate run_results.json: only error_model should be non-success
jq -e '
[.results[] | select(.status != "success") | .unique_id]
| length == 1 and .[0] == "model.elementary_integration_tests.error_model"
' target/run_results.json > /dev/null
jq_exit=$?
if [ $jq_exit -eq 0 ]; then
echo "✅ Validation passed: only error_model failed."
else
echo "❌ Validation failed. Unexpected failures:"
jq '[.results[] | select(.status != "success") | .unique_id] | join(", ")' target/run_results.json
fi
exit $jq_exit
- name: Test e2e dbt project
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
continue-on-error: true
run: |
# Dremio needs single-threaded execution to avoid Nessie catalog race conditions
EXTRA_ARGS=()
if [ "${{ inputs.warehouse-type }}" = "dremio" ]; then
EXTRA_ARGS+=(--threads 1 --exclude tag:ephemeral_model)
fi
dbt test --target "${{ inputs.warehouse-type }}" "${EXTRA_ARGS[@]}"
- name: Run help
run: edr --help
- name: Run monitor
env:
SLACK_WEBHOOK: ${{ secrets.CI_SLACK_WEBHOOK }}
run: >
edr monitor
-t "${{ inputs.warehouse-type }}"
--group-by table
--project-dir "${{ env.E2E_DBT_PROJECT_DIR }}"
--project-profile-target "${{ inputs.warehouse-type }}"
--slack-webhook "$SLACK_WEBHOOK"
- name: Validate alerts statuses were updated
working-directory: ${{ env.CLI_INTERNAL_DBT_PKG_DIR }}
run: |
dbt deps
dbt run-operation validate_alert_statuses_are_updated -t "${{ inputs.warehouse-type }}"
- name: Run report
run: >
edr monitor report
-t "${{ inputs.warehouse-type }}"
--project-dir "${{ env.E2E_DBT_PROJECT_DIR }}"
--project-profile-target "${{ inputs.warehouse-type }}"
- name: Set report artifact name
id: set_report_artifact_name
run: |
ARTIFACT_NAME=$(echo "report_${{ inputs.warehouse-type }}_${BRANCH_NAME}_dbt_${{ inputs.dbt-version || '' }}.html" | awk '{print tolower($0)}' | sed 's#[":/\\<>|*?-]#_#g')
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
- name: Upload report artifact
uses: actions/upload-artifact@v6
with:
name: ${{ steps.set_report_artifact_name.outputs.artifact_name }}
path: elementary/edr_target/elementary_report.html
- name: Write GCS keyfile
env:
GCS_KEYFILE: ${{ secrets.GCS_KEYFILE }}
run: echo "$GCS_KEYFILE" | base64 -d > /tmp/gcs_keyfile.json
- name: Run send report
env:
SLACK_TOKEN: ${{ secrets.CI_SLACK_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AZURE_CONNECTION_STRING: ${{ secrets.AZURE_CONNECTION_STRING }}
run: >
edr monitor send-report
-t "${{ inputs.warehouse-type }}"
--project-dir "${{ env.E2E_DBT_PROJECT_DIR }}"
--project-profile-target "${{ inputs.warehouse-type }}"
--slack-file-name "report_${{ inputs.warehouse-type }}_${{ env.BRANCH_NAME }}.html"
--slack-token "$SLACK_TOKEN"
--slack-channel-name data-ops
--bucket-file-path "ci_reports/report_${{ inputs.warehouse-type }}_${{ env.BRANCH_NAME }}.html"
--aws-access-key-id "$AWS_ACCESS_KEY_ID"
--aws-secret-access-key "$AWS_SECRET_ACCESS_KEY"
--s3-bucket-name elementary-ci-artifacts
# --google-service-account-path /tmp/gcs_keyfile.json
# --gcs-bucket-name elementary_ci_artifacts
--azure-connection-string "$AZURE_CONNECTION_STRING"
--azure-container-name reports
--update-bucket-website true
- name: Set artifact name
id: set_artifact_name
run: |
ARTIFACT_NAME=$(echo "edr_${{ inputs.warehouse-type }}_${BRANCH_NAME}_dbt_${{ inputs.dbt-version || '' }}.log" | awk '{print tolower($0)}' | sed 's#[":/\\<>|*?-]#_#g')
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
- name: Upload edr log
if: ${{ always() }}
uses: actions/upload-artifact@v6
with:
name: ${{ steps.set_artifact_name.outputs.artifact_name }}
path: elementary/edr_target/edr.log
- name: Run Python package e2e tests
run: pytest -vv tests/e2e --warehouse-type ${{ inputs.warehouse-type }}
- name: Drop test schemas
if: always()
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
continue-on-error: true
run: |
dbt run-operation elementary_integration_tests.drop_test_schemas --target "${{ inputs.warehouse-type }}"