Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions graphql_api/tests/test_bundle_analysis_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
10 changes: 9 additions & 1 deletion graphql_api/types/bundle_analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw ASSET_SIZE is another variable on this type; jw why its not included in this list?

Copy link
Contributor Author

@JerrySentry JerrySentry Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSET_SIZE is for tracking the size of individual javascript assets, so the sum of all asset measurements equals to the JAVASCRIPT_SIZE. And all the other types are aggregate types, notably REPORT_SIZE is the sum of all assets.
So we can compute the trends line of unknown asset sizes by doing a computation of:
UNKNOWN_SIZE = REPORT_SIZE - JS_SIZE - STYLESHEET_SIZE - FONT_SIZE - IMAGE_SIZE
and
ASSET_SIZE can be ignored because JS_SIZE = sum(ASSET_SIZE)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhhh okay makes a lot of sense! Thanks

BundleAnalysisMeasurementsAssetType.JAVASCRIPT_SIZE,
BundleAnalysisMeasurementsAssetType.STYLESHEET_SIZE,
BundleAnalysisMeasurementsAssetType.FONT_SIZE,
BundleAnalysisMeasurementsAssetType.IMAGE_SIZE,
]
else:
measurables_to_fetch = [
BundleAnalysisMeasurementsAssetType[item] for item in asset_types
Expand Down
Loading