Skip to content

Commit a174c35

Browse files
Rename disable_samples -> skip_test_result_rows for macro-level optimization
Separates the macro-level DB optimization from the existing OSS Python-level disable_samples mask: - skip_test_result_rows (new, macro-level): pure DB optimization. Skips the test_result_rows table query, gates get_test_rows_sample, selects null/'' as result_rows. Affects ALL test types. Used by cloud only. - disable_samples (unchanged, Python-level): masks sample_data for dbt_test rows only. Used by OSS --disable-samples CLI flag for PII protection. Anomaly metrics are preserved. Co-Authored-By: mika@elementary-data.com <mika.kerman@gmail.com>
1 parent 3507c3a commit a174c35

5 files changed

Lines changed: 26 additions & 25 deletions

File tree

elementary/monitor/api/report/report.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def get_report_data(
7676
exclude_elementary_models: bool = False,
7777
project_name: Optional[str] = None,
7878
disable_samples: bool = False,
79+
skip_test_result_rows: bool = False,
7980
filter: SelectorFilterSchema = SelectorFilterSchema(),
8081
env: Optional[str] = None,
8182
warehouse_type: Optional[str] = None,
@@ -86,7 +87,7 @@ def get_report_data(
8687
days_back=days_back,
8788
invocations_per_test=test_runs_amount,
8889
disable_passed_test_metrics=disable_passed_test_metrics,
89-
disable_samples=disable_samples,
90+
skip_test_result_rows=skip_test_result_rows,
9091
)
9192
source_freshnesses_api = SourceFreshnessesAPI(
9293
dbt_runner=self.dbt_runner,

elementary/monitor/api/tests/tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +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,
49+
skip_test_result_rows: bool = False,
5050
):
5151
super().__init__(dbt_runner)
5252
self.tests_fetcher = TestsFetcher(dbt_runner=self.dbt_runner)
5353
self.test_results_db_rows = self._get_test_results_db_rows(
5454
days_back=days_back,
5555
invocations_per_test=invocations_per_test,
5656
disable_passed_test_metrics=disable_passed_test_metrics,
57-
disable_samples=disable_samples,
57+
skip_test_result_rows=skip_test_result_rows,
5858
)
5959

6060
def _get_test_results_db_rows(
6161
self,
6262
days_back: Optional[int] = 7,
6363
invocations_per_test: int = 720,
6464
disable_passed_test_metrics: bool = False,
65-
disable_samples: bool = False,
65+
skip_test_result_rows: bool = False,
6666
) -> List[TestResultDBRowSchema]:
6767
return self.tests_fetcher.get_all_test_results_db_rows(
6868
days_back=days_back,
6969
invocations_per_test=invocations_per_test,
7070
disable_passed_test_metrics=disable_passed_test_metrics,
71-
disable_samples=disable_samples,
71+
skip_test_result_rows=skip_test_result_rows,
7272
)
7373

7474
def get_test_results_summary(

elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% macro current_tests_run_results_query(days_back = none, invocation_id = none, disable_samples = false) %}
1+
{% macro current_tests_run_results_query(days_back = none, invocation_id = none, skip_test_result_rows = false) %}
22
with elementary_test_results as (
33
select * from {{ ref('elementary', 'elementary_test_results') }}
44
{% if days_back %}
@@ -79,7 +79,7 @@
7979
dbt_tests.short_name,
8080
elementary_test_results.test_alias,
8181
elementary_test_results.failures,
82-
{% if disable_samples %}null{% else %}elementary_test_results.result_rows{% endif %} as result_rows,
82+
{% if skip_test_result_rows %}null{% else %}elementary_test_results.result_rows{% endif %} as result_rows,
8383
dbt_tests.original_path,
8484
dbt_tests.meta,
8585
dbt_tests.description as test_description,

elementary/monitor/dbt_project/macros/get_test_results.sql

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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)) }}
1+
{%- macro get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = false) -%}
2+
{{ return(adapter.dispatch('get_test_results', 'elementary_cli')(days_back, invocations_per_test, disable_passed_test_metrics, skip_test_result_rows)) }}
33
{%- endmacro -%}
44

55
{#
66
Shared post-processing helper: filters tests by meta, attaches sample data.
77
Called by both default__ and fabric__ dispatches to avoid duplicating the
88
Jinja processing loop.
99
#}
10-
{%- macro _process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples = false) -%}
10+
{%- macro _process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, skip_test_result_rows = false) -%}
1111
{% set test_results = [] %}
1212
{% set tests = elementary.agate_to_dicts(test_results_agate) %}
1313

@@ -26,7 +26,7 @@
2626
{% set test_params = fromjson(test.test_params) %}
2727
{% set status = test.status | lower %}
2828

