From c5b1252b6bde7f0b495f494460baa58c4a89ac2f Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Wed, 14 Feb 2024 21:19:17 -0500 Subject: [PATCH 1/6] setup .graphql files and restructuring --- graphql_api/types/__init__.py | 18 ++++++++++--- graphql_api/types/bundle_analysis/__init__.py | 23 ++++++++++++++++ .../types/bundle_analysis/base.graphql | 27 +++++++++++++++++++ graphql_api/types/bundle_analysis/base.py | 7 +++++ .../comparison.graphql} | 0 .../comparison.py} | 0 .../report.graphql} | 7 +++++ .../report.py} | 0 .../bundle_analysis_comparison/__init__.py | 11 -------- .../types/bundle_analysis_report/__init__.py | 11 -------- .../inputs/bundle_analysis_filters.graphql | 3 +++ 11 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 graphql_api/types/bundle_analysis/__init__.py create mode 100644 graphql_api/types/bundle_analysis/base.graphql create mode 100644 graphql_api/types/bundle_analysis/base.py rename graphql_api/types/{bundle_analysis_comparison/bundle_analysis_comparison.graphql => bundle_analysis/comparison.graphql} (100%) rename graphql_api/types/{bundle_analysis_comparison/bundle_analysis_comparison.py => bundle_analysis/comparison.py} (100%) rename graphql_api/types/{bundle_analysis_report/bundle_analysis_report.graphql => bundle_analysis/report.graphql} (52%) rename graphql_api/types/{bundle_analysis_report/bundle_analysis_report.py => bundle_analysis/report.py} (100%) delete mode 100644 graphql_api/types/bundle_analysis_comparison/__init__.py delete mode 100644 graphql_api/types/bundle_analysis_report/__init__.py create mode 100644 graphql_api/types/inputs/bundle_analysis_filters.graphql diff --git a/graphql_api/types/__init__.py b/graphql_api/types/__init__.py index 1158c4463f..d97fcd3551 100644 --- a/graphql_api/types/__init__.py +++ b/graphql_api/types/__init__.py @@ -3,17 +3,21 @@ from ..helpers.ariadne import ariadne_load_local_graphql from .branch import branch, branch_bindable -from .bundle_analysis_comparison import ( +from .bundle_analysis import ( + bundle_analysis, bundle_analysis_comparison, bundle_analysis_comparison_bindable, bundle_analysis_comparison_result_bindable, - bundle_comparison_bindable, -) -from .bundle_analysis_report import ( bundle_analysis_report, bundle_analysis_report_bindable, bundle_analysis_report_result_bindable, + bundle_asset_bindable, + bundle_comparison_bindable, + bundle_data_bindable, + bundle_load_time_bindable, + bundle_module_bindable, bundle_report_bindable, + bundle_size_bindable, ) from .commit import commit, commit_bindable from .comparison import comparison, comparison_bindable, comparison_result_bindable @@ -70,6 +74,7 @@ query, me, branch, + bundle_analysis, bundle_analysis_comparison, bundle_analysis_report, commit, @@ -108,6 +113,11 @@ query_bindable, me_bindable, branch_bindable, + bundle_module_bindable, + bundle_asset_bindable, + bundle_size_bindable, + bundle_load_time_bindable, + bundle_data_bindable, bundle_analysis_comparison_result_bindable, bundle_analysis_comparison_bindable, bundle_comparison_bindable, diff --git a/graphql_api/types/bundle_analysis/__init__.py b/graphql_api/types/bundle_analysis/__init__.py new file mode 100644 index 0000000000..333d7b197a --- /dev/null +++ b/graphql_api/types/bundle_analysis/__init__.py @@ -0,0 +1,23 @@ +from graphql_api.helpers.ariadne import ariadne_load_local_graphql + +from .base import ( + bundle_asset_bindable, + bundle_data_bindable, + bundle_load_time_bindable, + bundle_module_bindable, + bundle_size_bindable, +) +from .comparison import ( + bundle_analysis_comparison_bindable, + bundle_analysis_comparison_result_bindable, + bundle_comparison_bindable, +) +from .report import ( + bundle_analysis_report_bindable, + bundle_analysis_report_result_bindable, + bundle_report_bindable, +) + +bundle_analysis = ariadne_load_local_graphql(__file__, "base.graphql") +bundle_analysis_comparison = ariadne_load_local_graphql(__file__, "comparison.graphql") +bundle_analysis_report = ariadne_load_local_graphql(__file__, "report.graphql") diff --git a/graphql_api/types/bundle_analysis/base.graphql b/graphql_api/types/bundle_analysis/base.graphql new file mode 100644 index 0000000000..f484af8714 --- /dev/null +++ b/graphql_api/types/bundle_analysis/base.graphql @@ -0,0 +1,27 @@ +type BundleSize { + gzip: Int! + uncompress: Int! +} + +type BundleLoadTime { + threeG: Int! + highSpeed: Int! +} + +type BundleData { + loadTime: BundleLoadTime! + size: BundleSize! +} + +type BundleModule { + name: String! + bundleData: BundleData! +} + +type BundleAsset { + name: String! + normalizedName: String! + moduleExtensions: [String!]! + modules: [BundleModule]! + bundleData: BundleData! +} \ No newline at end of file diff --git a/graphql_api/types/bundle_analysis/base.py b/graphql_api/types/bundle_analysis/base.py new file mode 100644 index 0000000000..d4259217f7 --- /dev/null +++ b/graphql_api/types/bundle_analysis/base.py @@ -0,0 +1,7 @@ +from ariadne import ObjectType, UnionType + +bundle_size_bindable = ObjectType("BundleSize") +bundle_load_time_bindable = ObjectType("BundleLoadTime") +bundle_data_bindable = ObjectType("BundleData") +bundle_module_bindable = ObjectType("BundleModule") +bundle_asset_bindable = ObjectType("BundleAsset") diff --git a/graphql_api/types/bundle_analysis_comparison/bundle_analysis_comparison.graphql b/graphql_api/types/bundle_analysis/comparison.graphql similarity index 100% rename from graphql_api/types/bundle_analysis_comparison/bundle_analysis_comparison.graphql rename to graphql_api/types/bundle_analysis/comparison.graphql diff --git a/graphql_api/types/bundle_analysis_comparison/bundle_analysis_comparison.py b/graphql_api/types/bundle_analysis/comparison.py similarity index 100% rename from graphql_api/types/bundle_analysis_comparison/bundle_analysis_comparison.py rename to graphql_api/types/bundle_analysis/comparison.py diff --git a/graphql_api/types/bundle_analysis_report/bundle_analysis_report.graphql b/graphql_api/types/bundle_analysis/report.graphql similarity index 52% rename from graphql_api/types/bundle_analysis_report/bundle_analysis_report.graphql rename to graphql_api/types/bundle_analysis/report.graphql index 72b3e24445..877c179860 100644 --- a/graphql_api/types/bundle_analysis_report/bundle_analysis_report.graphql +++ b/graphql_api/types/bundle_analysis/report.graphql @@ -6,10 +6,17 @@ type BundleAnalysisReport { sizeTotal: Int! loadTimeTotal: Float! bundles: [BundleReport]! + bundle(name: String!, filters: BundleAnalysisReportFilters): BundleReport + moduleExtensions: [String!]! + moduleCount: Int! + assets: [BundleAsset]! + asset(name: String!): BundleAsset + bundleData: BundleData! } type BundleReport { name: String! sizeTotal: Int! loadTimeTotal: Float! + bundleData: BundleData! } \ No newline at end of file diff --git a/graphql_api/types/bundle_analysis_report/bundle_analysis_report.py b/graphql_api/types/bundle_analysis/report.py similarity index 100% rename from graphql_api/types/bundle_analysis_report/bundle_analysis_report.py rename to graphql_api/types/bundle_analysis/report.py diff --git a/graphql_api/types/bundle_analysis_comparison/__init__.py b/graphql_api/types/bundle_analysis_comparison/__init__.py deleted file mode 100644 index cad0a3dd5e..0000000000 --- a/graphql_api/types/bundle_analysis_comparison/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -from graphql_api.helpers.ariadne import ariadne_load_local_graphql - -from .bundle_analysis_comparison import ( - bundle_analysis_comparison_bindable, - bundle_analysis_comparison_result_bindable, - bundle_comparison_bindable, -) - -bundle_analysis_comparison = ariadne_load_local_graphql( - __file__, "bundle_analysis_comparison.graphql" -) diff --git a/graphql_api/types/bundle_analysis_report/__init__.py b/graphql_api/types/bundle_analysis_report/__init__.py deleted file mode 100644 index 5e3b0ed013..0000000000 --- a/graphql_api/types/bundle_analysis_report/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -from graphql_api.helpers.ariadne import ariadne_load_local_graphql - -from .bundle_analysis_report import ( - bundle_analysis_report_bindable, - bundle_analysis_report_result_bindable, - bundle_report_bindable, -) - -bundle_analysis_report = ariadne_load_local_graphql( - __file__, "bundle_analysis_report.graphql" -) diff --git a/graphql_api/types/inputs/bundle_analysis_filters.graphql b/graphql_api/types/inputs/bundle_analysis_filters.graphql new file mode 100644 index 0000000000..0f615eb69e --- /dev/null +++ b/graphql_api/types/inputs/bundle_analysis_filters.graphql @@ -0,0 +1,3 @@ +input BundleAnalysisReportFilters { + extensions: [String!]! +} \ No newline at end of file From ea7b21edf5cf6870a47318147337f25c00ab8a61 Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Wed, 14 Feb 2024 21:28:51 -0500 Subject: [PATCH 2/6] move BundleReport to base --- graphql_api/types/bundle_analysis/__init__.py | 2 +- .../types/bundle_analysis/base.graphql | 7 +++++++ graphql_api/types/bundle_analysis/base.py | 20 ++++++++++++++++++- .../types/bundle_analysis/report.graphql | 12 ----------- graphql_api/types/bundle_analysis/report.py | 16 --------------- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/graphql_api/types/bundle_analysis/__init__.py b/graphql_api/types/bundle_analysis/__init__.py index 333d7b197a..ddb8ddb136 100644 --- a/graphql_api/types/bundle_analysis/__init__.py +++ b/graphql_api/types/bundle_analysis/__init__.py @@ -5,6 +5,7 @@ bundle_data_bindable, bundle_load_time_bindable, bundle_module_bindable, + bundle_report_bindable, bundle_size_bindable, ) from .comparison import ( @@ -15,7 +16,6 @@ from .report import ( bundle_analysis_report_bindable, bundle_analysis_report_result_bindable, - bundle_report_bindable, ) bundle_analysis = ariadne_load_local_graphql(__file__, "base.graphql") diff --git a/graphql_api/types/bundle_analysis/base.graphql b/graphql_api/types/bundle_analysis/base.graphql index f484af8714..66a1468d73 100644 --- a/graphql_api/types/bundle_analysis/base.graphql +++ b/graphql_api/types/bundle_analysis/base.graphql @@ -24,4 +24,11 @@ type BundleAsset { moduleExtensions: [String!]! modules: [BundleModule]! bundleData: BundleData! +} + +type BundleReport { + name: String! + sizeTotal: Int! + loadTimeTotal: Float! + bundleData: BundleData! } \ No newline at end of file diff --git a/graphql_api/types/bundle_analysis/base.py b/graphql_api/types/bundle_analysis/base.py index d4259217f7..aee3974ea9 100644 --- a/graphql_api/types/bundle_analysis/base.py +++ b/graphql_api/types/bundle_analysis/base.py @@ -1,7 +1,25 @@ -from ariadne import ObjectType, UnionType +from ariadne import ObjectType + +from services.bundle_analysis import BundleReport bundle_size_bindable = ObjectType("BundleSize") bundle_load_time_bindable = ObjectType("BundleLoadTime") bundle_data_bindable = ObjectType("BundleData") bundle_module_bindable = ObjectType("BundleModule") bundle_asset_bindable = ObjectType("BundleAsset") +bundle_report_bindable = ObjectType("BundleReport") + + +@bundle_report_bindable.field("name") +def resolve_name(bundle_report: BundleReport, info) -> str: + return bundle_report.bundle_name + + +@bundle_report_bindable.field("sizeTotal") +def resolve_size_total(bundle_report: BundleReport, info) -> int: + return bundle_report.size_total + + +@bundle_report_bindable.field("loadTimeTotal") +def resolve_load_time_total(bundle_report: BundleReport, info) -> float: + return bundle_report.load_time_total diff --git a/graphql_api/types/bundle_analysis/report.graphql b/graphql_api/types/bundle_analysis/report.graphql index 877c179860..94ba67c9cf 100644 --- a/graphql_api/types/bundle_analysis/report.graphql +++ b/graphql_api/types/bundle_analysis/report.graphql @@ -6,17 +6,5 @@ type BundleAnalysisReport { sizeTotal: Int! loadTimeTotal: Float! bundles: [BundleReport]! - bundle(name: String!, filters: BundleAnalysisReportFilters): BundleReport - moduleExtensions: [String!]! - moduleCount: Int! - assets: [BundleAsset]! - asset(name: String!): BundleAsset bundleData: BundleData! } - -type BundleReport { - name: String! - sizeTotal: Int! - loadTimeTotal: Float! - bundleData: BundleData! -} \ No newline at end of file diff --git a/graphql_api/types/bundle_analysis/report.py b/graphql_api/types/bundle_analysis/report.py index 8632b0617e..c4c5d7ecd7 100644 --- a/graphql_api/types/bundle_analysis/report.py +++ b/graphql_api/types/bundle_analysis/report.py @@ -7,7 +7,6 @@ bundle_analysis_report_result_bindable = UnionType("BundleAnalysisReportResult") bundle_analysis_report_bindable = ObjectType("BundleAnalysisReport") -bundle_report_bindable = ObjectType("BundleReport") @bundle_analysis_report_result_bindable.type_resolver @@ -35,18 +34,3 @@ def resolve_bundles( bundles_analysis_report: BundleAnalysisReport, info ) -> List[BundleReport]: return bundles_analysis_report.bundles - - -@bundle_report_bindable.field("name") -def resolve_name(bundle_report: BundleReport, info) -> str: - return bundle_report.bundle_name - - -@bundle_report_bindable.field("sizeTotal") -def resolve_size_total(bundle_report: BundleReport, info) -> int: - return bundle_report.size_total - - -@bundle_report_bindable.field("loadTimeTotal") -def resolve_load_time_total(bundle_report: BundleReport, info) -> float: - return bundle_report.load_time_total From 10f7550b1c5163455db2e87af2ddbcc2a91162b9 Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Thu, 15 Feb 2024 13:46:46 -0500 Subject: [PATCH 3/6] add module extensions and other new ones --- graphql_api/types/bundle_analysis/base.graphql | 4 ++++ graphql_api/types/bundle_analysis/report.graphql | 1 + graphql_api/types/inputs/bundle_analysis_filters.graphql | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/graphql_api/types/bundle_analysis/base.graphql b/graphql_api/types/bundle_analysis/base.graphql index 66a1468d73..968901f1bb 100644 --- a/graphql_api/types/bundle_analysis/base.graphql +++ b/graphql_api/types/bundle_analysis/base.graphql @@ -30,5 +30,9 @@ type BundleReport { name: String! sizeTotal: Int! loadTimeTotal: Float! + moduleExtensions: [String!]! + moduleCount: Int! + assets(filters: BundleAnalysisReportFilters): [BundleAsset]! + asset(name: String!): BundleAsset bundleData: BundleData! } \ No newline at end of file diff --git a/graphql_api/types/bundle_analysis/report.graphql b/graphql_api/types/bundle_analysis/report.graphql index 94ba67c9cf..383ee4f279 100644 --- a/graphql_api/types/bundle_analysis/report.graphql +++ b/graphql_api/types/bundle_analysis/report.graphql @@ -7,4 +7,5 @@ type BundleAnalysisReport { loadTimeTotal: Float! bundles: [BundleReport]! bundleData: BundleData! + bundle(name: String!): BundleReport } diff --git a/graphql_api/types/inputs/bundle_analysis_filters.graphql b/graphql_api/types/inputs/bundle_analysis_filters.graphql index 0f615eb69e..fe091f115b 100644 --- a/graphql_api/types/inputs/bundle_analysis_filters.graphql +++ b/graphql_api/types/inputs/bundle_analysis_filters.graphql @@ -1,3 +1,3 @@ input BundleAnalysisReportFilters { - extensions: [String!]! + module_extensions: [String!] } \ No newline at end of file From 375095d99be7960233a0a6a40368151d5dc99a1d Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Fri, 16 Feb 2024 13:45:15 -0500 Subject: [PATCH 4/6] add in bundleData calc and other place holders --- graphql_api/types/__init__.py | 4 -- graphql_api/types/bundle_analysis/__init__.py | 2 - graphql_api/types/bundle_analysis/base.py | 61 ++++++++++++++++++- graphql_api/types/bundle_analysis/report.py | 19 +++++- .../inputs/bundle_analysis_filters.graphql | 2 +- services/bundle_analysis.py | 43 +++++++++++++ 6 files changed, 120 insertions(+), 11 deletions(-) diff --git a/graphql_api/types/__init__.py b/graphql_api/types/__init__.py index d97fcd3551..849d81d221 100644 --- a/graphql_api/types/__init__.py +++ b/graphql_api/types/__init__.py @@ -14,10 +14,8 @@ bundle_asset_bindable, bundle_comparison_bindable, bundle_data_bindable, - bundle_load_time_bindable, bundle_module_bindable, bundle_report_bindable, - bundle_size_bindable, ) from .commit import commit, commit_bindable from .comparison import comparison, comparison_bindable, comparison_result_bindable @@ -115,8 +113,6 @@ branch_bindable, bundle_module_bindable, bundle_asset_bindable, - bundle_size_bindable, - bundle_load_time_bindable, bundle_data_bindable, bundle_analysis_comparison_result_bindable, bundle_analysis_comparison_bindable, diff --git a/graphql_api/types/bundle_analysis/__init__.py b/graphql_api/types/bundle_analysis/__init__.py index ddb8ddb136..10b6fdaba3 100644 --- a/graphql_api/types/bundle_analysis/__init__.py +++ b/graphql_api/types/bundle_analysis/__init__.py @@ -3,10 +3,8 @@ from .base import ( bundle_asset_bindable, bundle_data_bindable, - bundle_load_time_bindable, bundle_module_bindable, bundle_report_bindable, - bundle_size_bindable, ) from .comparison import ( bundle_analysis_comparison_bindable, diff --git a/graphql_api/types/bundle_analysis/base.py b/graphql_api/types/bundle_analysis/base.py index aee3974ea9..65fe1e8b3d 100644 --- a/graphql_api/types/bundle_analysis/base.py +++ b/graphql_api/types/bundle_analysis/base.py @@ -1,25 +1,80 @@ +from typing import List, Mapping + from ariadne import ObjectType -from services.bundle_analysis import BundleReport +from services.bundle_analysis import ( + BundleData, + BundleLoadTime, + BundleReport, + BundleSize, +) -bundle_size_bindable = ObjectType("BundleSize") -bundle_load_time_bindable = ObjectType("BundleLoadTime") bundle_data_bindable = ObjectType("BundleData") bundle_module_bindable = ObjectType("BundleModule") bundle_asset_bindable = ObjectType("BundleAsset") bundle_report_bindable = ObjectType("BundleReport") +# ============= Bundle Data Bindable ============= + + +@bundle_data_bindable.field("size") +def resolve_bundle_size(bundle_data: BundleData, info) -> BundleSize: + return bundle_data.size + + +@bundle_data_bindable.field("loadTime") +def resolve_bundle_load_time(bundle_data: BundleData, info) -> BundleLoadTime: + return bundle_data.load_time + + +# ============= Bundle Report Bindable ============= + @bundle_report_bindable.field("name") def resolve_name(bundle_report: BundleReport, info) -> str: return bundle_report.bundle_name +# TODO: depreacted with Issue 1199 @bundle_report_bindable.field("sizeTotal") def resolve_size_total(bundle_report: BundleReport, info) -> int: return bundle_report.size_total +# TODO: depreacted with Issue 1199 @bundle_report_bindable.field("loadTimeTotal") def resolve_load_time_total(bundle_report: BundleReport, info) -> float: return bundle_report.load_time_total + + +@bundle_report_bindable.field("moduleExtensions") +def resolve_module_extensions(bundle_report: BundleReport, info) -> List[str]: + # TODO: Unimplemented + return [] + + +@bundle_report_bindable.field("moduleCount") +def resolve_module_count(bundle_report: BundleReport, info) -> List[str]: + # TODO: Unimplemented + return 0 + + +@bundle_report_bindable.field("assets") +def resolve_assets( + bundle_report: BundleReport, + info, + filters: Mapping = None, +) -> List[str]: + # TODO: Unimplemented + return [] + + +@bundle_report_bindable.field("asset") +def resolve_asset(bundle_report: BundleReport, info, name: str) -> List[str]: + # TODO: Unimplemented + return None + + +@bundle_report_bindable.field("bundleData") +def resolve_bundle_data(bundle_report: BundleReport, info) -> BundleData: + return BundleData(bundle_report.size_total) diff --git a/graphql_api/types/bundle_analysis/report.py b/graphql_api/types/bundle_analysis/report.py index c4c5d7ecd7..d199908dd9 100644 --- a/graphql_api/types/bundle_analysis/report.py +++ b/graphql_api/types/bundle_analysis/report.py @@ -3,7 +3,7 @@ from ariadne import ObjectType, UnionType from graphql_api.types.comparison.comparison import MissingHeadReport -from services.bundle_analysis import BundleAnalysisReport, BundleReport +from services.bundle_analysis import BundleAnalysisReport, BundleData, BundleReport bundle_analysis_report_result_bindable = UnionType("BundleAnalysisReportResult") bundle_analysis_report_bindable = ObjectType("BundleAnalysisReport") @@ -17,11 +17,13 @@ def resolve_bundle_analysis_report_result_type(obj, *_): return "MissingHeadReport" +# TODO: depreacted with Issue 1199 @bundle_analysis_report_bindable.field("sizeTotal") def resolve_size_total(bundles_analysis_report: BundleAnalysisReport, info) -> int: return bundles_analysis_report.size_total +# TODO: depreacted with Issue 1199 @bundle_analysis_report_bindable.field("loadTimeTotal") def resolve_load_time_total( bundles_analysis_report: BundleAnalysisReport, info @@ -34,3 +36,18 @@ def resolve_bundles( bundles_analysis_report: BundleAnalysisReport, info ) -> List[BundleReport]: return bundles_analysis_report.bundles + + +@bundle_analysis_report_bindable.field("bundle") +def resolve_bundle( + bundles_analysis_report: BundleAnalysisReport, info, name: str +) -> BundleReport: + # TODO: Unimplemented + return None + + +@bundle_analysis_report_bindable.field("bundleData") +def resolve_bundle_data( + bundles_analysis_report: BundleAnalysisReport, info +) -> BundleData: + return BundleData(bundles_analysis_report.size_total) diff --git a/graphql_api/types/inputs/bundle_analysis_filters.graphql b/graphql_api/types/inputs/bundle_analysis_filters.graphql index fe091f115b..b6d7562ccd 100644 --- a/graphql_api/types/inputs/bundle_analysis_filters.graphql +++ b/graphql_api/types/inputs/bundle_analysis_filters.graphql @@ -1,3 +1,3 @@ input BundleAnalysisReportFilters { - module_extensions: [String!] + moduleExtensions: [String!] } \ No newline at end of file diff --git a/services/bundle_analysis.py b/services/bundle_analysis.py index 89ad52231d..aaa33f091a 100644 --- a/services/bundle_analysis.py +++ b/services/bundle_analysis.py @@ -34,6 +34,7 @@ def load_report( return loader.load(commit_report.external_id) +# TODO: depreacted with Issue 1199 def load_time_conversion(size): """ Converts total size in bytes to approximate time (in seconds) to download using a 3G internet (3 Mbps) @@ -41,6 +42,48 @@ def load_time_conversion(size): return round((8 * size) / (1024 * 1024 * 3), 1) +@dataclass +class BundleLoadTime: + """ + Value in Milliseconds + Reference for speed estimation: + https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/throttling/index.html + """ + + three_g: int + high_speed: int + + +@dataclass +class BundleSize: + """ + Value in Bytes + """ + + gzip: int + uncompress: int + + +@dataclass +class BundleData: + def __init__(self, size_in_bytes: int): + self.size_in_bytes = size_in_bytes + + @cached_property + def size(self) -> BundleSize: + return BundleSize( + gzip=int(self.size_in_bytes * 0.001), + uncompress=int(self.size_in_bytes), + ) + + @cached_property + def load_time(self) -> BundleLoadTime: + return BundleLoadTime( + three_g=int(((8 * self.size_in_bytes) / (750 * 1000)) * 1000), + high_speed=int(((8 * self.size_in_bytes) / (30 * 1000 * 1000)) * 1000), + ) + + @dataclass class BundleAnalysisReport(object): def __init__(self, report: SharedBundleAnalysisReport): From cfdd184ce8a71fca0192ffdcab597877d644e3cc Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Fri, 16 Feb 2024 15:03:48 -0500 Subject: [PATCH 5/6] update test --- graphql_api/tests/test_commit.py | 164 +++++++++++++++++++++++++++---- 1 file changed, 143 insertions(+), 21 deletions(-) diff --git a/graphql_api/tests/test_commit.py b/graphql_api/tests/test_commit.py index 9d1a3882ad..36721b57c5 100644 --- a/graphql_api/tests/test_commit.py +++ b/graphql_api/tests/test_commit.py @@ -932,31 +932,70 @@ def test_bundle_analysis_report(self, get_storage_service): ) storage.write_file(get_bucket_name(), storage_path, f) - query = ( - query_commit - % """ - bundleAnalysisReport { - __typename - ... on BundleAnalysisReport { - sizeTotal - loadTimeTotal - bundles { - name - sizeTotal - loadTimeTotal + query = """ + query FetchCommit($org: String!, $repo: String!, $commit: String!, $filters: BundleAnalysisReportFilters) { + owner(username: $org) { + repository(name: $repo) { + ... on Repository { + commit(id: $commit) { + bundleAnalysisReport { + __typename + ... on BundleAnalysisReport { + sizeTotal + loadTimeTotal + bundles { + name + sizeTotal + loadTimeTotal + moduleExtensions + moduleCount + assets(filters: $filters) { + name + } + asset(name: "not_exist") { + name + } + bundleData { + loadTime { + threeG + highSpeed + } + size { + gzip + uncompress + } + } + } + bundleData { + loadTime { + threeG + highSpeed + } + size { + gzip + uncompress + } + } + bundle(name: "not_exist") { + name + } + } + ... on MissingHeadReport { + message + } + } + } + } } } - ... on MissingHeadReport { - message - } } - """ - ) + """ variables = { "org": self.org.username, "repo": self.repo.name, "commit": self.commit.commitid, + "filters": {"moduleExtensions": []}, } data = self.gql_request(query, variables=variables) commit = data["owner"]["repository"]["commit"] @@ -966,11 +1005,94 @@ def test_bundle_analysis_report(self, get_storage_service): "sizeTotal": 201720, "loadTimeTotal": 0.5, "bundles": [ - {"name": "b1", "sizeTotal": 20, "loadTimeTotal": 0.0}, - {"name": "b2", "sizeTotal": 200, "loadTimeTotal": 0.0}, - {"name": "b3", "sizeTotal": 1500, "loadTimeTotal": 0.0}, - {"name": "b5", "sizeTotal": 200000, "loadTimeTotal": 0.5}, + { + "name": "b1", + "sizeTotal": 20, + "loadTimeTotal": 0.0, + "moduleExtensions": [], + "moduleCount": 0, + "assets": [], + "asset": None, + "bundleData": { + "loadTime": { + "threeG": 0, + "highSpeed": 0, + }, + "size": { + "gzip": 0, + "uncompress": 20, + }, + }, + }, + { + "name": "b2", + "sizeTotal": 200, + "loadTimeTotal": 0.0, + "moduleExtensions": [], + "moduleCount": 0, + "assets": [], + "asset": None, + "bundleData": { + "loadTime": { + "threeG": 2, + "highSpeed": 0, + }, + "size": { + "gzip": 0, + "uncompress": 200, + }, + }, + }, + { + "name": "b3", + "sizeTotal": 1500, + "loadTimeTotal": 0.0, + "moduleExtensions": [], + "moduleCount": 0, + "assets": [], + "asset": None, + "bundleData": { + "loadTime": { + "threeG": 16, + "highSpeed": 0, + }, + "size": { + "gzip": 1, + "uncompress": 1500, + }, + }, + }, + { + "name": "b5", + "sizeTotal": 200000, + "loadTimeTotal": 0.5, + "moduleExtensions": [], + "moduleCount": 0, + "assets": [], + "asset": None, + "bundleData": { + "loadTime": { + "threeG": 2133, + "highSpeed": 53, + }, + "size": { + "gzip": 200, + "uncompress": 200000, + }, + }, + }, ], + "bundleData": { + "loadTime": { + "threeG": 2151, + "highSpeed": 53, + }, + "size": { + "gzip": 201, + "uncompress": 201720, + }, + }, + "bundle": None, } def test_compare_with_parent_missing_change_coverage(self): From ba3dedf2f861e4ada48fbb118cb9db68b4f91f83 Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Fri, 16 Feb 2024 16:23:35 -0500 Subject: [PATCH 6/6] Make load time and size calculations understandable --- services/bundle_analysis.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/services/bundle_analysis.py b/services/bundle_analysis.py index aaa33f091a..c9f60e0dc5 100644 --- a/services/bundle_analysis.py +++ b/services/bundle_analysis.py @@ -50,6 +50,11 @@ class BundleLoadTime: https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/throttling/index.html """ + # Speed of internet in bits per second (as reference above) + THREE_G_SPEED = 750 * 1000 # Equivalent to 750 Kbps + HIGH_SPEED = 30 * 1000 * 1000 # Equivalent to 30 Mbps + + # Computed load time in milliseconds three_g: int high_speed: int @@ -60,6 +65,11 @@ class BundleSize: Value in Bytes """ + # Compression ratio compared to uncompressed size + GZIP = 0.001 + UNCOMPRESS = 1.0 + + # Computed size in bytes gzip: int uncompress: int @@ -68,19 +78,20 @@ class BundleSize: class BundleData: def __init__(self, size_in_bytes: int): self.size_in_bytes = size_in_bytes + self.size_in_bits = size_in_bytes * 8 @cached_property def size(self) -> BundleSize: return BundleSize( - gzip=int(self.size_in_bytes * 0.001), - uncompress=int(self.size_in_bytes), + gzip=int(self.size_in_bytes * BundleSize.GZIP), + uncompress=int(self.size_in_bytes * BundleSize.UNCOMPRESS), ) @cached_property def load_time(self) -> BundleLoadTime: return BundleLoadTime( - three_g=int(((8 * self.size_in_bytes) / (750 * 1000)) * 1000), - high_speed=int(((8 * self.size_in_bytes) / (30 * 1000 * 1000)) * 1000), + three_g=int((self.size_in_bits / BundleLoadTime.THREE_G_SPEED) * 1000), + high_speed=int((self.size_in_bits / BundleLoadTime.HIGH_SPEED) * 1000), )