|
5 | 5 | {% set raw_test_alerts_agate = run_query(elementary_cli.populate_test_alerts_query(days_back)) %} |
6 | 6 | {% set raw_test_alerts = elementary.agate_to_dicts(raw_test_alerts_agate) %} |
7 | 7 | {% for raw_test_alert in raw_test_alerts %} |
8 | | - {# ClickHouse may return original column names instead of aliases, so we handle both cases #} |
9 | | - {% set test_type = raw_test_alert.get('alert_type', raw_test_alert.get('test_type')) %} |
10 | | - {% set status = raw_test_alert.status | lower %} |
11 | | - |
12 | | - {# ClickHouse may return original column names instead of aliases, so we handle both cases #} |
| 8 | + {# ClickHouse may return original column names instead of aliases, so we use .get() for all field accesses #} |
13 | 9 | {% set alert_id = raw_test_alert.get('alert_id', raw_test_alert.get('id')) %} |
| 10 | + {% set test_type = raw_test_alert.get('alert_type', raw_test_alert.get('test_type')) %} |
| 11 | + {% set status = raw_test_alert.get('status', '') | lower %} |
| 12 | + {% set sub_type = raw_test_alert.get('sub_type', raw_test_alert.get('test_sub_type')) %} |
| 13 | + {% set alert_description = raw_test_alert.get('alert_description', raw_test_alert.get('test_results_description')) %} |
| 14 | + {% set alert_results_query = raw_test_alert.get('alert_results_query', raw_test_alert.get('test_results_query')) %} |
| 15 | + {% set test_description = raw_test_alert.get('test_description', raw_test_alert.get('description')) %} |
| 16 | + {% set test_meta = raw_test_alert.get('test_meta', raw_test_alert.get('meta')) %} |
| 17 | + {% set model_meta = raw_test_alert.get('model_meta') %} |
| 18 | + {% set result_rows = raw_test_alert.get('result_rows') %} |
14 | 19 |
|
15 | 20 | {% set test_rows_sample = none %} |
16 | 21 | {%- if not disable_samples and ((test_type == 'dbt_test' and status in ['fail', 'warn']) or (test_type != 'dbt_test' and status != 'error')) -%} |
17 | | - {% set test_rows_sample = elementary_cli.get_test_rows_sample(raw_test_alert.result_rows, test_result_rows_agate.get(alert_id)) %} |
| 22 | + {% set test_rows_sample = elementary_cli.get_test_rows_sample(result_rows, test_result_rows_agate.get(alert_id)) %} |
18 | 23 | {%- endif -%} |
19 | | - {% set sub_type = raw_test_alert.get('sub_type', raw_test_alert.get('test_sub_type')) %} |
20 | | - {% set alert_description = raw_test_alert.get('alert_description', raw_test_alert.get('test_results_description')) %} |
21 | | - {% set alert_results_query = raw_test_alert.get('alert_results_query', raw_test_alert.get('test_results_query')) %} |
22 | 24 |
|
23 | 25 | {% set test_alert_data = { |
24 | 26 | 'id': alert_id, |
25 | | - 'alert_class_id': raw_test_alert.alert_class_id, |
26 | | - 'model_unique_id': raw_test_alert.model_unique_id, |
27 | | - 'test_unique_id': raw_test_alert.test_unique_id, |
28 | | - 'detected_at': raw_test_alert.detected_at, |
29 | | - 'database_name': raw_test_alert.database_name, |
30 | | - 'schema_name': raw_test_alert.schema_name, |
31 | | - 'table_name': raw_test_alert.table_name, |
32 | | - 'column_name': raw_test_alert.column_name, |
| 27 | + 'alert_class_id': raw_test_alert.get('alert_class_id'), |
| 28 | + 'model_unique_id': raw_test_alert.get('model_unique_id'), |
| 29 | + 'test_unique_id': raw_test_alert.get('test_unique_id'), |
| 30 | + 'detected_at': raw_test_alert.get('detected_at'), |
| 31 | + 'database_name': raw_test_alert.get('database_name'), |
| 32 | + 'schema_name': raw_test_alert.get('schema_name'), |
| 33 | + 'table_name': raw_test_alert.get('table_name'), |
| 34 | + 'column_name': raw_test_alert.get('column_name'), |
33 | 35 | 'test_type': test_type, |
34 | 36 | 'test_sub_type': sub_type, |
35 | | - 'test_description': raw_test_alert.test_description, |
| 37 | + 'test_description': test_description, |
36 | 38 | 'test_results_description': alert_description, |
37 | | - 'owners': raw_test_alert.owners, |
38 | | - 'tags': raw_test_alert.tags, |
| 39 | + 'owners': raw_test_alert.get('owners'), |
| 40 | + 'tags': raw_test_alert.get('tags'), |
39 | 41 | 'test_results_query': alert_results_query, |
40 | 42 | 'test_rows_sample': test_rows_sample, |
41 | | - 'other': raw_test_alert.other, |
42 | | - 'test_name': raw_test_alert.test_name, |
43 | | - 'test_short_name': raw_test_alert.test_short_name, |
44 | | - 'test_params': raw_test_alert.test_params, |
45 | | - 'severity': raw_test_alert.severity, |
46 | | - 'test_meta': raw_test_alert.test_meta, |
47 | | - 'model_meta': raw_test_alert.model_meta, |
| 43 | + 'other': raw_test_alert.get('other'), |
| 44 | + 'test_name': raw_test_alert.get('test_name'), |
| 45 | + 'test_short_name': raw_test_alert.get('test_short_name'), |
| 46 | + 'test_params': raw_test_alert.get('test_params'), |
| 47 | + 'severity': raw_test_alert.get('severity'), |
| 48 | + 'test_meta': test_meta, |
| 49 | + 'model_meta': model_meta, |
48 | 50 | 'status': status, |
49 | | - 'elementary_unique_id': raw_test_alert.elementary_unique_id, |
50 | | - 'job_id': raw_test_alert.job_id, |
51 | | - 'job_name': raw_test_alert.job_name, |
52 | | - 'job_run_id': raw_test_alert.job_run_id, |
53 | | - 'job_url': raw_test_alert.job_url, |
54 | | - 'job_run_url': raw_test_alert.job_run_url, |
55 | | - 'orchestrator': raw_test_alert.orchestrator |
| 51 | + 'elementary_unique_id': raw_test_alert.get('elementary_unique_id'), |
| 52 | + 'job_id': raw_test_alert.get('job_id'), |
| 53 | + 'job_name': raw_test_alert.get('job_name'), |
| 54 | + 'job_run_id': raw_test_alert.get('job_run_id'), |
| 55 | + 'job_url': raw_test_alert.get('job_url'), |
| 56 | + 'job_run_url': raw_test_alert.get('job_run_url'), |
| 57 | + 'orchestrator': raw_test_alert.get('orchestrator') |
56 | 58 | } |
57 | 59 | %} |
58 | 60 |
|
59 | 61 | {% set test_alert = elementary_cli.generate_alert_object( |
60 | 62 | alert_id, |
61 | | - raw_test_alert.alert_class_id, |
| 63 | + raw_test_alert.get('alert_class_id'), |
62 | 64 | 'test', |
63 | | - raw_test_alert.detected_at, |
64 | | - raw_test_alert.created_at, |
| 65 | + raw_test_alert.get('detected_at'), |
| 66 | + raw_test_alert.get('created_at'), |
65 | 67 | test_alert_data, |
66 | 68 | ) %} |
67 | 69 | {% do test_alerts.append(test_alert) %} |
|
0 commit comments