From 6533086a02a5b315576762f457eaa2b232df85b4 Mon Sep 17 00:00:00 2001 From: Joseph Sawaya Date: Mon, 24 Mar 2025 13:05:17 -0400 Subject: [PATCH] feat(ta-gql): handle receiving all branches filter add all branches special case for TA results branch filter in new TA functionality --- ...gql_query_with_new_ta_all_branches__0.json | 77 +++++++++++++++++++ graphql_api/tests/test_test_analytics.py | 65 ++++++++++++++++ .../types/test_analytics/test_analytics.py | 3 +- utils/test_results.py | 8 +- 4 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 graphql_api/tests/snapshots/analytics__TestAnalyticsTestCase__gql_query_with_new_ta_all_branches__0.json diff --git a/graphql_api/tests/snapshots/analytics__TestAnalyticsTestCase__gql_query_with_new_ta_all_branches__0.json b/graphql_api/tests/snapshots/analytics__TestAnalyticsTestCase__gql_query_with_new_ta_all_branches__0.json new file mode 100644 index 0000000000..6dffacc939 --- /dev/null +++ b/graphql_api/tests/snapshots/analytics__TestAnalyticsTestCase__gql_query_with_new_ta_all_branches__0.json @@ -0,0 +1,77 @@ +[ + { + "cursor": "MC44fHRlc3Q0", + "node": { + "name": "test4", + "failureRate": 0.8, + "flakeRate": 0.0, + "avgDuration": 100.0, + "totalFailCount": 20, + "totalFlakyFailCount": 0, + "totalPassCount": 5, + "totalSkipCount": 5, + "commitsFailed": 5, + "lastDuration": 100.0 + } + }, + { + "cursor": "MC43NXx0ZXN0Mw==", + "node": { + "name": "test3", + "failureRate": 0.75, + "flakeRate": 0.0, + "avgDuration": 100.0, + "totalFailCount": 15, + "totalFlakyFailCount": 0, + "totalPassCount": 5, + "totalSkipCount": 5, + "commitsFailed": 5, + "lastDuration": 100.0 + } + }, + { + "cursor": "MC42NjY2NjY2NjY2NjY2NjY2fHRlc3Qy", + "node": { + "name": "test2", + "failureRate": 0.6666666666666666, + "flakeRate": 0.0, + "avgDuration": 100.0, + "totalFailCount": 10, + "totalFlakyFailCount": 0, + "totalPassCount": 5, + "totalSkipCount": 5, + "commitsFailed": 5, + "lastDuration": 100.0 + } + }, + { + "cursor": "MC41fHRlc3Qx", + "node": { + "name": "test1", + "failureRate": 0.5, + "flakeRate": 0.5, + "avgDuration": 100.0, + "totalFailCount": 5, + "totalFlakyFailCount": 5, + "totalPassCount": 5, + "totalSkipCount": 5, + "commitsFailed": 5, + "lastDuration": 100.0 + } + }, + { + "cursor": "MC4wfHRlc3Qw", + "node": { + "name": "test0", + "failureRate": 0.0, + "flakeRate": 0.0, + "avgDuration": 100.0, + "totalFailCount": 0, + "totalFlakyFailCount": 0, + "totalPassCount": 5, + "totalSkipCount": 5, + "commitsFailed": 5, + "lastDuration": 100.0 + } + } +] diff --git a/graphql_api/tests/test_test_analytics.py b/graphql_api/tests/test_test_analytics.py index 07501ca25d..c8cc7f3851 100644 --- a/graphql_api/tests/test_test_analytics.py +++ b/graphql_api/tests/test_test_analytics.py @@ -808,3 +808,68 @@ def test_gql_query_with_new_ta(self, mocker, repository, snapshot): settings.GCS_BUCKET_NAME, f"test_analytics/branch_rollups/{repository.repoid}/{repository.branch}.arrow", ) + + def test_gql_query_with_new_ta_all_branches(self, mocker, repository, snapshot): + # set the feature flag + mocker.patch("rollouts.READ_NEW_TA.check_value", return_value=True) + + # read file from samples + storage = get_appropriate_storage_service() + try: + storage.create_root_storage(settings.GCS_BUCKET_NAME) + except BucketAlreadyExistsError: + pass + storage.write_file( + settings.GCS_BUCKET_NAME, + f"test_analytics/repo_rollups/{repository.repoid}.arrow", + test_results_table_no_version.write_ipc(None).getvalue(), + ) + + # run the GQL query + query = base_gql_query % ( + repository.author.username, + repository.name, + """ + testResults(filters: { branch: "All branches" }, ordering: { parameter: FAILURE_RATE, direction: DESC } ) { + totalCount + edges { + cursor + node { + name + failureRate + flakeRate + updatedAt + avgDuration + totalFailCount + totalFlakyFailCount + totalPassCount + totalSkipCount + commitsFailed + lastDuration + } + } + } + """, + ) + + result = self.gql_request(query, owner=repository.author) + + # take a snapshot of the results + assert ( + result["owner"]["repository"]["testAnalytics"]["testResults"]["totalCount"] + == 5 + ) + assert snapshot("json") == [ + { + **edge, + "node": {k: v for k, v in edge["node"].items() if k != "updatedAt"}, + } + for edge in result["owner"]["repository"]["testAnalytics"]["testResults"][ + "edges" + ] + ] + + storage.delete_file( + settings.GCS_BUCKET_NAME, + f"test_analytics/repo_rollups/{repository.repoid}.arrow", + ) diff --git a/graphql_api/types/test_analytics/test_analytics.py b/graphql_api/types/test_analytics/test_analytics.py index 26a3c2e885..569310921f 100644 --- a/graphql_api/types/test_analytics/test_analytics.py +++ b/graphql_api/types/test_analytics/test_analytics.py @@ -198,8 +198,7 @@ def generate_test_results( :param repoid: repoid of the repository we want to calculate aggregates for :param branch: optional name of the branch we want to filter on, if this is provided the aggregates calculated will only take into account - test instances generated on that branch. By default branches will not be filtered and test instances on all branches wil be taken into - account. + test instances generated on that branch. :param interval: timedelta for filtering test instances used to calculate the aggregates by time, the test instances used will be those with a created at larger than now - interval. :param testsuites: optional list of testsuite names to filter by, this is done via a union diff --git a/utils/test_results.py b/utils/test_results.py index c42c543646..a5803bfcfd 100644 --- a/utils/test_results.py +++ b/utils/test_results.py @@ -11,6 +11,8 @@ from rollouts import READ_NEW_TA from services.task import TaskService +ALL_BRANCHES = "All branches" + get_results_summary = Summary( "test_results_get_results", "Time it takes to download results from GCS", ["impl"] ) @@ -144,10 +146,10 @@ def old_get_results( return table -def rollup_blob_path(repoid: int, branch: str | None = None) -> str: +def rollup_blob_path(repoid: int, branch: str) -> str: return ( f"test_analytics/branch_rollups/{repoid}/{branch}.arrow" - if branch + if branch != ALL_BRANCHES else f"test_analytics/repo_rollups/{repoid}.arrow" ) @@ -223,7 +225,7 @@ def v1_agg_table(table: pl.LazyFrame) -> pl.LazyFrame: def new_get_results( repoid: int, - branch: str | None, + branch: str, interval_start: int, interval_end: int | None = None, ) -> pl.DataFrame | None: