dataops-testgen 2.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dataops_testgen-2.2.0.dist-info/LICENSE +203 -0
- dataops_testgen-2.2.0.dist-info/METADATA +287 -0
- dataops_testgen-2.2.0.dist-info/NOTICE +5 -0
- dataops_testgen-2.2.0.dist-info/RECORD +270 -0
- dataops_testgen-2.2.0.dist-info/WHEEL +5 -0
- dataops_testgen-2.2.0.dist-info/entry_points.txt +2 -0
- dataops_testgen-2.2.0.dist-info/top_level.txt +1 -0
- testgen/__init__.py +0 -0
- testgen/__main__.py +770 -0
- testgen/commands/__init__.py +0 -0
- testgen/commands/queries/__init__.py +0 -0
- testgen/commands/queries/execute_cat_tests_query.py +95 -0
- testgen/commands/queries/execute_tests_query.py +160 -0
- testgen/commands/queries/generate_tests_query.py +94 -0
- testgen/commands/queries/profiling_query.py +366 -0
- testgen/commands/queries/test_parameter_validation_query.py +88 -0
- testgen/commands/run_execute_cat_tests.py +162 -0
- testgen/commands/run_execute_tests.py +168 -0
- testgen/commands/run_generate_tests.py +107 -0
- testgen/commands/run_get_entities.py +122 -0
- testgen/commands/run_launch_db_config.py +84 -0
- testgen/commands/run_observability_exporter.py +330 -0
- testgen/commands/run_profiling_bridge.py +495 -0
- testgen/commands/run_quick_start.py +168 -0
- testgen/commands/run_setup_profiling_tools.py +96 -0
- testgen/commands/run_test_definition.py +146 -0
- testgen/commands/run_test_parameter_validation.py +135 -0
- testgen/commands/run_upgrade_db_config.py +156 -0
- testgen/common/__init__.py +8 -0
- testgen/common/clean_sql.py +53 -0
- testgen/common/credentials.py +25 -0
- testgen/common/database/__init__.py +0 -0
- testgen/common/database/database_service.py +629 -0
- testgen/common/database/flavor/__init__.py +0 -0
- testgen/common/database/flavor/flavor_service.py +75 -0
- testgen/common/database/flavor/mssql_flavor_service.py +34 -0
- testgen/common/database/flavor/postgresql_flavor_service.py +5 -0
- testgen/common/database/flavor/redshift_flavor_service.py +22 -0
- testgen/common/database/flavor/snowflake_flavor_service.py +69 -0
- testgen/common/database/flavor/trino_flavor_service.py +21 -0
- testgen/common/date_service.py +68 -0
- testgen/common/display_service.py +85 -0
- testgen/common/docker_service.py +76 -0
- testgen/common/encrypt.py +55 -0
- testgen/common/get_pipeline_parms.py +57 -0
- testgen/common/logs.py +79 -0
- testgen/common/process_service.py +62 -0
- testgen/common/read_file.py +69 -0
- testgen/settings.py +440 -0
- testgen/template/dbsetup/010_create_base_schema.sql +2 -0
- testgen/template/dbsetup/020_create_standard_functions_sprocs.sql +179 -0
- testgen/template/dbsetup/030_initialize_new_schema_structure.sql +735 -0
- testgen/template/dbsetup/040_populate_new_schema_project.sql +59 -0
- testgen/template/dbsetup/050_populate_new_schema_metadata.sql +1517 -0
- testgen/template/dbsetup/060_create_standard_views.sql +248 -0
- testgen/template/dbsetup/070_create_default_users.sql +17 -0
- testgen/template/dbsetup/075_grant_role_rights.sql +43 -0
- testgen/template/dbsetup/080_set_current_revision.sql +5 -0
- testgen/template/dbupgrade/0100_incremental_upgrade.sql +5 -0
- testgen/template/dbupgrade/0101_incremental_upgrade.sql +15 -0
- testgen/template/dbupgrade/0102_incremental_upgrade.sql +4 -0
- testgen/template/dbupgrade/0103_incremental_upgrade.sql +22 -0
- testgen/template/dbupgrade/0104_incremental_upgrade.sql +44 -0
- testgen/template/dbupgrade/0105_incremental_upgrade.sql +1 -0
- testgen/template/dbupgrade/0106_incremental_upgrade.sql +5 -0
- testgen/template/dbupgrade/0107_incremental_upgrade.sql +3 -0
- testgen/template/dbupgrade_helpers/get_tg_revision.sql +2 -0
- testgen/template/exec_cat_tests/ex_cat_build_agg_table_tests.sql +116 -0
- testgen/template/exec_cat_tests/ex_cat_get_distinct_tables.sql +11 -0
- testgen/template/exec_cat_tests/ex_cat_results_parse.sql +69 -0
- testgen/template/exec_cat_tests/ex_cat_retrieve_agg_test_parms.sql +6 -0
- testgen/template/exec_cat_tests/ex_cat_test_query.sql +8 -0
- testgen/template/execution/ex_finalize_test_run_results.sql +37 -0
- testgen/template/execution/ex_get_tests_non_cat.sql +47 -0
- testgen/template/execution/ex_update_test_record_in_testrun_table.sql +27 -0
- testgen/template/execution/ex_write_test_record_to_testrun_table.sql +6 -0
- testgen/template/flavors/generic/exec_query_tests/ex_aggregate_match_no_drops_generic.sql +48 -0
- testgen/template/flavors/generic/exec_query_tests/ex_aggregate_match_num_incr_generic.sql +34 -0
- testgen/template/flavors/generic/exec_query_tests/ex_aggregate_match_percent_above_generic.sql +49 -0
- testgen/template/flavors/generic/exec_query_tests/ex_aggregate_match_percent_within_generic.sql +49 -0
- testgen/template/flavors/generic/exec_query_tests/ex_aggregate_match_same_generic.sql +49 -0
- testgen/template/flavors/generic/exec_query_tests/ex_custom_query_generic.sql +39 -0
- testgen/template/flavors/generic/exec_query_tests/ex_data_match_2way_generic.sql +58 -0
- testgen/template/flavors/generic/exec_query_tests/ex_data_match_generic.sql +44 -0
- testgen/template/flavors/generic/exec_query_tests/ex_prior_match_generic.sql +37 -0
- testgen/template/flavors/generic/exec_query_tests/ex_relative_entropy_generic.sql +53 -0
- testgen/template/flavors/generic/exec_query_tests/ex_window_match_no_drops_generic.sql +46 -0
- testgen/template/flavors/generic/exec_query_tests/ex_window_match_same_generic.sql +59 -0
- testgen/template/flavors/generic/profiling/contingency_counts.sql +3 -0
- testgen/template/flavors/generic/validate_tests/ex_get_project_column_list_generic.sql +3 -0
- testgen/template/flavors/mssql/exec_query_tests/ex_relative_entropy_mssql.sql +53 -0
- testgen/template/flavors/mssql/profiling/project_ddf_query_mssql.sql +35 -0
- testgen/template/flavors/mssql/profiling/project_profiling_query_mssql.yaml +246 -0
- testgen/template/flavors/mssql/profiling/project_secondary_profiling_query_mssql.sql +36 -0
- testgen/template/flavors/mssql/setup_profiling_tools/00_drop_existing_functions_mssql.sql +8 -0
- testgen/template/flavors/mssql/setup_profiling_tools/01_create_functions_mssql.sql +12 -0
- testgen/template/flavors/mssql/setup_profiling_tools/02_create_functions_mssql.sql +54 -0
- testgen/template/flavors/mssql/setup_profiling_tools/create_qc_schema_mssql.sql +4 -0
- testgen/template/flavors/mssql/setup_profiling_tools/grant_execute_privileges_mssql.sql +1 -0
- testgen/template/flavors/postgresql/exec_query_tests/ex_window_match_no_drops_postgresql.sql +46 -0
- testgen/template/flavors/postgresql/exec_query_tests/ex_window_match_same_postgresql.sql +59 -0
- testgen/template/flavors/postgresql/profiling/project_ddf_query_postgresql.sql +42 -0
- testgen/template/flavors/postgresql/profiling/project_profiling_query_postgresql.yaml +225 -0
- testgen/template/flavors/postgresql/profiling/project_secondary_profiling_query_postgresql.sql +28 -0
- testgen/template/flavors/postgresql/setup_profiling_tools/create_functions_postgresql.sql +157 -0
- testgen/template/flavors/postgresql/setup_profiling_tools/create_qc_schema_postgresql.sql +1 -0
- testgen/template/flavors/postgresql/setup_profiling_tools/grant_execute_privileges_postgresql.sql +2 -0
- testgen/template/flavors/redshift/profiling/project_ddf_query_redshift.sql +38 -0
- testgen/template/flavors/redshift/profiling/project_profiling_query_redshift.yaml +221 -0
- testgen/template/flavors/redshift/profiling/project_secondary_profiling_query_redshift.sql +29 -0
- testgen/template/flavors/redshift/setup_profiling_tools/create_functions_redshift.sql +115 -0
- testgen/template/flavors/redshift/setup_profiling_tools/create_qc_schema_redshift.sql +1 -0
- testgen/template/flavors/redshift/setup_profiling_tools/grant_execute_privileges_redshift.sql +2 -0
- testgen/template/flavors/snowflake/profiling/project_ddf_query_snowflake.sql +38 -0
- testgen/template/flavors/snowflake/profiling/project_profiling_query_snowflake.yaml +220 -0
- testgen/template/flavors/snowflake/profiling/project_secondary_profiling_query_snowflake.sql +29 -0
- testgen/template/flavors/snowflake/setup_profiling_tools/create_functions_snowflake.sql +69 -0
- testgen/template/flavors/snowflake/setup_profiling_tools/create_qc_schema_snowflake.sql +1 -0
- testgen/template/flavors/snowflake/setup_profiling_tools/grant_execute_privileges_snowflake.sql +6 -0
- testgen/template/flavors/trino/profiling/project_profiling_query_trino.yaml +219 -0
- testgen/template/flavors/trino/setup_profiling_tools/create_functions_trino.sql +92 -0
- testgen/template/flavors/trino/setup_profiling_tools/create_qc_schema_trino.sql +1 -0
- testgen/template/gen_funny_cat_tests/gen_test_constant.sql +104 -0
- testgen/template/gen_funny_cat_tests/gen_test_distinct_value_ct.sql +98 -0
- testgen/template/gen_funny_cat_tests/gen_test_row_ct.sql +57 -0
- testgen/template/gen_funny_cat_tests/gen_test_row_ct_pct.sql +59 -0
- testgen/template/generation/gen_delete_old_tests.sql +5 -0
- testgen/template/generation/gen_insert_test_suite.sql +5 -0
- testgen/template/generation/gen_retrieve_or_insert_test_suite.sql +58 -0
- testgen/template/generation/gen_standard_test_type_list.sql +13 -0
- testgen/template/generation/gen_standard_tests.sql +48 -0
- testgen/template/get_entities/get_connection.sql +21 -0
- testgen/template/get_entities/get_connections_list.sql +9 -0
- testgen/template/get_entities/get_latest.sql +4 -0
- testgen/template/get_entities/get_profile.sql +12 -0
- testgen/template/get_entities/get_profile_info.sql +17 -0
- testgen/template/get_entities/get_profile_list.sql +17 -0
- testgen/template/get_entities/get_profile_screen.sql +275 -0
- testgen/template/get_entities/get_project_list.sql +6 -0
- testgen/template/get_entities/get_table_group_list.sql +10 -0
- testgen/template/get_entities/get_test_generation_list.sql +18 -0
- testgen/template/get_entities/get_test_info.sql +41 -0
- testgen/template/get_entities/get_test_results_for_run_cli.sql +16 -0
- testgen/template/get_entities/get_test_run_list.sql +24 -0
- testgen/template/get_entities/get_test_suite.sql +13 -0
- testgen/template/get_entities/get_test_suite_list.sql +18 -0
- testgen/template/get_entities/list_test_types.sql +4 -0
- testgen/template/observability/get_event_data.sql +23 -0
- testgen/template/observability/get_test_results.sql +41 -0
- testgen/template/observability/update_test_results_exported_to_observability.sql +12 -0
- testgen/template/parms/parms_profiling.sql +34 -0
- testgen/template/parms/parms_test_execution.sql +13 -0
- testgen/template/parms/parms_test_gen.sql +23 -0
- testgen/template/profiling/contingency_columns.sql +7 -0
- testgen/template/profiling/datatype_suggestions.sql +56 -0
- testgen/template/profiling/functional_datatype.sql +523 -0
- testgen/template/profiling/functional_tabletype_stage.sql +48 -0
- testgen/template/profiling/functional_tabletype_update.sql +8 -0
- testgen/template/profiling/pii_flag.sql +133 -0
- testgen/template/profiling/profile_anomalies_screen_column.sql +22 -0
- testgen/template/profiling/profile_anomalies_screen_multi_column.sql +58 -0
- testgen/template/profiling/profile_anomalies_screen_table.sql +22 -0
- testgen/template/profiling/profile_anomalies_screen_table_dates.sql +30 -0
- testgen/template/profiling/profile_anomalies_screen_variants.sql +40 -0
- testgen/template/profiling/profile_anomaly_types_get.sql +3 -0
- testgen/template/profiling/project_get_table_sample_count.sql +22 -0
- testgen/template/profiling/project_profile_run_record_insert.sql +8 -0
- testgen/template/profiling/project_profile_run_record_update.sql +5 -0
- testgen/template/profiling/project_profile_run_record_update_status.sql +5 -0
- testgen/template/profiling/project_update_profile_results_to_estimates.sql +32 -0
- testgen/template/profiling/refresh_anomalies.sql +33 -0
- testgen/template/profiling/refresh_data_chars_from_profiling.sql +156 -0
- testgen/template/profiling/secondary_profiling_columns.sql +12 -0
- testgen/template/profiling/secondary_profiling_delete.sql +4 -0
- testgen/template/profiling/secondary_profiling_update.sql +18 -0
- testgen/template/quick_start/populate_target_data.sql +1077 -0
- testgen/template/quick_start/recreate_target_data_schema.sql +167 -0
- testgen/template/quick_start/update_target_data.sql +100 -0
- testgen/template/updates/create_tmp_test_definition.sql +19 -0
- testgen/template/updates/get_test_def_parms.sql +38 -0
- testgen/template/updates/populate_stg_test_definitions.sql +184 -0
- testgen/template/validate_tests/ex_disable_tests_test_definitions.sql +5 -0
- testgen/template/validate_tests/ex_flag_tests_test_definitions.sql +64 -0
- testgen/template/validate_tests/ex_get_project_column_list_generic.sql +3 -0
- testgen/template/validate_tests/ex_get_test_column_list_tg.sql +65 -0
- testgen/template/validate_tests/ex_write_test_val_errors.sql +22 -0
- testgen/ui/__init__.py +0 -0
- testgen/ui/app.py +98 -0
- testgen/ui/assets/dk_logo.svg +46 -0
- testgen/ui/assets/question_mark.png +0 -0
- testgen/ui/assets/scripts.js +68 -0
- testgen/ui/assets/style.css +140 -0
- testgen/ui/bootstrap.py +109 -0
- testgen/ui/components/__init__.py +0 -0
- testgen/ui/components/frontend/css/KFOlCnqEu92Fr1MmEU9fBBc4.woff2 +0 -0
- testgen/ui/components/frontend/css/KFOlCnqEu92Fr1MmEU9fChc4EsA.woff2 +0 -0
- testgen/ui/components/frontend/css/KFOmCnqEu92Fr1Mu4mxK.woff2 +0 -0
- testgen/ui/components/frontend/css/KFOmCnqEu92Fr1Mu7GxKOzY.woff2 +0 -0
- testgen/ui/components/frontend/css/material-symbols-rounded.css +24 -0
- testgen/ui/components/frontend/css/material-symbols-rounded.woff2 +0 -0
- testgen/ui/components/frontend/css/roboto-font-faces.css +35 -0
- testgen/ui/components/frontend/css/shared.css +36 -0
- testgen/ui/components/frontend/img/dk_logo.svg +46 -0
- testgen/ui/components/frontend/index.html +17 -0
- testgen/ui/components/frontend/js/components/breadcrumbs.js +86 -0
- testgen/ui/components/frontend/js/components/button.js +66 -0
- testgen/ui/components/frontend/js/components/location.js +62 -0
- testgen/ui/components/frontend/js/components/select.js +75 -0
- testgen/ui/components/frontend/js/components/sidebar.js +358 -0
- testgen/ui/components/frontend/js/main.js +99 -0
- testgen/ui/components/frontend/js/streamlit.js +19 -0
- testgen/ui/components/frontend/js/van.min.js +1 -0
- testgen/ui/components/utils/__init__.py +0 -0
- testgen/ui/components/utils/callbacks.py +51 -0
- testgen/ui/components/utils/component.py +13 -0
- testgen/ui/components/widgets/__init__.py +6 -0
- testgen/ui/components/widgets/breadcrumbs.py +32 -0
- testgen/ui/components/widgets/location.py +65 -0
- testgen/ui/components/widgets/modal.py +97 -0
- testgen/ui/components/widgets/sidebar.py +69 -0
- testgen/ui/navigation/__init__.py +0 -0
- testgen/ui/navigation/menu.py +42 -0
- testgen/ui/navigation/page.py +20 -0
- testgen/ui/navigation/router.py +63 -0
- testgen/ui/queries/__init__.py +0 -0
- testgen/ui/queries/authentication_queries.py +47 -0
- testgen/ui/queries/connection_queries.py +121 -0
- testgen/ui/queries/profiling_queries.py +148 -0
- testgen/ui/queries/project_queries.py +9 -0
- testgen/ui/queries/table_group_queries.py +186 -0
- testgen/ui/queries/test_definition_queries.py +270 -0
- testgen/ui/queries/test_run_queries.py +32 -0
- testgen/ui/queries/test_suite_queries.py +145 -0
- testgen/ui/scripts/__init__.py +0 -0
- testgen/ui/scripts/patch_streamlit.py +111 -0
- testgen/ui/services/__init__.py +0 -0
- testgen/ui/services/authentication_service.py +119 -0
- testgen/ui/services/connection_service.py +220 -0
- testgen/ui/services/database_service.py +282 -0
- testgen/ui/services/form_service.py +1008 -0
- testgen/ui/services/javascript_service.py +44 -0
- testgen/ui/services/query_service.py +316 -0
- testgen/ui/services/string_service.py +12 -0
- testgen/ui/services/table_group_service.py +130 -0
- testgen/ui/services/test_definition_service.py +117 -0
- testgen/ui/services/test_run_service.py +13 -0
- testgen/ui/services/test_suite_service.py +76 -0
- testgen/ui/services/toolbar_service.py +77 -0
- testgen/ui/session.py +46 -0
- testgen/ui/views/__init__.py +0 -0
- testgen/ui/views/app_log_modal.py +92 -0
- testgen/ui/views/connections.py +72 -0
- testgen/ui/views/connections_base.py +367 -0
- testgen/ui/views/login.py +40 -0
- testgen/ui/views/not_found.py +16 -0
- testgen/ui/views/overview.py +34 -0
- testgen/ui/views/profiling_anomalies.py +501 -0
- testgen/ui/views/profiling_details.py +335 -0
- testgen/ui/views/profiling_modal.py +40 -0
- testgen/ui/views/profiling_results.py +206 -0
- testgen/ui/views/profiling_summary.py +177 -0
- testgen/ui/views/project_settings.py +74 -0
- testgen/ui/views/table_groups.py +530 -0
- testgen/ui/views/test_definitions.py +1020 -0
- testgen/ui/views/test_results.py +908 -0
- testgen/ui/views/test_runs.py +195 -0
- testgen/ui/views/test_suites.py +545 -0
- testgen/utils/__init__.py +0 -0
- testgen/utils/plugins.py +17 -0
- testgen/utils/singleton.py +14 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
import sys
|
|
4
|
+
import uuid
|
|
5
|
+
from collections import namedtuple
|
|
6
|
+
from urllib.parse import urlparse
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
from requests_extensions import get_session
|
|
10
|
+
|
|
11
|
+
from testgen import settings
|
|
12
|
+
from testgen.common import date_service, display_service, read_template_sql_file
|
|
13
|
+
from testgen.common.database.database_service import ExecuteDBQuery, RetrieveDBResultsToDictList
|
|
14
|
+
|
|
15
|
+
LOG = logging.getLogger("testgen")
|
|
16
|
+
|
|
17
|
+
DEFAULT_COMPONENT_TYPE = "dataset"
|
|
18
|
+
|
|
19
|
+
PAYLOAD_MAX_SIZE = 100000
|
|
20
|
+
PAYLOAD_MAX_ITEMS = 500
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def calculate_chunk_size(test_outcomes):
|
|
24
|
+
size = len(json.dumps(test_outcomes))
|
|
25
|
+
split = size / PAYLOAD_MAX_SIZE * 2
|
|
26
|
+
chunk_size = int(round(len(test_outcomes) / split))
|
|
27
|
+
return min(PAYLOAD_MAX_ITEMS, chunk_size)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def post_event(event_type, payload, api_url, api_key, test_outcomes, is_test=False):
|
|
31
|
+
qty_of_events = len(test_outcomes)
|
|
32
|
+
if not is_test and qty_of_events == 0:
|
|
33
|
+
display_service.echo("Nothing to be sent to Observability")
|
|
34
|
+
return qty_of_events
|
|
35
|
+
|
|
36
|
+
def chunkify(collection, chunk_size):
|
|
37
|
+
return [collection[i : i + chunk_size] for i in range(0, len(collection), chunk_size)]
|
|
38
|
+
|
|
39
|
+
if not is_test:
|
|
40
|
+
chunk_size = calculate_chunk_size(test_outcomes)
|
|
41
|
+
chunks = chunkify(test_outcomes, chunk_size)
|
|
42
|
+
else:
|
|
43
|
+
chunks = [[]]
|
|
44
|
+
|
|
45
|
+
session = get_session()
|
|
46
|
+
|
|
47
|
+
url = _get_api_endpoint(api_url, event_type)
|
|
48
|
+
headers = {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
"ServiceAccountAuthenticationKey": api_key,
|
|
51
|
+
}
|
|
52
|
+
for chunk in chunks:
|
|
53
|
+
payload["test_outcomes"] = chunk
|
|
54
|
+
response = session.post(url, headers=headers, json=payload, verify=settings.OBSERVABILITY_VERIFY_SSL)
|
|
55
|
+
if not response.ok:
|
|
56
|
+
if is_test and "test_outcomes" in response.text and "Length must be between 1 and 500" in response.text:
|
|
57
|
+
continue
|
|
58
|
+
else:
|
|
59
|
+
raise requests.HTTPError(
|
|
60
|
+
f"Call to {url} failed with status code: {response.status_code} and message: {response.text}"
|
|
61
|
+
)
|
|
62
|
+
return qty_of_events
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _get_api_endpoint(api_url: str | None, event_type: str) -> str:
|
|
66
|
+
if not api_url:
|
|
67
|
+
raise Warning("Unable to post events due to misconfigured Observability API URL")
|
|
68
|
+
|
|
69
|
+
parsed_url = urlparse(api_url)
|
|
70
|
+
return f"{parsed_url.scheme!s}://{parsed_url.netloc!s}{parsed_url.path!s}/events/v1/{event_type}"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def collect_event_data(project_code, test_suite):
|
|
74
|
+
try:
|
|
75
|
+
event_data_query = (
|
|
76
|
+
read_template_sql_file("get_event_data.sql", "observability")
|
|
77
|
+
.replace("{PROJECT_CODE}", project_code)
|
|
78
|
+
.replace("{TEST_SUITE}", test_suite)
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
event_data_query_result = RetrieveDBResultsToDictList("DKTG", event_data_query)
|
|
82
|
+
if not event_data_query_result:
|
|
83
|
+
LOG.error(
|
|
84
|
+
f"Could not get event data for exporting to Observability. Test suite '{test_suite}' - project_code '{project_code}'. EXITING!"
|
|
85
|
+
)
|
|
86
|
+
sys.exit(1)
|
|
87
|
+
if len(event_data_query_result) == 0:
|
|
88
|
+
LOG.error(
|
|
89
|
+
f"Event data query is empty. Test suite '{test_suite}' - project_code '{project_code}'. Exiting export to Observability!"
|
|
90
|
+
)
|
|
91
|
+
sys.exit(1)
|
|
92
|
+
|
|
93
|
+
event = event_data_query_result[0]
|
|
94
|
+
event_data = _get_event_data(event)
|
|
95
|
+
api_key = event.observability_api_key
|
|
96
|
+
api_url = event.observability_api_url
|
|
97
|
+
except Exception:
|
|
98
|
+
LOG.exception(
|
|
99
|
+
f"Error collecting event data for exporting to Observability. Test suite '{test_suite}' - project_code '{project_code}'"
|
|
100
|
+
)
|
|
101
|
+
sys.exit(2)
|
|
102
|
+
else:
|
|
103
|
+
return event_data, api_url, api_key
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _get_test_event_data(project_code):
|
|
107
|
+
Event = namedtuple(
|
|
108
|
+
"Event",
|
|
109
|
+
[
|
|
110
|
+
"sql_flavor",
|
|
111
|
+
"dataset_key",
|
|
112
|
+
"dataset_name",
|
|
113
|
+
"schema",
|
|
114
|
+
"connection_name",
|
|
115
|
+
"project_db",
|
|
116
|
+
"table_groups_id",
|
|
117
|
+
"profile_use_sampling",
|
|
118
|
+
"project_code",
|
|
119
|
+
"profile_sample_percent",
|
|
120
|
+
"profile_sample_minimum_count",
|
|
121
|
+
"profiling_include_mask",
|
|
122
|
+
"profiling_exclude_mask",
|
|
123
|
+
"profiling_table_set",
|
|
124
|
+
],
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
event = Event(
|
|
128
|
+
sql_flavor="redshift",
|
|
129
|
+
dataset_key="test_dataset_key",
|
|
130
|
+
dataset_name="test_dataset_name",
|
|
131
|
+
schema="test_schema",
|
|
132
|
+
connection_name="test_connection_name",
|
|
133
|
+
project_db="test_project_db",
|
|
134
|
+
table_groups_id=uuid.uuid4(),
|
|
135
|
+
profile_use_sampling="N",
|
|
136
|
+
project_code=project_code,
|
|
137
|
+
profile_sample_percent="30",
|
|
138
|
+
profile_sample_minimum_count="15000",
|
|
139
|
+
profiling_include_mask="%",
|
|
140
|
+
profiling_exclude_mask="tmp%",
|
|
141
|
+
profiling_table_set="",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
event_data = _get_event_data(event)
|
|
145
|
+
return event_data
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _get_event_data(event):
|
|
149
|
+
event_data = {
|
|
150
|
+
"external_url": None,
|
|
151
|
+
"stream_name": None,
|
|
152
|
+
"run_key": None,
|
|
153
|
+
"server_name": None,
|
|
154
|
+
"task_name": None,
|
|
155
|
+
"pipeline_key": None,
|
|
156
|
+
"pipeline_name": None,
|
|
157
|
+
"metadata": {},
|
|
158
|
+
"run_name": None,
|
|
159
|
+
"task_key": None,
|
|
160
|
+
"stream_key": None,
|
|
161
|
+
"server_key": None,
|
|
162
|
+
"component_tool": event.sql_flavor,
|
|
163
|
+
"dataset_key": event.dataset_key,
|
|
164
|
+
"dataset_name": event.dataset_name,
|
|
165
|
+
"event_timestamp": date_service.get_now_as_iso_timestamp(),
|
|
166
|
+
"component_integrations": {
|
|
167
|
+
"integrations": {
|
|
168
|
+
"testgen": {
|
|
169
|
+
"schema": event.schema,
|
|
170
|
+
"connection_name": event.connection_name,
|
|
171
|
+
"database_name": event.project_db,
|
|
172
|
+
"version": 1,
|
|
173
|
+
"table_group_configuration": {
|
|
174
|
+
"group_id": str(event.table_groups_id),
|
|
175
|
+
"uses_sampling": event.profile_use_sampling == "Y",
|
|
176
|
+
"project_code": event.project_code,
|
|
177
|
+
"sample_percentage": (
|
|
178
|
+
event.profile_sample_percent if event.profile_use_sampling == "Y" else None
|
|
179
|
+
),
|
|
180
|
+
"sample_minimum_count": (
|
|
181
|
+
event.profile_sample_minimum_count if event.profile_use_sampling == "Y" else None
|
|
182
|
+
),
|
|
183
|
+
},
|
|
184
|
+
"tables": {
|
|
185
|
+
"include_pattern": event.profiling_include_mask,
|
|
186
|
+
"exclude_pattern": event.profiling_exclude_mask,
|
|
187
|
+
"include_list": _get_processed_profiling_table_set(event.profiling_table_set),
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
}
|
|
193
|
+
return event_data
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _get_processed_profiling_table_set(profiling_table_set):
|
|
197
|
+
if profiling_table_set is None:
|
|
198
|
+
return []
|
|
199
|
+
items = profiling_table_set.split(",")
|
|
200
|
+
items_no_quotes = [x.replace("'", "") for x in items]
|
|
201
|
+
items_remove_blank = list(filter(lambda x: x != "", items_no_quotes))
|
|
202
|
+
return items_remove_blank
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def collect_test_results(project_code, test_suite, max_qty_events):
|
|
206
|
+
try:
|
|
207
|
+
query = (
|
|
208
|
+
read_template_sql_file("get_test_results.sql", "observability")
|
|
209
|
+
.replace("{PROJECT_CODE}", project_code)
|
|
210
|
+
.replace("{TEST_SUITE}", test_suite)
|
|
211
|
+
.replace("{MAX_QTY_EVENTS}", str(max_qty_events))
|
|
212
|
+
)
|
|
213
|
+
query_results = RetrieveDBResultsToDictList("DKTG", query)
|
|
214
|
+
collected = []
|
|
215
|
+
updated_ids = []
|
|
216
|
+
except Exception:
|
|
217
|
+
LOG.exception("Error collecting test results! EXITING!")
|
|
218
|
+
sys.exit(2)
|
|
219
|
+
for result in query_results:
|
|
220
|
+
try:
|
|
221
|
+
result_payload = {
|
|
222
|
+
"integrations": {
|
|
223
|
+
"testgen": {
|
|
224
|
+
"columns": result.column_names.split(",") if result.column_names is not None else [],
|
|
225
|
+
"table": result.table_name,
|
|
226
|
+
"test_suite": result.test_suite,
|
|
227
|
+
"test_parameters": _get_input_parameters(result.input_parameters),
|
|
228
|
+
"version": 1,
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
"key": str(result.test_definition_id),
|
|
232
|
+
"type": result.type,
|
|
233
|
+
"min_threshold": result.min_threshold,
|
|
234
|
+
"max_threshold": result.max_threshold,
|
|
235
|
+
"name": result.name,
|
|
236
|
+
"description": result.description,
|
|
237
|
+
"metadata": {},
|
|
238
|
+
"start_time": date_service.as_iso_timestamp(result.start_time),
|
|
239
|
+
"result": result.result_message,
|
|
240
|
+
"end_time": date_service.as_iso_timestamp(result.end_time),
|
|
241
|
+
"dimensions": [result.dq_dimension],
|
|
242
|
+
"status": result.result_status.upper(),
|
|
243
|
+
"metric_value": result.metric_value,
|
|
244
|
+
"metric_name": result.measure_uom,
|
|
245
|
+
"metric_description": result.measure_uom_description,
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
collected.append(result_payload)
|
|
249
|
+
updated_ids.append(str(result.result_id))
|
|
250
|
+
except Exception:
|
|
251
|
+
LOG.warning("Error collecting record", exc_info=True)
|
|
252
|
+
|
|
253
|
+
return collected, updated_ids
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _get_input_parameters(input_parameters):
|
|
257
|
+
ret = []
|
|
258
|
+
if input_parameters is None:
|
|
259
|
+
return ret
|
|
260
|
+
|
|
261
|
+
items = input_parameters.split("=")
|
|
262
|
+
|
|
263
|
+
if len(items) < 2:
|
|
264
|
+
return ret
|
|
265
|
+
|
|
266
|
+
is_first = True
|
|
267
|
+
item_number = 0
|
|
268
|
+
name = None
|
|
269
|
+
for item in items:
|
|
270
|
+
item_number += 1
|
|
271
|
+
if is_first:
|
|
272
|
+
name = item
|
|
273
|
+
is_first = False
|
|
274
|
+
elif len(items) == item_number: # is last
|
|
275
|
+
value = item
|
|
276
|
+
ret.append({"name": name.strip(), "value": value.strip()})
|
|
277
|
+
else:
|
|
278
|
+
words = item.split(",")
|
|
279
|
+
value = ",".join(words[:-1]) # everything but the last word
|
|
280
|
+
ret.append({"name": name.strip(), "value": value.strip()})
|
|
281
|
+
name = words[-1] # the last word is the next name
|
|
282
|
+
return ret
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def mark_exported_results(project_code, test_suite, ids):
|
|
286
|
+
if len(ids) == 0:
|
|
287
|
+
return
|
|
288
|
+
|
|
289
|
+
result_ids = ", ".join(ids)
|
|
290
|
+
query = (
|
|
291
|
+
read_template_sql_file("update_test_results_exported_to_observability.sql", "observability")
|
|
292
|
+
.replace("{PROJECT_CODE}", project_code)
|
|
293
|
+
.replace("{TEST_SUITE}", test_suite)
|
|
294
|
+
.replace("{RESULT_IDS}", result_ids)
|
|
295
|
+
)
|
|
296
|
+
try:
|
|
297
|
+
ExecuteDBQuery("DKTG", query)
|
|
298
|
+
except Exception:
|
|
299
|
+
LOG.exception("Error marking exported results.")
|
|
300
|
+
LOG.error( # noqa: TRY400
|
|
301
|
+
f"These should be marked manually!. Run the following query to fix \n------\n{query}\n------"
|
|
302
|
+
)
|
|
303
|
+
sys.exit(3)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def export_test_results(project_code, test_suite):
|
|
307
|
+
LOG.info("Observability Export V2 - Privileged UI")
|
|
308
|
+
event, api_url, api_key = collect_event_data(project_code, test_suite)
|
|
309
|
+
max_qty_events = settings.OBSERVABILITY_EXPORT_LIMIT
|
|
310
|
+
qty_of_exported_events = 0
|
|
311
|
+
while True:
|
|
312
|
+
display_service.echo(f"Observability Export Increment - {qty_of_exported_events} exported events so far")
|
|
313
|
+
test_outcomes, updated_ids = collect_test_results(project_code, test_suite, max_qty_events)
|
|
314
|
+
if len(test_outcomes) == 0:
|
|
315
|
+
return qty_of_exported_events
|
|
316
|
+
qty_of_exported_events += post_event("test-outcomes", event, api_url, api_key, test_outcomes)
|
|
317
|
+
mark_exported_results(project_code, test_suite, updated_ids)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def run_observability_exporter(project_code, test_suite):
|
|
321
|
+
LOG.info("CurrentStep: Observability Export - Test Results")
|
|
322
|
+
qty_of_exported_events = export_test_results(project_code, test_suite)
|
|
323
|
+
display_service.echo(f"{qty_of_exported_events} events have been exported.")
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def test_observability_exporter(project_code, api_url, api_key):
|
|
327
|
+
event = _get_test_event_data(project_code)
|
|
328
|
+
test_outcomes = []
|
|
329
|
+
post_event("test-outcomes", event, api_url, api_key, test_outcomes, is_test=True)
|
|
330
|
+
LOG.info("Test Observability Exporter Finished")
|