Skip to content

Commit b1dbb25

Browse files
APP-1123: add disable_samples to skip test_result_rows query
Thread a new disable_samples parameter from ReportAPI.get_report_data through TestsAPI -> TestsFetcher -> the get_test_results dbt macro. When disable_samples=true, the macro skips the get_result_rows_agate query against test_result_rows entirely instead of relying on the caller to clear sample_data after the SQL has already run. This is consumed by elementary-internal's cloud report generation, where results_sample has zero consumers (522 GB / 249.6M rows scanned per cycle for nothing). The default remains false so OSS users and other callers are unaffected. Co-Authored-By: mika@elementary-data.com <mika.kerman@gmail.com>
1 parent fc1599e commit b1dbb25

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

elementary/monitor/api/report/report.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def get_report_data(
8686
days_back=days_back,
8787
invocations_per_test=test_runs_amount,
8888
disable_passed_test_metrics=disable_passed_test_metrics,
89+
disable_samples=disable_samples,
8990
)
9091
source_freshnesses_api = SourceFreshnessesAPI(
9192
dbt_runner=self.dbt_runner,

elementary/monitor/api/tests/tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,29 @@ def __init__(
4646
days_back: int = 7,
4747
invocations_per_test: int = 720,
4848
disable_passed_test_metrics: bool = False,
49+
disable_samples: bool = False,
4950
):
5051
super().__init__(dbt_runner)
5152
self.tests_fetcher = TestsFetcher(dbt_runner=self.dbt_runner)
5253
self.test_results_db_rows = self._get_test_results_db_rows(
5354
days_back=days_back,
5455
invocations_per_test=invocations_per_test,
5556
disable_passed_test_metrics=disable_passed_test_metrics,
57+
disable_samples=disable_samples,
5658
)
5759

5860
def _get_test_results_db_rows(
5961
self,
6062
days_back: Optional[int] = 7,
6163
invocations_per_test: int = 720,
6264
disable_passed_test_metrics: bool = False,
65+
disable_samples: bool = False,
6366
) -> List[TestResultDBRowSchema]:
6467
return self.tests_fetcher.get_all_test_results_db_rows(
6568
days_back=days_back,
6669
invocations_per_test=invocations_per_test,
6770
disable_passed_test_metrics=disable_passed_test_metrics,
71+
disable_samples=disable_samples,
6872
)
6973

7074
def get_test_results_summary(

elementary/monitor/dbt_project/macros/get_test_results.sql

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{%- macro get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false) -%}
2-
{{ return(adapter.dispatch('get_test_results', 'elementary_cli')(days_back, invocations_per_test, disable_passed_test_metrics)) }}
1+
{%- macro get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%}
2+
{{ return(adapter.dispatch('get_test_results', 'elementary_cli')(days_back, invocations_per_test, disable_passed_test_metrics, disable_samples)) }}
33
{%- endmacro -%}
44

55
{#
@@ -40,7 +40,7 @@
4040
{% do return(test_results) %}
4141
{%- endmacro -%}
4242

43-
{%- macro default__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false) -%}
43+
{%- macro default__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%}
4444
{% set elementary_tests_allowlist_status = ['fail', 'warn'] if disable_passed_test_metrics else ['fail', 'warn', 'pass'] %}
4545
{% set select_test_results %}
4646
with test_results as (
@@ -111,15 +111,19 @@
111111
{% endset %}
112112

113113
{% set test_results_agate = elementary.run_query(test_results_agate_sql) %}
114-
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
114+
{% if not disable_samples %}
115+
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
116+
{% else %}
117+
{% set test_result_rows_agate = {} %}
118+
{% endif %}
115119
{% if not elementary.has_temp_table_support() %}
116120
{% do elementary.fully_drop_relation(ordered_test_results_relation) %}
117121
{% endif %}
118122

119123
{% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status)) %}
120124
{%- endmacro -%}
121125

122-
{%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false) -%}
126+
{%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%}
123127
{#
124128
T-SQL does not allow nested CTEs (WITH inside WITH).
125129
current_tests_run_results_query already starts with WITH, so we
@@ -165,7 +169,11 @@
165169
{% endset %}
166170

167171
{% set test_results_agate = elementary.run_query(test_results_agate_sql) %}
168-
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
172+
{% if not disable_samples %}
173+
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
174+
{% else %}
175+
{% set test_result_rows_agate = {} %}
176+
{% endif %}
169177

170178
{# Clean up intermediate tables #}
171179
{% do elementary.fully_drop_relation(base_relation) %}
@@ -174,7 +182,7 @@
174182
{% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status)) %}
175183
{%- endmacro -%}
176184

177-
{%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false) -%}
185+
{%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%}
178186
{% do elementary.run_query('drop table if exists ordered_test_results') %}
179187
{% set create_table_query %}
180188
CREATE TABLE ordered_test_results (
@@ -302,7 +310,11 @@
302310
{% endset %}
303311

304312
{% set test_results_agate = elementary.run_query(test_results_agate_sql) %}
305-
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
313+
{% if not disable_samples %}
314+
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
315+
{% else %}
316+
{% set test_result_rows_agate = {} %}
317+
{% endif %}
306318
{% if not elementary.has_temp_table_support() %}
307319
{% do elementary.fully_drop_relation(ordered_test_results_relation) %}
308320
{% endif %}

elementary/monitor/fetchers/tests/tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ def get_all_test_results_db_rows(
2222
days_back: Optional[int] = 7,
2323
invocations_per_test: int = 720,
2424
disable_passed_test_metrics: bool = False,
25+
disable_samples: bool = False,
2526
) -> List[TestResultDBRowSchema]:
2627
run_operation_response = self.dbt_runner.run_operation(
2728
macro_name="elementary_cli.get_test_results",
2829
macro_args=dict(
2930
days_back=days_back,
3031
invocations_per_test=invocations_per_test,
3132
disable_passed_test_metrics=disable_passed_test_metrics,
33+
disable_samples=disable_samples,
3234
),
3335
)
3436
test_results = (

0 commit comments

Comments
 (0)