Skip to content

Commit 7f13126

Browse files
authored
Merge branch 'master' into 1944-add-orchestrator-job-data-alerts
2 parents 8244b2a + 6db610e commit 7f13126

198 files changed

Lines changed: 4550 additions & 1277 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-warehouse.yml

Lines changed: 82 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ on:
2626
type: string
2727
required: false
2828
description: dbt's version to test with
29-
should-run-tests:
30-
type: boolean
31-
required: false
32-
default: true
33-
description: Whether to run E2E tests
34-
clear-tests:
35-
type: boolean
36-
required: false
37-
default: true
38-
description: Whether to clean test environment
3929
generate-data:
4030
type: boolean
4131
required: false
@@ -47,10 +37,6 @@ on:
4737
warehouse-type:
4838
type: string
4939
required: true
50-
should-run-tests:
51-
type: boolean
52-
required: false
53-
default: true
5440
elementary-ref:
5541
type: string
5642
required: false
@@ -60,24 +46,37 @@ on:
6046
dbt-version:
6147
type: string
6248
required: false
63-
clear-tests:
64-
type: boolean
65-
required: false
66-
default: true
6749
generate-data:
6850
type: boolean
6951
required: false
7052
default: false
7153

7254
env:
7355
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
74-
DBT_PKG_INTEG_TESTS_DIR: ${{ github.workspace }}/dbt-data-reliability/integration_tests/deprecated_tests
75-
ELMENTARY_INTERNAL_DBT_PKG_DIR: ${{ github.workspace }}/elementary/elementary/monitor/dbt_project
56+
ELEMENTARY_DBT_PACKAGE_PATH: ${{ github.workspace }}/dbt-data-reliability
57+
CLI_INTERNAL_DBT_PKG_DIR: ${{ github.workspace }}/elementary/elementary/monitor/dbt_project
58+
E2E_DBT_PROJECT_DIR: ${{ github.workspace }}/elementary/tests/e2e_dbt_project
7659

