-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ele 2626 support singular tests in test results runs #1449
Merged
NoyaArie
merged 6 commits into
master
from
ele-2626-support-singular-tests-in-test-results-runs
Mar 6, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9ae4502
rename
NoyaArie e4dfc00
test results and runs includes keys for singular as well
NoyaArie 7b9496d
freshness api types
NoyaArie 65f62f2
change test runs totals
NoyaArie 3495da6
fix type
NoyaArie e52b704
types cleanup + fix test results totals
NoyaArie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,14 +67,14 @@ def get_report_data( | |
models = models_api.get_models(exclude_elementary_models) | ||
sources = models_api.get_sources() | ||
exposures = models_api.get_exposures() | ||
tests = tests_api.get_singular_tests() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename |
||
singular_tests = tests_api.get_singular_tests() | ||
|
||
groups = groups_api.get_groups( | ||
artifacts=[ | ||
*models.values(), | ||
*sources.values(), | ||
*exposures.values(), | ||
*tests, | ||
*singular_tests, | ||
] | ||
) | ||
|
||
|
@@ -140,9 +140,11 @@ def get_report_data( | |
|
||
invocations_job_identification = defaultdict(list) | ||
for invocation in invocations: | ||
key = invocation.job_name or invocation.job_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename key to invocation_key |
||
if key is not None: | ||
invocations_job_identification[key].append(invocation.invocation_id) | ||
invocation_key = invocation.job_name or invocation.job_id | ||
if invocation_key is not None: | ||
invocations_job_identification[invocation_key].append( | ||
invocation.invocation_id | ||
) | ||
|
||
report_data = ReportDataSchema( | ||
creation_time=get_now_utc_iso_format(), | ||
|
@@ -193,33 +195,27 @@ def _serialize_models_runs(self, models_runs: List[ModelRunsSchema]) -> List[dic | |
def _serialize_test_results( | ||
self, | ||
test_results: Dict[ | ||
Optional[str], List[Union[TestResultSchema, SourceFreshnessResultSchema]] | ||
str, List[Union[TestResultSchema, SourceFreshnessResultSchema]] | ||
], | ||
) -> Dict[Optional[str], List[dict]]: | ||
) -> Dict[str, List[dict]]: | ||
serializable_test_results = defaultdict(list) | ||
for model_unique_id, test_result in test_results.items(): | ||
serializable_test_results[model_unique_id].extend( | ||
for key, test_result in test_results.items(): | ||
serializable_test_results[key].extend( | ||
[result.dict() for result in test_result] | ||
) | ||
return serializable_test_results | ||
|
||
def _serialize_test_runs( | ||
self, | ||
test_runs: Dict[ | ||
Optional[str], List[Union[TestRunSchema, SourceFreshnessRunSchema]] | ||
], | ||
) -> Dict[Optional[str], List[dict]]: | ||
test_runs: Dict[str, List[Union[TestRunSchema, SourceFreshnessRunSchema]]], | ||
) -> Dict[str, List[dict]]: | ||
serializable_test_runs = defaultdict(list) | ||
for model_unique_id, test_run in test_runs.items(): | ||
serializable_test_runs[model_unique_id].extend( | ||
[run.dict() for run in test_run] | ||
) | ||
for key, test_run in test_runs.items(): | ||
serializable_test_runs[key].extend([run.dict() for run in test_run]) | ||
return serializable_test_runs | ||
|
||
def _serialize_totals( | ||
self, totals: Dict[Optional[str], TotalsSchema] | ||
) -> Dict[Optional[str], dict]: | ||
def _serialize_totals(self, totals: Dict[str, TotalsSchema]) -> Dict[str, dict]: | ||
serialized_totals = dict() | ||
for model_unique_id, total in totals.items(): | ||
serialized_totals[model_unique_id] = total.dict() | ||
for key, total in totals.items(): | ||
serialized_totals[key] = total.dict() | ||
return serialized_totals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,40 @@ | ||
from collections import defaultdict | ||
from typing import Dict, List, Optional, Union | ||
from typing import Dict, List, Union | ||
|
||
from elementary.monitor.api.source_freshnesses.schema import ( | ||
SourceFreshnessMetadataSchema, | ||
SourceFreshnessResultSchema, | ||
SourceFreshnessRunSchema, | ||
) | ||
from elementary.monitor.api.tests.schema import ( | ||
TestMetadataSchema, | ||
TestResultSchema, | ||
TestRunSchema, | ||
) | ||
from elementary.monitor.api.tests.schema import TestResultSchema, TestRunSchema | ||
from elementary.monitor.api.totals_schema import TotalsSchema | ||
|
||
|
||
def get_total_test_results( | ||
test_results: Dict[ | ||
Optional[str], List[Union[TestResultSchema, SourceFreshnessResultSchema]] | ||
], | ||
) -> Dict[Optional[str], TotalsSchema]: | ||
test_metadatas = [] | ||
for test_result in test_results.values(): | ||
test_metadatas.extend([result.metadata for result in test_result]) | ||
test_results: Dict[str, List[Union[TestResultSchema, SourceFreshnessResultSchema]]], | ||
) -> Dict[str, TotalsSchema]: | ||
totals: Dict[str, TotalsSchema] = defaultdict(TotalsSchema) | ||
for key, test_result in test_results.items(): | ||
for result in test_result: | ||
# count by the key of the tests_results | ||
totals[key].add_total(result.metadata.latest_run_status) | ||
|
||
return _calculate_test_results_totals(test_metadatas) | ||
return totals | ||
|
||
|
||
def get_total_test_runs( | ||
tests_runs: Dict[ | ||
Optional[str], List[Union[TestRunSchema, SourceFreshnessRunSchema]] | ||
] | ||
) -> Dict[Optional[str], TotalsSchema]: | ||
totals: Dict[Optional[str], TotalsSchema] = defaultdict(TotalsSchema) | ||
for test_runs in tests_runs.values(): | ||
tests_runs: Dict[str, List[Union[TestRunSchema, SourceFreshnessRunSchema]]] | ||
) -> Dict[str, TotalsSchema]: | ||
totals: Dict[str, TotalsSchema] = defaultdict(TotalsSchema) | ||
for key, test_runs in tests_runs.items(): | ||
for test_run in test_runs: | ||
# It's possible test_runs will be None if we didn't find any invocations associated | ||
# with this test, in that case it also makes sense to skip it. | ||
if not test_run.test_runs: | ||
continue | ||
|
||
test_invocations = test_run.test_runs.invocations | ||
model_unique_id = test_run.metadata.model_unique_id | ||
|
||
for test_invocation in test_invocations: | ||
totals[model_unique_id].add_total(test_invocation.status) | ||
return totals | ||
|
||
|
||
def _calculate_test_results_totals( | ||
test_metadatas: List[Union[TestMetadataSchema, SourceFreshnessMetadataSchema]], | ||
) -> Dict[Optional[str], TotalsSchema]: | ||
totals: Dict[Optional[str], TotalsSchema] = defaultdict(TotalsSchema) | ||
for test in test_metadatas: | ||
totals[test.model_unique_id].add_total(test.latest_run_status) | ||
# count by the key of the tests_runs | ||
totals[key].add_total(test_invocation.status) | ||
return totals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keys of test_results, test_runs, test_results_totals, test_runs_totals are no longer nullable