From 30a8a6b038a34fbded68059b4215467188f7aab2 Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Wed, 23 Oct 2024 03:00:24 +0900 Subject: [PATCH] bundle analysis: fix unknown asset size compute --- .../test_bundle_analysis_measurements.py | 159 ++++++++++++++++++ graphql_api/types/bundle_analysis/base.py | 10 +- 2 files changed, 168 insertions(+), 1 deletion(-) diff --git a/graphql_api/tests/test_bundle_analysis_measurements.py b/graphql_api/tests/test_bundle_analysis_measurements.py index 8d692ff32c..861a8b6eb0 100644 --- a/graphql_api/tests/test_bundle_analysis_measurements.py +++ b/graphql_api/tests/test_bundle_analysis_measurements.py @@ -2971,3 +2971,162 @@ def test_bundle_report_bad_data_check(self, get_storage_service): "name": "super", }, } + + @patch("graphql_api.dataloader.bundle_analysis.get_appropriate_storage_service") + def test_bundle_report_measurements_only_unknown(self, get_storage_service): + storage = MemoryStorageService({}) + get_storage_service.return_value = storage + + with open("./services/tests/samples/bundle_with_uuid.sqlite", "rb") as f: + storage_path = StoragePaths.bundle_report.path( + repo_key=ArchiveService.get_archive_hash(self.repo), + report_key=self.head_commit_report.external_id, + ) + storage.write_file(get_bucket_name(), storage_path, f) + + query = """ + query FetchMeasurements( + $org: String!, + $repo: String!, + $commit: String! + $filters: BundleAnalysisMeasurementsSetFilters + $orderingDirection: OrderingDirection! + $interval: MeasurementInterval! + $before: DateTime! + $after: DateTime! + ) { + owner(username: $org) { + repository(name: $repo) { + ... on Repository { + commit(id: $commit) { + bundleAnalysis { + bundleAnalysisReport { + __typename + ... on BundleAnalysisReport { + bundle(name: "super") { + name + measurements( + filters: $filters + orderingDirection: $orderingDirection + after: $after + interval: $interval + before: $before + ){ + assetType + name + size { + loadTime { + threeG + highSpeed + } + size { + gzip + uncompress + } + } + change { + loadTime { + threeG + highSpeed + } + size { + gzip + uncompress + } + } + measurements { + avg + min + max + timestamp + } + } + } + } + } + } + } + } + } + } + } + """ + + # Test without using asset type filters + variables = { + "org": self.org.username, + "repo": self.repo.name, + "commit": self.commit.commitid, + "orderingDirection": "ASC", + "interval": "INTERVAL_1_DAY", + "after": "2024-06-06", + "before": "2024-06-10", + "filters": {"assetTypes": ["UNKNOWN_SIZE"]}, + } + data = self.gql_request(query, variables=variables) + commit = data["owner"]["repository"]["commit"] + + assert commit["bundleAnalysis"]["bundleAnalysisReport"] == { + "__typename": "BundleAnalysisReport", + "bundle": { + "measurements": [ + { + "assetType": "UNKNOWN_SIZE", + "change": { + "loadTime": { + "highSpeed": 0, + "threeG": 0, + }, + "size": { + "gzip": 0, + "uncompress": 0, + }, + }, + "measurements": [ + { + "avg": 0.0, + "max": 0.0, + "min": 0.0, + "timestamp": "2024-06-06T00:00:00+00:00", + }, + { + "avg": None, + "max": None, + "min": None, + "timestamp": "2024-06-07T00:00:00+00:00", + }, + { + "avg": None, + "max": None, + "min": None, + "timestamp": "2024-06-08T00:00:00+00:00", + }, + { + "avg": None, + "max": None, + "min": None, + "timestamp": "2024-06-09T00:00:00+00:00", + }, + { + "avg": 0.0, + "max": 0.0, + "min": 0.0, + "timestamp": "2024-06-10T00:00:00+00:00", + }, + ], + "name": None, + "size": { + "loadTime": { + "highSpeed": 0, + "threeG": 0, + }, + "size": { + "gzip": 0, + "uncompress": 0, + }, + }, + }, + ], + "name": "super", + }, + } diff --git a/graphql_api/types/bundle_analysis/base.py b/graphql_api/types/bundle_analysis/base.py index a5c550f9b8..6b6399bbec 100644 --- a/graphql_api/types/bundle_analysis/base.py +++ b/graphql_api/types/bundle_analysis/base.py @@ -295,10 +295,18 @@ def resolve_bundle_report_measurements( ) # All measureable names we need to fetch to compute the requested asset types - if not asset_types or ASSET_TYPE_UNKNOWN in asset_types: + if not asset_types: measurables_to_fetch = [ item for item in list(BundleAnalysisMeasurementsAssetType) ] + elif ASSET_TYPE_UNKNOWN in asset_types: + measurables_to_fetch = [ + BundleAnalysisMeasurementsAssetType.REPORT_SIZE, + BundleAnalysisMeasurementsAssetType.JAVASCRIPT_SIZE, + BundleAnalysisMeasurementsAssetType.STYLESHEET_SIZE, + BundleAnalysisMeasurementsAssetType.FONT_SIZE, + BundleAnalysisMeasurementsAssetType.IMAGE_SIZE, + ] else: measurables_to_fetch = [ BundleAnalysisMeasurementsAssetType[item] for item in asset_types