7760
jobs:
61+
# PRs from forks require approval, specifically with the "pull_request_target" event as it contains repo secrets.
62+
check-if-requires-approval:
63+
runs-on: ubuntu-latest
64+
outputs:
65+
requires_approval: ${{ steps.set-output.outputs.requires_approval }}
66+
steps:
67+
- name: Set requires approval output
68+
id: set-output
69+
run: |
70+
if [[ "${{ github.event_name }}" =~ ^pull_request && "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then
71+
echo "requires_approval=true" >> $GITHUB_OUTPUT
72+
else
73+
echo "requires_approval=false" >> $GITHUB_OUTPUT
74+
fi
75+
7876
test:
7977
runs-on: ubuntu-latest
80-
environment: elementary_test_env # This is a github environment (not to be confused with env vars)
78+
needs: [check-if-requires-approval]
79+
environment: ${{ (needs.check-if-requires-approval.outputs.requires_approval == 'true' && 'elementary_test_env') || '' }}
8180
defaults:
8281
run:
8382
working-directory: elementary
@@ -101,12 +100,12 @@ jobs:
101100

102101
- name: Start Postgres
103102
if: inputs.warehouse-type == 'postgres'
104-
working-directory: ${{ env.DBT_PKG_INTEG_TESTS_DIR }}
103+
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
105104
run: docker compose up -d postgres
106105

107106
# - name: Start Clickhouse
108107
# if: inputs.warehouse-type == 'clickhouse'
109-
# working-directory: ${{ env.DBT_PKG_INTEG_TESTS_DIR }}
108+
# working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
110109
# run: docker compose up -d clickhouse
111110

112111
- name: Setup Python
@@ -122,8 +121,7 @@ jobs:
122121
run: >
123122
pip install
124123
"dbt-core${{ inputs.dbt-version && format('=={0}', inputs.dbt-version) }}"
125-
# TODO: remove the <1.10.2 once we have a fix for https://github.com/elementary-data/elementary/issues/1931
126-
"dbt-${{ (inputs.warehouse-type == 'databricks_catalog' && 'databricks<1.10.2,') || inputs.warehouse-type }}${{ inputs.dbt-version && format('~={0}', inputs.dbt-version) }}"
124+
"dbt-${{ (inputs.warehouse-type == 'databricks_catalog' && 'databricks') || inputs.warehouse-type }}${{ inputs.dbt-version && format('~={0}', inputs.dbt-version) }}"
127125
128126
- name: Install Elementary
129127
run: |
@@ -136,7 +134,7 @@ jobs:
136134
run: |
137135
mkdir -p ~/.dbt
138136
DBT_VERSION=$(pip show dbt-core | grep -i version | awk '{print $2}' | sed 's/\.//g')
139-
UNDERSCORED_REF_NAME=$(echo "dbt_${DBT_VERSION}_${BRANCH_NAME}" | head -c 32 | sed "s/-/_/g")
137+
UNDERSCORED_REF_NAME=$(echo "${{ inputs.warehouse-type }}_dbt_${DBT_VERSION}_${BRANCH_NAME}" | awk '{print tolower($0)}' | head -c 40 | sed "s/[-\/]/_/g")
140138
echo "$PROFILES_YML" | base64 -d | sed "s/<SCHEMA_NAME>/py_$UNDERSCORED_REF_NAME/g" > ~/.dbt/profiles.yml
141139
142140
- name: Run Python package unit tests
@@ -154,12 +152,46 @@ jobs:
154152
rm -rf "$DBT_PKGS_PATH/elementary"
155153
ln -vs "$GITHUB_WORKSPACE/dbt-data-reliability" "$DBT_PKGS_PATH/elementary"
156154
157-
- name: Run dbt package integration tests
158-
if: github.event_name != 'workflow_dispatch' || inputs.should-run-tests
159-
working-directory: ${{ env.DBT_PKG_INTEG_TESTS_DIR }}
155+
- name: Run deps for E2E dbt project
156+
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
157+
env:
158+
ELEMENTARY_DBT_PACKAGE_PATH: ${{ env.ELEMENTARY_DBT_PACKAGE_PATH }}
160159
run: |
161160
dbt deps
162-
python run_e2e_tests.py -t "${{ inputs.warehouse-type }}" -g "${{ inputs.warehouse-type == 'postgres' || inputs.generate-data }}" --clear-tests "${{ inputs.clear-tests }}"
161+
162+
- name: Seed e2e dbt project
163+
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
164+
if: inputs.warehouse-type == 'postgres' || inputs.generate-data
165+
run: |
166+
python generate_data.py
167+
dbt seed -f --target "${{ inputs.warehouse-type }}"
168+
169+
- name: Run e2e dbt project
170+
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
171+
run: |
172+
dbt run --target "${{ inputs.warehouse-type }}" || true
173+
174+
# Validate run_results.json: only error_model should be non-success
175+
jq -e '
176+
[.results[] | select(.status != "success") | .unique_id]
177+
| length == 1 and .[0] == "model.elementary_integration_tests.error_model"
178+
' target/run_results.json > /dev/null
179+
jq_exit=$?
180+
181+
if [ $jq_exit -eq 0 ]; then
182+
echo "✅ Validation passed: only error_model failed."
183+
else
184+
echo "❌ Validation failed. Unexpected failures:"
185+
jq '[.results[] | select(.status != "success") | .unique_id] | join(", ")' target/run_results.json
186+
fi
187+
188+
exit $jq_exit
189+
190+
- name: Test e2e dbt project
191+
working-directory: ${{ env.E2E_DBT_PROJECT_DIR }}
192+
continue-on-error: true
193+
run: |
194+
dbt test --target "${{ inputs.warehouse-type }}"
163195
164196
- name: Run help
165197
run: edr --help
@@ -168,15 +200,15 @@ jobs:
168200
env:
169201
SLACK_WEBHOOK: ${{ secrets.CI_SLACK_WEBHOOK }}
170202
run: >
171-
edr monitor
203+
edr monitor
172204
-t "${{ inputs.warehouse-type }}"
173205
--group-by table
174-
--project-dir "${{ env.DBT_PKG_INTEG_TESTS_DIR }}"
206+
--project-dir "${{ env.E2E_DBT_PROJECT_DIR }}"
175207
--project-profile-target "${{ inputs.warehouse-type }}"
176208
--slack-webhook "$SLACK_WEBHOOK"
177209
178210
- name: Validate alerts statuses were updated
179-
working-directory: ${{ env.ELMENTARY_INTERNAL_DBT_PKG_DIR }}
211+
working-directory: ${{ env.CLI_INTERNAL_DBT_PKG_DIR }}
180212
run: |
181213
dbt deps
182214
dbt run-operation validate_alert_statuses_are_updated -t "${{ inputs.warehouse-type }}"
@@ -185,13 +217,19 @@ jobs:
185217
run: >
186218
edr monitor report
187219
-t "${{ inputs.warehouse-type }}"
188-
--project-dir "${{ env.DBT_PKG_INTEG_TESTS_DIR }}"
220+
--project-dir "${{ env.E2E_DBT_PROJECT_DIR }}"
189221
--project-profile-target "${{ inputs.warehouse-type }}"
190222
223+
- name: Set report artifact name
224+
id: set_report_artifact_name
225+
run: |
226+
ARTIFACT_NAME=$(echo "report_${{ inputs.warehouse-type }}_${BRANCH_NAME}_dbt_${{ inputs.dbt-version || '' }}.html" | awk '{print tolower($0)}' | sed 's#[":/\\<>|*?-]#_#g')
227+
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
228+
191229
- name: Upload report artifact
192230
uses: actions/upload-artifact@v4
193231
with:
194-
name: report_${{ inputs.warehouse-type }}_${{ env.BRANCH_NAME }}_dbt_${{ inputs.dbt-version }}.html
232+
name: ${{ steps.set_report_artifact_name.outputs.artifact_name }}
195233
path: elementary/edr_target/elementary_report.html
196234

197235
- name: Write GCS keyfile
@@ -206,9 +244,9 @@ jobs:
206244
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
207245
AZURE_CONNECTION_STRING: ${{ secrets.AZURE_CONNECTION_STRING }}
208246
run: >
209-
edr monitor send-report
247+
edr monitor send-report
210248
-t "${{ inputs.warehouse-type }}"
211-
--project-dir "${{ env.DBT_PKG_INTEG_TESTS_DIR }}"
249+
--project-dir "${{ env.E2E_DBT_PROJECT_DIR }}"
212250
--project-profile-target "${{ inputs.warehouse-type }}"
213251
--slack-file-name "report_${{ inputs.warehouse-type }}_${{ env.BRANCH_NAME }}.html"
214252
--slack-token "$SLACK_TOKEN"
@@ -223,13 +261,18 @@ jobs:
223261
--azure-container-name reports
224262
--update-bucket-website true
225263
264+
- name: Set artifact name
265+
id: set_artifact_name
266+
run: |
267+
ARTIFACT_NAME=$(echo "edr_${{ inputs.warehouse-type }}_${BRANCH_NAME}_dbt_${{ inputs.dbt-version || '' }}.log" | awk '{print tolower($0)}' | sed 's#[":/\\<>|*?-]#_#g')
268+
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
269+
226270
- name: Upload edr log
227271
if: ${{ always() }}
228272
uses: actions/upload-artifact@v4
229273
with:
230-
name: edr_${{ inputs.warehouse-type }}_${{ env.BRANCH_NAME }}_dbt_${{ inputs.dbt-version }}.log
274+
name: ${{ steps.set_artifact_name.outputs.artifact_name }}
231275
path: elementary/edr_target/edr.log
232276

233277
- name: Run Python package e2e tests
234-
if: github.event_name != 'workflow_dispatch' || inputs.should-run-tests
235278
run: pytest -vv tests/e2e --warehouse-type ${{ inputs.warehouse-type }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ venv/
9696

9797
# elementary outputs
9898
edr_target/
99-
tests/tests_with_db/dbt_project/dbt_packages/
99+
**/dbt_packages/

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ For additional information and help, you can use one of these channels:
101101
<a href="https://github.com/erikzaadi"><img src="https://avatars.githubusercontent.com/u/77775?v=4" width="50" height="50" alt=""/></a>
102102
<a href="https://github.com/dapollak"><img src="https://avatars.githubusercontent.com/u/13542197?v=4" width="50" height="50" alt=""/></a>
103103
<a href="https://github.com/Adamgo23"><img src="https://avatars.githubusercontent.com/u/125807478?v=4" width="50" height="50" alt=""/></a>
104+
<a href="https://github.com/MikaKerman"><img src="https://avatars.githubusercontent.com/u/24632225?v=4" width="50" height="50" alt=""/></a>
105+
<a href="https://github.com/GuyEshdat"><img src="https://avatars.githubusercontent.com/u/81393741?v=4" width="50" height="50" alt=""/></a>
106+
<a href="https://github.com/michael-myaskovsky"><img src="https://avatars.githubusercontent.com/u/203525071?v=4" width="50" height="50" alt=""/></a>
107+
<a href="https://github.com/arbiv"><img src="https://avatars.githubusercontent.com/u/12132333?v=4" width="50" height="50" alt=""/></a>
104108
<a href="https://github.com/RoiTabach"><img src="https://avatars.githubusercontent.com/u/25003091?v=4" width="50" height="50" alt=""/></a>
105109
<a href="https://github.com/hahnbeelee"><img src="https://avatars.githubusercontent.com/u/55263191?v=4" width="50" height="50" alt=""/></a>
106110
<a href="https://github.com/seanglynn-thrive"><img src="https://avatars.githubusercontent.com/u/93200565?v=4" width="50" height="50" alt=""/></a>
@@ -199,6 +203,12 @@ For additional information and help, you can use one of these channels:
199203
<a href="https://github.com/nkmr-jp"><img src="https://avatars.githubusercontent.com/u/8490118?v=4" width="50" height="50" alt=""/></a>
200204
<a href="https://github.com/dbt-markwan"><img src="https://avatars.githubusercontent.com/u/114556261?v=4" width="50" height="50" alt=""/></a>
201205
<a href="https://github.com/pedro-klein-ext-bayer"><img src="https://avatars.githubusercontent.com/u/181362556?v=4" width="50" height="50" alt=""/></a>
206+
<a href="https://github.com/ClementSicard"><img src="https://avatars.githubusercontent.com/u/33360172?v=4" width="50" height="50" alt=""/></a>
207+
<a href="https://github.com/nickozilla"><img src="https://avatars.githubusercontent.com/u/14976256?v=4" width="50" height="50" alt=""/></a>
208+
<a href="https://github.com/Lawiss"><img src="https://avatars.githubusercontent.com/u/30115537?v=4" width="50" height="50" alt=""/></a>
209+
<a href="https://github.com/abhipalsingh"><img src="https://avatars.githubusercontent.com/u/57302403?v=4" width="50" height="50" alt=""/></a>
210+
<a href="https://github.com/pushrbx"><img src="https://avatars.githubusercontent.com/u/6832715?v=4" width="50" height="50" alt=""/></a>
211+
202212

203213

204214
<!-- markdownlint-restore -->

docs/_snippets/quickstart-package-install.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Some packages we recommend you check out: [dbt_utils](https://github.com/dbt-lab
3939
```yml packages.yml
4040
packages:
4141
- package: elementary-data/elementary
42-
version: 0.19.2
42+
version: 0.20.0
4343
## Docs: https://docs.elementary-data.com
4444
```
4545
</Step>

elementary/clients/dbt/api_dbt_runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def collect_dbt_command_logs(event):
5757
logs=[DbtLog.from_log_line(log) for log in dbt_logs],
5858
)
5959

60-
return APIDbtCommandResult(success=res.success, output=output, result_obj=res)
60+
return APIDbtCommandResult(
61+
success=res.success, output=output, stderr=None, result_obj=res
62+
)
6163

6264
def _parse_ls_command_result(
6365
self, select: Optional[str], result: DbtCommandResult

elementary/clients/dbt/command_line_dbt_runner.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
class DbtCommandResult:
2626
success: bool
2727
output: Optional[str]
28+
stderr: Optional[str]
2829

2930

3031
class CommandLineDbtRunner(BaseDbtRunner):
@@ -190,22 +191,28 @@ def run_operation(
190191
log_pattern = (
191192
RAW_EDR_LOGS_PATTERN if return_raw_edr_logs else MACRO_RESULT_PATTERN
192193
)
193-
if capture_output and result.output is not None:
194-
for log in parse_dbt_output(result.output):
195-
if log_errors and log.level == "error":
196-
logger.error(log.msg)
197-
continue
198-
199-
if log.msg:
200-
match = log_pattern.match(log.msg)
201-
if match:
202-
run_operation_results.append(match.group(1))
194+
if capture_output:
195+
if result.output is not None:
196+
for log in parse_dbt_output(result.output):
197+
if log_errors and log.level == "error":
198+
logger.error(log.msg)
199+
continue
200+
201+
if log.msg:
202+
match = log_pattern.match(log.msg)
203+
if match:
204+
run_operation_results.append(match.group(1))
205+
206+
if result.stderr is not None and log_errors:
207+
for log in parse_dbt_output(result.stderr):
208+
if log.level == "error":
209+
logger.error(log.msg)
210+
continue
203211

204212
return run_operation_results
205213

206214
def run(
207215
self,
208-
models: Optional[str] = None,
209216
select: Optional[str] = None,
210217
selector: Optional[str] = None,
211218
full_refresh: bool = False,
@@ -216,8 +223,6 @@ def run(
216223
command_args = ["run"]
217224
if full_refresh:
218225
command_args.append("--full-refresh")
219-
if models:
220-
command_args.extend(["-m", models])
221226
if select:
222227
command_args.extend(["-s", select])
223228
if selector:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
3+
from elementary.clients.dbt.subprocess_dbt_runner import SubprocessDbtRunner
4+
5+
DBT_FUSION_PATH = os.getenv("DBT_FUSION_PATH", "~/.local/bin/dbt")
6+
7+
8+
class DbtFusionRunner(SubprocessDbtRunner):
9+
def _get_dbt_command_name(self) -> str:
10+
return os.path.expanduser(DBT_FUSION_PATH)
11+
12+
def _run_deps_if_needed(self):
13+
# Currently we don't support auto-updating deps for dbt fusion
14+
return

0 commit comments

Comments
 (0)