From b152c25ef288acd943d842f041db15677c60919e Mon Sep 17 00:00:00 2001 From: Ofek Weiss Date: Sun, 9 Mar 2025 12:52:01 +0200 Subject: [PATCH 1/2] Consider invocation filters in the send-report summary --- elementary/monitor/api/tests/tests.py | 8 ++++++++ .../data_monitoring/report/data_monitoring_report.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/elementary/monitor/api/tests/tests.py b/elementary/monitor/api/tests/tests.py index 17dcdc3d1..376054061 100644 --- a/elementary/monitor/api/tests/tests.py +++ b/elementary/monitor/api/tests/tests.py @@ -26,6 +26,7 @@ ) from elementary.monitor.api.totals_schema import TotalsSchema from elementary.monitor.data_monitoring.schema import SelectorFilterSchema +from elementary.monitor.fetchers.invocations.schema import DbtInvocationSchema from elementary.monitor.fetchers.tests.schema import ( NormalizedTestSchema, TestDBRowSchema, @@ -69,8 +70,15 @@ def _get_test_results_db_rows( def get_test_results_summary( self, filter: SelectorFilterSchema = SelectorFilterSchema(), + dbt_invocation: Optional[DbtInvocationSchema] = None, ) -> List[TestResultSummarySchema]: filtered_test_results_db_rows = self.test_results_db_rows + if dbt_invocation and dbt_invocation.invocation_id: + filtered_test_results_db_rows = [ + test_result + for test_result in filtered_test_results_db_rows + if test_result.invocation_id == dbt_invocation.invocation_id + ] if filter.tag: filtered_test_results_db_rows = [ test_result diff --git a/elementary/monitor/data_monitoring/report/data_monitoring_report.py b/elementary/monitor/data_monitoring/report/data_monitoring_report.py index 7f1718b5b..7924f7b28 100644 --- a/elementary/monitor/data_monitoring/report/data_monitoring_report.py +++ b/elementary/monitor/data_monitoring/report/data_monitoring_report.py @@ -10,6 +10,7 @@ from elementary.clients.s3.client import S3Client from elementary.clients.slack.client import SlackClient from elementary.config.config import Config +from elementary.monitor.api.invocations.invocations import InvocationsAPI from elementary.monitor.api.report.report import ReportAPI from elementary.monitor.api.report.schema import ReportDataSchema from elementary.monitor.api.tests.tests import TestsAPI @@ -285,8 +286,15 @@ def send_test_results_summary( invocations_per_test=test_runs_amount, disable_passed_test_metrics=disable_passed_test_metrics, ) + invocations_api = InvocationsAPI( + dbt_runner=self.internal_dbt_runner, + ) + invocation = invocations_api.get_test_invocation_from_filter( + self.selector_filter.to_selector_filter_schema() + ) summary_test_results = tests_api.get_test_results_summary( filter=self.selector_filter.to_selector_filter_schema(), + dbt_invocation=invocation, ) if self.slack_client: send_succeeded = self.slack_client.send_message( From df4b0876597fb77a2413d141e7cc13fd8c80faea Mon Sep 17 00:00:00 2001 From: Ofek Weiss Date: Sun, 9 Mar 2025 13:02:00 +0200 Subject: [PATCH 2/2] if else --- elementary/monitor/api/tests/tests.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/elementary/monitor/api/tests/tests.py b/elementary/monitor/api/tests/tests.py index 376054061..9164eba5e 100644 --- a/elementary/monitor/api/tests/tests.py +++ b/elementary/monitor/api/tests/tests.py @@ -73,12 +73,6 @@ def get_test_results_summary( dbt_invocation: Optional[DbtInvocationSchema] = None, ) -> List[TestResultSummarySchema]: filtered_test_results_db_rows = self.test_results_db_rows - if dbt_invocation and dbt_invocation.invocation_id: - filtered_test_results_db_rows = [ - test_result - for test_result in filtered_test_results_db_rows - if test_result.invocation_id == dbt_invocation.invocation_id - ] if filter.tag: filtered_test_results_db_rows = [ test_result @@ -101,11 +95,19 @@ def get_test_results_summary( ) ] - filtered_test_results_db_rows = [ - test_result - for test_result in filtered_test_results_db_rows - if test_result.invocations_rank_index == 1 - ] + if dbt_invocation and dbt_invocation.invocation_id: + filtered_test_results_db_rows = [ + test_result + for test_result in filtered_test_results_db_rows + if test_result.invocation_id == dbt_invocation.invocation_id + ] + else: + filtered_test_results_db_rows = [ + test_result + for test_result in filtered_test_results_db_rows + if test_result.invocations_rank_index == 1 + ] + return [ TestResultSummarySchema( test_unique_id=test_result.test_unique_id,