From 7671bbd1f52cc5ef24f93c0cef4703c5f7ae2013 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 10:58:24 +0300 Subject: [PATCH 01/23] null commit --- macros/edr/tests/test_utils/get_anomaly_query.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/edr/tests/test_utils/get_anomaly_query.sql b/macros/edr/tests/test_utils/get_anomaly_query.sql index 71f3d8566..d5515d7bb 100644 --- a/macros/edr/tests/test_utils/get_anomaly_query.sql +++ b/macros/edr/tests/test_utils/get_anomaly_query.sql @@ -95,7 +95,7 @@ case when order by bucket_end, dimension_value {%- endset -%} {{- return(anomaly_query) -}} -{% endmacro %} +{% endmacro %} {%- macro set_directional_anomaly(anomaly_direction, anomaly_score, sensitivity) -%} From ca8a22fef7628e5c6457f33b570834121e6a1ce4 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 13:49:39 +0300 Subject: [PATCH 02/23] try run --- integration_tests/tests/test_dbt_artifacts/test_artifacts.py | 1 + integration_tests/tests/test_information_schema_columns.py | 1 + 2 files changed, 2 insertions(+) diff --git a/integration_tests/tests/test_dbt_artifacts/test_artifacts.py b/integration_tests/tests/test_dbt_artifacts/test_artifacts.py index bc6506201..f1187442b 100644 --- a/integration_tests/tests/test_dbt_artifacts/test_artifacts.py +++ b/integration_tests/tests/test_dbt_artifacts/test_artifacts.py @@ -27,6 +27,7 @@ def test_artifacts_caching(dbt_project: DbtProject): def test_artifacts_collection_in_multiple_row_batches(dbt_project: DbtProject): + dbt_project.dbt_runner.run() existing_artifacts = dbt_project.read_table("dbt_models") dbt_project.dbt_runner.vars[ diff --git a/integration_tests/tests/test_information_schema_columns.py b/integration_tests/tests/test_information_schema_columns.py index b6afbc1bb..a22838355 100644 --- a/integration_tests/tests/test_information_schema_columns.py +++ b/integration_tests/tests/test_information_schema_columns.py @@ -49,6 +49,7 @@ def test_information_schema_columns(dbt_project: DbtProject): sources = {"version": 2, "sources": [REGULAR_SOURCE]} with dbt_project.write_yaml(sources): + dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success From d5c1d661203ffd63b860b681054510f233409ecf Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 13:56:29 +0300 Subject: [PATCH 03/23] add more runs --- integration_tests/tests/test_anomalies_backfill_logic.py | 1 + integration_tests/tests/test_anomalies_ranges.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/integration_tests/tests/test_anomalies_backfill_logic.py b/integration_tests/tests/test_anomalies_backfill_logic.py index e37935000..45d88dd49 100644 --- a/integration_tests/tests/test_anomalies_backfill_logic.py +++ b/integration_tests/tests/test_anomalies_backfill_logic.py @@ -386,6 +386,7 @@ def test_bucket_size_not_aligned_with_days(dbt_project: DbtProject, test_id: str We also want to see that the "stale" buckets are not included in the computation """ + dbt_project.dbt_runner.run() utc_today = datetime.utcnow().date() data_dates = generate_dates( base_date=utc_today, step=timedelta(hours=1), days_back=4 diff --git a/integration_tests/tests/test_anomalies_ranges.py b/integration_tests/tests/test_anomalies_ranges.py index 890f421a4..2d0ece89f 100644 --- a/integration_tests/tests/test_anomalies_ranges.py +++ b/integration_tests/tests/test_anomalies_ranges.py @@ -34,6 +34,7 @@ def get_latest_anomaly_test_points(dbt_project: DbtProject, test_id: str): def test_anomaly_ranges_are_valid(test_id: str, dbt_project: DbtProject): + dbt_project.dbt_runner.run() utc_today = datetime.utcnow().date() test_date, *training_dates = generate_dates(base_date=utc_today - timedelta(1)) @@ -69,6 +70,7 @@ def test_anomaly_ranges_are_valid(test_id: str, dbt_project: DbtProject): def test_anomaly_ranges_are_valid_with_seasonality( test_id: str, dbt_project: DbtProject ): + dbt_project.dbt_runner.run() utc_today = datetime.utcnow().date() test_date, *training_dates = generate_dates( base_date=utc_today - timedelta(1), days_back=7 * 14 From 836fd9b5661c13cab906cc9980a3ad8c06db23c8 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 15:19:47 +0300 Subject: [PATCH 04/23] dbt run --- integration_tests/tests/test_anomalies_ranges.py | 2 +- integration_tests/tests/test_information_schema_columns.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/integration_tests/tests/test_anomalies_ranges.py b/integration_tests/tests/test_anomalies_ranges.py index 2d0ece89f..aaa0a2abd 100644 --- a/integration_tests/tests/test_anomalies_ranges.py +++ b/integration_tests/tests/test_anomalies_ranges.py @@ -70,7 +70,7 @@ def test_anomaly_ranges_are_valid(test_id: str, dbt_project: DbtProject): def test_anomaly_ranges_are_valid_with_seasonality( test_id: str, dbt_project: DbtProject ): - dbt_project.dbt_runner.run() + dbt_project.dbt_runner.run(capture_output=True) utc_today = datetime.utcnow().date() test_date, *training_dates = generate_dates( base_date=utc_today - timedelta(1), days_back=7 * 14 diff --git a/integration_tests/tests/test_information_schema_columns.py b/integration_tests/tests/test_information_schema_columns.py index a22838355..d09272908 100644 --- a/integration_tests/tests/test_information_schema_columns.py +++ b/integration_tests/tests/test_information_schema_columns.py @@ -58,6 +58,7 @@ def test_information_schema_columns(dbt_project: DbtProject): def test_information_schema_non_existing_schema(dbt_project: DbtProject): sources = {"version": 2, "sources": [NON_EXISTING_SCHEMA_SOURCE]} with dbt_project.write_yaml(sources): + dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success @@ -66,5 +67,6 @@ def test_information_schema_non_existing_schema(dbt_project: DbtProject): def test_information_schema_non_existing_database(dbt_project: DbtProject): sources = {"version": 2, "sources": [NON_EXISTING_DATABASE_SOURCE]} with dbt_project.write_yaml(sources): + dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success From ca845bc9d7d1861497e34d323bf04a5322e76780 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 15:36:08 +0300 Subject: [PATCH 05/23] check without index --- models/edr/run_results/test_result_rows.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/models/edr/run_results/test_result_rows.sql b/models/edr/run_results/test_result_rows.sql index 163547d21..624abf4a9 100644 --- a/models/edr/run_results/test_result_rows.sql +++ b/models/edr/run_results/test_result_rows.sql @@ -4,9 +4,6 @@ materialized = 'incremental', unique_key = 'elementary_test_results_id', on_schema_change = 'append_new_columns', - indexes=[ - {'columns': ['created_at']}, - ], full_refresh=elementary.get_config_var('elementary_full_refresh'), meta={ "timestamp_column": "created_at", From 25bd3e03c881a8c86541134b3a9f7b701fb4d344 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 16:19:18 +0300 Subject: [PATCH 06/23] fix redshift --- integration_tests/tests/test_anomalies_ranges.py | 2 -- macros/edr/tests/test_utils/get_anomaly_query.sql | 2 +- models/edr/run_results/test_result_rows.sql | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/integration_tests/tests/test_anomalies_ranges.py b/integration_tests/tests/test_anomalies_ranges.py index aaa0a2abd..890f421a4 100644 --- a/integration_tests/tests/test_anomalies_ranges.py +++ b/integration_tests/tests/test_anomalies_ranges.py @@ -34,7 +34,6 @@ def get_latest_anomaly_test_points(dbt_project: DbtProject, test_id: str): def test_anomaly_ranges_are_valid(test_id: str, dbt_project: DbtProject): - dbt_project.dbt_runner.run() utc_today = datetime.utcnow().date() test_date, *training_dates = generate_dates(base_date=utc_today - timedelta(1)) @@ -70,7 +69,6 @@ def test_anomaly_ranges_are_valid(test_id: str, dbt_project: DbtProject): def test_anomaly_ranges_are_valid_with_seasonality( test_id: str, dbt_project: DbtProject ): - dbt_project.dbt_runner.run(capture_output=True) utc_today = datetime.utcnow().date() test_date, *training_dates = generate_dates( base_date=utc_today - timedelta(1), days_back=7 * 14 diff --git a/macros/edr/tests/test_utils/get_anomaly_query.sql b/macros/edr/tests/test_utils/get_anomaly_query.sql index d5515d7bb..71f3d8566 100644 --- a/macros/edr/tests/test_utils/get_anomaly_query.sql +++ b/macros/edr/tests/test_utils/get_anomaly_query.sql @@ -95,7 +95,7 @@ case when order by bucket_end, dimension_value {%- endset -%} {{- return(anomaly_query) -}} -{% endmacro %} +{% endmacro %} {%- macro set_directional_anomaly(anomaly_direction, anomaly_score, sensitivity) -%} diff --git a/models/edr/run_results/test_result_rows.sql b/models/edr/run_results/test_result_rows.sql index 624abf4a9..f28bf0450 100644 --- a/models/edr/run_results/test_result_rows.sql +++ b/models/edr/run_results/test_result_rows.sql @@ -4,6 +4,7 @@ materialized = 'incremental', unique_key = 'elementary_test_results_id', on_schema_change = 'append_new_columns', + indexes=[{'columns': ['created_at']}] if target.type == "postgres" else [], full_refresh=elementary.get_config_var('elementary_full_refresh'), meta={ "timestamp_column": "created_at", From 6aaee96b94f247f94c3df5e9c537daee5148fa39 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 16:27:05 +0300 Subject: [PATCH 07/23] unused dbt run --- integration_tests/tests/test_anomalies_backfill_logic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integration_tests/tests/test_anomalies_backfill_logic.py b/integration_tests/tests/test_anomalies_backfill_logic.py index 45d88dd49..e37935000 100644 --- a/integration_tests/tests/test_anomalies_backfill_logic.py +++ b/integration_tests/tests/test_anomalies_backfill_logic.py @@ -386,7 +386,6 @@ def test_bucket_size_not_aligned_with_days(dbt_project: DbtProject, test_id: str We also want to see that the "stale" buckets are not included in the computation """ - dbt_project.dbt_runner.run() utc_today = datetime.utcnow().date() data_dates = generate_dates( base_date=utc_today, step=timedelta(hours=1), days_back=4 From a39cafd7182910d484d80975748f8fb31cfe0a98 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 18:14:14 +0300 Subject: [PATCH 08/23] debug race --- .github/workflows/test-warehouse.yml | 2 +- integration_tests/tests/env.py | 4 ++-- .../tests/test_dbt_artifacts/test_artifacts.py | 2 +- integration_tests/tests/test_information_schema_columns.py | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index 7efa8dfbd..7bf08b814 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -119,7 +119,7 @@ jobs: - name: Test working-directory: "${{ env.TESTS_DIR }}/tests" - run: py.test -n8 -vvv --target "${{ inputs.warehouse-type }}" --junit-xml=test-results.xml --html=detailed_report_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}.html --self-contained-html + run: py.test -n8 -vvv --target --log-cli-level=DEBUG "${{ inputs.warehouse-type }}" --junit-xml=test-results.xml --html=detailed_report_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}.html --self-contained-html - name: Upload test results if: always() diff --git a/integration_tests/tests/env.py b/integration_tests/tests/env.py index f60cda7ed..00e0bdbd9 100644 --- a/integration_tests/tests/env.py +++ b/integration_tests/tests/env.py @@ -15,5 +15,5 @@ def clear(self): self.dbt_runner.run_operation("elementary_tests.clear_env") def init(self): - self.dbt_runner.run(selector="init") - self.dbt_runner.run(select="elementary") + self.dbt_runner.run(selector="init", capture_output=True) + self.dbt_runner.run(select="elementary", capture_output=True) diff --git a/integration_tests/tests/test_dbt_artifacts/test_artifacts.py b/integration_tests/tests/test_dbt_artifacts/test_artifacts.py index f1187442b..90c4d7921 100644 --- a/integration_tests/tests/test_dbt_artifacts/test_artifacts.py +++ b/integration_tests/tests/test_dbt_artifacts/test_artifacts.py @@ -27,7 +27,7 @@ def test_artifacts_caching(dbt_project: DbtProject): def test_artifacts_collection_in_multiple_row_batches(dbt_project: DbtProject): - dbt_project.dbt_runner.run() + # dbt_project.dbt_runner.run() existing_artifacts = dbt_project.read_table("dbt_models") dbt_project.dbt_runner.vars[ diff --git a/integration_tests/tests/test_information_schema_columns.py b/integration_tests/tests/test_information_schema_columns.py index d09272908..884e6fea7 100644 --- a/integration_tests/tests/test_information_schema_columns.py +++ b/integration_tests/tests/test_information_schema_columns.py @@ -49,7 +49,7 @@ def test_information_schema_columns(dbt_project: DbtProject): sources = {"version": 2, "sources": [REGULAR_SOURCE]} with dbt_project.write_yaml(sources): - dbt_project.dbt_runner.run() + # dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success @@ -58,7 +58,7 @@ def test_information_schema_columns(dbt_project: DbtProject): def test_information_schema_non_existing_schema(dbt_project: DbtProject): sources = {"version": 2, "sources": [NON_EXISTING_SCHEMA_SOURCE]} with dbt_project.write_yaml(sources): - dbt_project.dbt_runner.run() + # dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success @@ -67,6 +67,6 @@ def test_information_schema_non_existing_schema(dbt_project: DbtProject): def test_information_schema_non_existing_database(dbt_project: DbtProject): sources = {"version": 2, "sources": [NON_EXISTING_DATABASE_SOURCE]} with dbt_project.write_yaml(sources): - dbt_project.dbt_runner.run() + # dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success From 908f7d0148e21c899fac209e7452ae959bc65c1b Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 18:16:20 +0300 Subject: [PATCH 09/23] fix yml --- .github/workflows/test-warehouse.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index 7bf08b814..0fbe9f3bf 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -119,7 +119,7 @@ jobs: - name: Test working-directory: "${{ env.TESTS_DIR }}/tests" - run: py.test -n8 -vvv --target --log-cli-level=DEBUG "${{ inputs.warehouse-type }}" --junit-xml=test-results.xml --html=detailed_report_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}.html --self-contained-html + run: py.test -n8 -vvv --log-cli-level=DEBUG --target "${{ inputs.warehouse-type }}" --junit-xml=test-results.xml --html=detailed_report_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}.html --self-contained-html - name: Upload test results if: always() From 3a3d86908e3501c6c05ecdeda24c35d82036bd77 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 18:59:06 +0300 Subject: [PATCH 10/23] write fixture logs --- .github/workflows/test-warehouse.yml | 6 ++++++ integration_tests/tests/env.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index 0fbe9f3bf..9ecfdc584 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -121,6 +121,12 @@ jobs: working-directory: "${{ env.TESTS_DIR }}/tests" run: py.test -n8 -vvv --log-cli-level=DEBUG --target "${{ inputs.warehouse-type }}" --junit-xml=test-results.xml --html=detailed_report_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}.html --self-contained-html + - name: upload dbt logs + uses: actions/upload-artifact@v4 + with: + name: dbt-logs + path: /tmp/dbt.log + - name: Upload test results if: always() uses: pmeier/pytest-results-action@main diff --git a/integration_tests/tests/env.py b/integration_tests/tests/env.py index 00e0bdbd9..c3bf19050 100644 --- a/integration_tests/tests/env.py +++ b/integration_tests/tests/env.py @@ -16,4 +16,6 @@ def clear(self): def init(self): self.dbt_runner.run(selector="init", capture_output=True) - self.dbt_runner.run(select="elementary", capture_output=True) + s, output = self.dbt_runner.run(select="elementary", capture_output=True) + for log in output: + open("/tmp/dbt.log", "a").write(log) From 2ed701accf2a3a3d340b8322ff44dc6a2be2b65d Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 19:05:11 +0300 Subject: [PATCH 11/23] fix --- integration_tests/tests/env.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/integration_tests/tests/env.py b/integration_tests/tests/env.py index c3bf19050..0032f40f4 100644 --- a/integration_tests/tests/env.py +++ b/integration_tests/tests/env.py @@ -16,6 +16,13 @@ def clear(self): def init(self): self.dbt_runner.run(selector="init", capture_output=True) - s, output = self.dbt_runner.run(select="elementary", capture_output=True) + command_args = ["run"] + command_args.extend(["-s", "elementary"]) + s, output = self.dbt_runner._run_command( + command_args=command_args, + vars=None, + quiet=False, + capture_output=True, + ) for log in output: open("/tmp/dbt.log", "a").write(log) From 39ba53bd969419a216a778fc2fc4c04d2ae88b9e Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 19:29:23 +0300 Subject: [PATCH 12/23] always --- .github/workflows/test-warehouse.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index 9ecfdc584..c925f1941 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -122,6 +122,7 @@ jobs: run: py.test -n8 -vvv --log-cli-level=DEBUG --target "${{ inputs.warehouse-type }}" --junit-xml=test-results.xml --html=detailed_report_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}.html --self-contained-html - name: upload dbt logs + if: always() uses: actions/upload-artifact@v4 with: name: dbt-logs From 21b1a49c997c0d86dff2e654a3ee5484c78afbff Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 19:57:43 +0300 Subject: [PATCH 13/23] artifacts name --- .github/workflows/test-warehouse.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index c925f1941..9932a0d44 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -125,7 +125,7 @@ jobs: if: always() uses: actions/upload-artifact@v4 with: - name: dbt-logs + name: dbt-logs-${{ inputs.warehouse-type }}-${{ input.dbt-version }} path: /tmp/dbt.log - name: Upload test results From fcd7e41901ce0dbbdcdcde7c5717e224a6ffc7f1 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 20:01:28 +0300 Subject: [PATCH 14/23] separate workers --- .github/workflows/test-warehouse.yml | 2 +- integration_tests/tests/env.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index 9932a0d44..bd5a704cf 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -126,7 +126,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: dbt-logs-${{ inputs.warehouse-type }}-${{ input.dbt-version }} - path: /tmp/dbt.log + path: /tmp/dbt_worker*.log - name: Upload test results if: always() diff --git a/integration_tests/tests/env.py b/integration_tests/tests/env.py index 0032f40f4..e996eae00 100644 --- a/integration_tests/tests/env.py +++ b/integration_tests/tests/env.py @@ -1,5 +1,9 @@ +import os + import dbt_project +PYTEST_XDIST_WORKER = os.environ.get("PYTEST_XDIST_WORKER", "") + def init(target: str, project_dir: str): tests_env = Environment(target, project_dir) @@ -25,4 +29,4 @@ def init(self): capture_output=True, ) for log in output: - open("/tmp/dbt.log", "a").write(log) + open(f"/tmp/dbt_worker_{PYTEST_XDIST_WORKER}.log", "a").write(log) From 6dd18238b80216e20bfeed8075d62e9566a64899 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 20:25:17 +0300 Subject: [PATCH 15/23] . --- integration_tests/tests/env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/tests/env.py b/integration_tests/tests/env.py index e996eae00..7750143e5 100644 --- a/integration_tests/tests/env.py +++ b/integration_tests/tests/env.py @@ -22,7 +22,7 @@ def init(self): self.dbt_runner.run(selector="init", capture_output=True) command_args = ["run"] command_args.extend(["-s", "elementary"]) - s, output = self.dbt_runner._run_command( + ss, output = self.dbt_runner._run_command( command_args=command_args, vars=None, quiet=False, From 6ea8cd0a58e9c50cf798abf2ed30ed0649a111dd Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 20:56:34 +0300 Subject: [PATCH 16/23] fix yml --- .github/workflows/test-warehouse.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index bd5a704cf..247368935 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -125,7 +125,7 @@ jobs: if: always() uses: actions/upload-artifact@v4 with: - name: dbt-logs-${{ inputs.warehouse-type }}-${{ input.dbt-version }} + name: dbt-logs-${{ inputs.warehouse-type }}-${{ inputs.dbt-version }} path: /tmp/dbt_worker*.log - name: Upload test results From b2415ba5563e57382cc7e34aa7b8e09943c511ac Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Thu, 11 Apr 2024 22:38:54 +0300 Subject: [PATCH 17/23] add logs --- macros/edr/system/system_utils/logs.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/macros/edr/system/system_utils/logs.sql b/macros/edr/system/system_utils/logs.sql index c516df16e..e599a2b4b 100644 --- a/macros/edr/system/system_utils/logs.sql +++ b/macros/edr/system/system_utils/logs.sql @@ -55,20 +55,25 @@ {% macro end_duration_measure_context(context_name, log_durations=false) %} {% set duration_context_stack = elementary.get_cache('duration_context_stack') %} + {% do elementary.debug_log('### duration_context_stack' ~ duration_context_stack) %} {% if duration_context_stack is none %} {# If the duration stack is not initialized, it means we're not called from the package #} {% do return(none) %} {% endif %} {% set context_index = elementary.get_duration_context_index(context_name) %} + {% do elementary.debug_log('### context_index' ~ (context_index | str)) %} {% if context_index is none %} {% do elementary.debug_log('warning - end_duration_measure_context called without matching start_duration_measure_context') %} {% do return(none) %} {% endif %} {% set cur_context = namespace(data=none) %} + {% do elementary.debug_log('### context_index' ~ (cur_context | str)) %} {% for _ in range(context_index) %} - {% set cur_context.data = elementary.pop_duration_context() %} + {% set dur_context = elementary.pop_duration_context() %} + {% do elementary.debug_log('### dur_context' ~ (dur_context | str)) %} + {% set cur_context.data = dur_context %} {% endfor %} {% if log_durations %} From d37777647428b5cc1d5c3690955563f404077ef1 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Fri, 12 Apr 2024 06:27:51 +0300 Subject: [PATCH 18/23] fix ? --- macros/edr/system/system_utils/logs.sql | 39 ++++++++++++------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/macros/edr/system/system_utils/logs.sql b/macros/edr/system/system_utils/logs.sql index e599a2b4b..5591888ad 100644 --- a/macros/edr/system/system_utils/logs.sql +++ b/macros/edr/system/system_utils/logs.sql @@ -55,24 +55,21 @@ {% macro end_duration_measure_context(context_name, log_durations=false) %} {% set duration_context_stack = elementary.get_cache('duration_context_stack') %} - {% do elementary.debug_log('### duration_context_stack' ~ duration_context_stack) %} {% if duration_context_stack is none %} {# If the duration stack is not initialized, it means we're not called from the package #} {% do return(none) %} {% endif %} {% set context_index = elementary.get_duration_context_index(context_name) %} - {% do elementary.debug_log('### context_index' ~ (context_index | str)) %} {% if context_index is none %} {% do elementary.debug_log('warning - end_duration_measure_context called without matching start_duration_measure_context') %} {% do return(none) %} {% endif %} {% set cur_context = namespace(data=none) %} - {% do elementary.debug_log('### context_index' ~ (cur_context | str)) %} {% for _ in range(context_index) %} {% set dur_context = elementary.pop_duration_context() %} - {% do elementary.debug_log('### dur_context' ~ (dur_context | str)) %} + {% endif %} {% set cur_context.data = dur_context %} {% endfor %} @@ -117,23 +114,25 @@ }) %} {# Merge durations and num runs to parent context #} - {% set parent_context = duration_context_stack[-1] %} - {% for sub_context_name, sub_context_duration in cur_context.durations.items() %} - {% set full_sub_context_name = parent_context.name ~ '.' ~ sub_context_name %} - {% set existing_duration = parent_context.durations.get(full_sub_context_name, modules.datetime.timedelta()) %} - - {% do parent_context.durations.update({ - full_sub_context_name: existing_duration + sub_context_duration, - }) %} - {% endfor %} - {% for sub_context_name, sub_context_num_runs in cur_context.num_runs.items() %} - {% set full_sub_context_name = parent_context.name ~ '.' ~ sub_context_name %} - {% set existing_num_runs = parent_context.num_runs.get(full_sub_context_name, 0) %} + {% if duration_context_stack | length > 0 %} + {% set parent_context = duration_context_stack[-1] %} + {% for sub_context_name, sub_context_duration in cur_context.durations.items() %} + {% set full_sub_context_name = parent_context.name ~ '.' ~ sub_context_name %} + {% set existing_duration = parent_context.durations.get(full_sub_context_name, modules.datetime.timedelta()) %} + + {% do parent_context.durations.update({ + full_sub_context_name: existing_duration + sub_context_duration, + }) %} + {% endfor %} + {% for sub_context_name, sub_context_num_runs in cur_context.num_runs.items() %} + {% set full_sub_context_name = parent_context.name ~ '.' ~ sub_context_name %} + {% set existing_num_runs = parent_context.num_runs.get(full_sub_context_name, 0) %} - {% do parent_context.num_runs.update({ - full_sub_context_name: existing_num_runs + sub_context_num_runs - }) %} - {% endfor %} + {% do parent_context.num_runs.update({ + full_sub_context_name: existing_num_runs + sub_context_num_runs + }) %} + {% endfor %} + {% endif %} {% do return(cur_context) %} {% endmacro %} From 6a4a9391b01e39bdd0cf5a42465e456dec928978 Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Fri, 12 Apr 2024 06:29:12 +0300 Subject: [PATCH 19/23] . --- macros/edr/system/system_utils/logs.sql | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/macros/edr/system/system_utils/logs.sql b/macros/edr/system/system_utils/logs.sql index 5591888ad..1f944507b 100644 --- a/macros/edr/system/system_utils/logs.sql +++ b/macros/edr/system/system_utils/logs.sql @@ -68,9 +68,7 @@ {% set cur_context = namespace(data=none) %} {% for _ in range(context_index) %} - {% set dur_context = elementary.pop_duration_context() %} - {% endif %} - {% set cur_context.data = dur_context %} + {% set cur_context.data = elementary.pop_duration_context() %} {% endfor %} {% if log_durations %} From bf2012bfc1762e6dd43d4a05ad882c19dfd584cd Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Fri, 12 Apr 2024 16:18:40 +0300 Subject: [PATCH 20/23] thread safe duration contexts --- macros/edr/system/system_utils/logs.sql | 24 +++++++++++++++---- .../on_run_start/init_elementary_graph.sql | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/macros/edr/system/system_utils/logs.sql b/macros/edr/system/system_utils/logs.sql index 1f944507b..a25930f05 100644 --- a/macros/edr/system/system_utils/logs.sql +++ b/macros/edr/system/system_utils/logs.sql @@ -44,7 +44,7 @@ {% endmacro %} {% macro begin_duration_measure_context(context_name) %} - {% set duration_context_stack = elementary.get_cache('duration_context_stack') %} + {% set duration_context_stack = elementary.get_duration_context_stack() %} {% if duration_context_stack is none %} {# If the duration stack is not initialized, it means we're not called from the package #} {% do return(none) %} @@ -54,7 +54,7 @@ {% endmacro %} {% macro end_duration_measure_context(context_name, log_durations=false) %} - {% set duration_context_stack = elementary.get_cache('duration_context_stack') %} + {% set duration_context_stack = elementary.get_duration_context_stack() %} {% if duration_context_stack is none %} {# If the duration stack is not initialized, it means we're not called from the package #} {% do return(none) %} @@ -89,8 +89,22 @@ }) %} {% endmacro %} +{% macro get_duration_context_stack() %} + {% set global_duration_context_stack = elementary.get_cache('duration_context_stack') %} + {% if global_duration_context_stack is none %} + {# If the duration stack is not initialized, it means we're not called from the package #} + {% do return(none) %} + {% endif %} + + {% set thread_stack = global_duration_context_stack.get(thread_id) %} + {% if not thread_stack %} + {% do global_duration_context_stack.get("elementary", {}).update({thread_id: []}) %} + {% endif %} + {{ return(global_duration_context_stack.get(thread_id)) }} +{% endmacro %} + {% macro get_duration_context_index(context_name) %} - {% set duration_context_stack = elementary.get_cache('duration_context_stack') %} + {% set duration_context_stack = elementary.get_duration_context_stack() %} {% for context in duration_context_stack | reverse %} {% if context.name == context_name %} {% do return(loop.index) %} @@ -100,7 +114,7 @@ {% endmacro %} {% macro pop_duration_context() %} - {% set duration_context_stack = elementary.get_cache('duration_context_stack') %} + {% set duration_context_stack = elementary.get_duration_context_stack() %} {# Pop current context and calculate total duration for it #} {% set cur_context = duration_context_stack.pop() %} @@ -136,7 +150,7 @@ {% endmacro %} {% macro get_stack_contexts() %} - {% set duration_context_stack = elementary.get_cache('duration_context_stack') %} + {% set duration_context_stack = elementary.get_duration_context_stack() %} {% set names = []%} {% for context in duration_context_stack %} {% do names.append(context.name) %} diff --git a/macros/edr/tests/on_run_start/init_elementary_graph.sql b/macros/edr/tests/on_run_start/init_elementary_graph.sql index c167583fe..cc6423116 100644 --- a/macros/edr/tests/on_run_start/init_elementary_graph.sql +++ b/macros/edr/tests/on_run_start/init_elementary_graph.sql @@ -11,6 +11,6 @@ "schema_snapshots": [] }, "temp_test_table_relations_map": {}, - "duration_context_stack": [elementary.init_duration_context_dict('main')], + "duration_context_stack": {thread_id: [elementary.init_duration_context_dict('main')]}, }) %} {% endmacro %} From 1fac338924bd87a66d658eb3bff021829367311f Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Fri, 12 Apr 2024 17:18:27 +0300 Subject: [PATCH 21/23] remove code from tests --- integration_tests/tests/test_dbt_artifacts/test_artifacts.py | 1 - integration_tests/tests/test_information_schema_columns.py | 3 --- 2 files changed, 4 deletions(-) diff --git a/integration_tests/tests/test_dbt_artifacts/test_artifacts.py b/integration_tests/tests/test_dbt_artifacts/test_artifacts.py index 90c4d7921..bc6506201 100644 --- a/integration_tests/tests/test_dbt_artifacts/test_artifacts.py +++ b/integration_tests/tests/test_dbt_artifacts/test_artifacts.py @@ -27,7 +27,6 @@ def test_artifacts_caching(dbt_project: DbtProject): def test_artifacts_collection_in_multiple_row_batches(dbt_project: DbtProject): - # dbt_project.dbt_runner.run() existing_artifacts = dbt_project.read_table("dbt_models") dbt_project.dbt_runner.vars[ diff --git a/integration_tests/tests/test_information_schema_columns.py b/integration_tests/tests/test_information_schema_columns.py index 884e6fea7..b6afbc1bb 100644 --- a/integration_tests/tests/test_information_schema_columns.py +++ b/integration_tests/tests/test_information_schema_columns.py @@ -49,7 +49,6 @@ def test_information_schema_columns(dbt_project: DbtProject): sources = {"version": 2, "sources": [REGULAR_SOURCE]} with dbt_project.write_yaml(sources): - # dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success @@ -58,7 +57,6 @@ def test_information_schema_columns(dbt_project: DbtProject): def test_information_schema_non_existing_schema(dbt_project: DbtProject): sources = {"version": 2, "sources": [NON_EXISTING_SCHEMA_SOURCE]} with dbt_project.write_yaml(sources): - # dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success @@ -67,6 +65,5 @@ def test_information_schema_non_existing_schema(dbt_project: DbtProject): def test_information_schema_non_existing_database(dbt_project: DbtProject): sources = {"version": 2, "sources": [NON_EXISTING_DATABASE_SOURCE]} with dbt_project.write_yaml(sources): - # dbt_project.dbt_runner.run() success = dbt_project.dbt_runner.run(select="information_schema_columns") assert success From ca3b99d26b8211f5815ce6cac21df396a3cc890c Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Sun, 14 Apr 2024 00:17:32 +0300 Subject: [PATCH 22/23] fix init ? --- macros/edr/system/system_utils/logs.sql | 2 +- macros/edr/tests/on_run_start/init_elementary_graph.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/macros/edr/system/system_utils/logs.sql b/macros/edr/system/system_utils/logs.sql index a25930f05..6a39e1997 100644 --- a/macros/edr/system/system_utils/logs.sql +++ b/macros/edr/system/system_utils/logs.sql @@ -98,7 +98,7 @@ {% set thread_stack = global_duration_context_stack.get(thread_id) %} {% if not thread_stack %} - {% do global_duration_context_stack.get("elementary", {}).update({thread_id: []}) %} + {% do global_duration_context_stack.get("elementary", {}).update({thread_id: [elementary.init_duration_context_dict('main')]}) %} {% endif %} {{ return(global_duration_context_stack.get(thread_id)) }} {% endmacro %} diff --git a/macros/edr/tests/on_run_start/init_elementary_graph.sql b/macros/edr/tests/on_run_start/init_elementary_graph.sql index cc6423116..1ff785523 100644 --- a/macros/edr/tests/on_run_start/init_elementary_graph.sql +++ b/macros/edr/tests/on_run_start/init_elementary_graph.sql @@ -11,6 +11,6 @@ "schema_snapshots": [] }, "temp_test_table_relations_map": {}, - "duration_context_stack": {thread_id: [elementary.init_duration_context_dict('main')]}, + "duration_context_stack": {}, }) %} {% endmacro %} From f344ed33b56261c79dabfe0da5219a220e3370ef Mon Sep 17 00:00:00 2001 From: Daniel Pollak Date: Sun, 14 Apr 2024 11:37:58 +0300 Subject: [PATCH 23/23] final --- .github/workflows/test-warehouse.yml | 9 +-------- integration_tests/tests/env.py | 17 ++--------------- macros/edr/system/system_utils/logs.sql | 2 +- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index 247368935..7efa8dfbd 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -119,14 +119,7 @@ jobs: - name: Test working-directory: "${{ env.TESTS_DIR }}/tests" - run: py.test -n8 -vvv --log-cli-level=DEBUG --target "${{ inputs.warehouse-type }}" --junit-xml=test-results.xml --html=detailed_report_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}.html --self-contained-html - - - name: upload dbt logs - if: always() - uses: actions/upload-artifact@v4 - with: - name: dbt-logs-${{ inputs.warehouse-type }}-${{ inputs.dbt-version }} - path: /tmp/dbt_worker*.log + run: py.test -n8 -vvv --target "${{ inputs.warehouse-type }}" --junit-xml=test-results.xml --html=detailed_report_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}.html --self-contained-html - name: Upload test results if: always() diff --git a/integration_tests/tests/env.py b/integration_tests/tests/env.py index 7750143e5..f60cda7ed 100644 --- a/integration_tests/tests/env.py +++ b/integration_tests/tests/env.py @@ -1,9 +1,5 @@ -import os - import dbt_project -PYTEST_XDIST_WORKER = os.environ.get("PYTEST_XDIST_WORKER", "") - def init(target: str, project_dir: str): tests_env = Environment(target, project_dir) @@ -19,14 +15,5 @@ def clear(self): self.dbt_runner.run_operation("elementary_tests.clear_env") def init(self): - self.dbt_runner.run(selector="init", capture_output=True) - command_args = ["run"] - command_args.extend(["-s", "elementary"]) - ss, output = self.dbt_runner._run_command( - command_args=command_args, - vars=None, - quiet=False, - capture_output=True, - ) - for log in output: - open(f"/tmp/dbt_worker_{PYTEST_XDIST_WORKER}.log", "a").write(log) + self.dbt_runner.run(selector="init") + self.dbt_runner.run(select="elementary") diff --git a/macros/edr/system/system_utils/logs.sql b/macros/edr/system/system_utils/logs.sql index 6a39e1997..767188aea 100644 --- a/macros/edr/system/system_utils/logs.sql +++ b/macros/edr/system/system_utils/logs.sql @@ -98,7 +98,7 @@ {% set thread_stack = global_duration_context_stack.get(thread_id) %} {% if not thread_stack %} - {% do global_duration_context_stack.get("elementary", {}).update({thread_id: [elementary.init_duration_context_dict('main')]}) %} + {% do global_duration_context_stack.update({thread_id: [elementary.init_duration_context_dict('main')]}) %} {% endif %} {{ return(global_duration_context_stack.get(thread_id)) }} {% endmacro %}