29-
{%- if not disable_samples and ((test_type == 'dbt_test' and status in ['fail', 'warn']) or (test_type != 'dbt_test' and status in elementary_tests_allowlist_status)) -%}
29+
{%- if not skip_test_result_rows and ((test_type == 'dbt_test' and status in ['fail', 'warn']) or (test_type != 'dbt_test' and status in elementary_tests_allowlist_status)) -%}
3030
{% set test_rows_sample = elementary_cli.get_test_rows_sample(test.result_rows, test_result_rows_agate.get(test.id)) %}
3131
{%- endif -%}
3232
{% else %}
@@ -40,11 +40,11 @@
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, disable_samples = false) -%}
43+
{%- macro default__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = 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 (
47-
{{ elementary_cli.current_tests_run_results_query(days_back=days_back, disable_samples=disable_samples) }}
47+
{{ elementary_cli.current_tests_run_results_query(days_back=days_back, skip_test_result_rows=skip_test_result_rows) }}
4848
),
4949

5050
ordered_test_results as (
@@ -111,7 +111,7 @@
111111
{% endset %}
112112

113113
{% set test_results_agate = elementary.run_query(test_results_agate_sql) %}
114-
{% if not disable_samples %}
114+
{% if not skip_test_result_rows %}
115115
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
116116
{% else %}
117117
{% set test_result_rows_agate = {} %}
@@ -120,10 +120,10 @@
120120
{% do elementary.fully_drop_relation(ordered_test_results_relation) %}
121121
{% endif %}
122122

123-
{% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %}
123+
{% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, skip_test_result_rows)) %}
124124
{%- endmacro -%}
125125

126-
{%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%}
126+
{%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = false) -%}
127127
{#
128128
T-SQL does not allow nested CTEs (WITH inside WITH).
129129
current_tests_run_results_query already starts with WITH, so we
@@ -136,7 +136,7 @@
136136

137137
{# Step 1 – materialise the base test-results query into a temp table #}
138138
{% set base_query %}
139-
{{ elementary_cli.current_tests_run_results_query(days_back=days_back, disable_samples=disable_samples) }}
139+
{{ elementary_cli.current_tests_run_results_query(days_back=days_back, skip_test_result_rows=skip_test_result_rows) }}
140140
{% endset %}
141141

142142
{% set elementary_database, elementary_schema = elementary.get_package_database_and_schema() %}
@@ -169,7 +169,7 @@
169169
{% endset %}
170170

171171
{% set test_results_agate = elementary.run_query(test_results_agate_sql) %}
172-
{% if not disable_samples %}
172+
{% if not skip_test_result_rows %}
173173
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
174174
{% else %}
175175
{% set test_result_rows_agate = {} %}
@@ -179,10 +179,10 @@
179179
{% do elementary.fully_drop_relation(base_relation) %}
180180
{% do elementary.fully_drop_relation(ordered_relation) %}
181181

182-
{% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %}
182+
{% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, skip_test_result_rows)) %}
183183
{%- endmacro -%}
184184

185-
{%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%}
185+
{%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = false) -%}
186186
{% do elementary.run_query('drop table if exists ordered_test_results') %}
187187
{% set create_table_query %}
188188
CREATE TABLE ordered_test_results (
@@ -270,7 +270,7 @@
270270
{{ elementary.edr_datediff(elementary.edr_cast_as_timestamp('etr.detected_at'), elementary.edr_current_timestamp(), 'day') }} AS days_diff,
271271
ROW_NUMBER() OVER (PARTITION BY elementary_unique_id ORDER BY etr.detected_at DESC) AS invocations_rank_index,
272272
etr.failures,
273-
{% if disable_samples %}''{% else %}etr.result_rows{% endif %} AS result_rows
273+
{% if skip_test_result_rows %}''{% else %}etr.result_rows{% endif %} AS result_rows
274274
FROM {{ ref('elementary', 'elementary_test_results') }} etr
275275
JOIN {{ ref('elementary', 'dbt_tests') }} dt ON etr.test_unique_id = dt.unique_id
276276
LEFT JOIN (
@@ -310,7 +310,7 @@
310310
{% endset %}
311311

312312
{% set test_results_agate = elementary.run_query(test_results_agate_sql) %}
313-
{% if not disable_samples %}
313+
{% if not skip_test_result_rows %}
314314
{% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %}
315315
{% else %}
316316
{% set test_result_rows_agate = {} %}
@@ -319,5 +319,5 @@
319319
{% do elementary.fully_drop_relation(ordered_test_results_relation) %}
320320
{% endif %}
321321

322-
{% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %}
322+
{% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, skip_test_result_rows)) %}
323323
{%- endmacro -%}

elementary/monitor/fetchers/tests/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +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,
25+
skip_test_result_rows: bool = False,
2626
) -> List[TestResultDBRowSchema]:
2727
run_operation_response = self.dbt_runner.run_operation(
2828
macro_name="elementary_cli.get_test_results",
2929
macro_args=dict(
3030
days_back=days_back,
3131
invocations_per_test=invocations_per_test,
3232
disable_passed_test_metrics=disable_passed_test_metrics,
33-
disable_samples=disable_samples,
33+
skip_test_result_rows=skip_test_result_rows,
3434
),
3535
)
3636
test_results = (

0 commit comments

Comments
 (0)