diff --git a/elementary/monitor/api/tests/tests.py b/elementary/monitor/api/tests/tests.py index 17dcdc3d1..9164eba5e 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,6 +70,7 @@ 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 filter.tag: @@ -93,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, 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(