Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 135483f

Browse files
Merge branch 'main' into rvinnakota/add-ip-address-sentry
2 parents cb66b1e + 87d198a commit 135483f

File tree

7 files changed

+1151
-38
lines changed

7 files changed

+1151
-38
lines changed

graphql_api/tests/test_bundle_analysis_measurements.py

Lines changed: 842 additions & 0 deletions
Large diffs are not rendered by default.

graphql_api/types/bundle_analysis/base.graphql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
enum BundleAnalysisMeasurementsAssetType {
2+
REPORT_SIZE
3+
JAVASCRIPT_SIZE
4+
STYLESHEET_SIZE
5+
FONT_SIZE
6+
IMAGE_SIZE
7+
ASSET_SIZE
8+
}
9+
110
type BundleSize {
211
gzip: Int!
312
uncompress: Int!
@@ -26,6 +35,12 @@ type BundleAsset {
2635
moduleExtensions: [String!]!
2736
modules: [BundleModule]!
2837
bundleData: BundleData!
38+
measurements(
39+
interval: MeasurementInterval!
40+
before: DateTime!
41+
after: DateTime!
42+
branch: String
43+
): BundleAnalysisMeasurements
2944
}
3045

3146
type BundleReport {
@@ -37,4 +52,20 @@ type BundleReport {
3752
assets(filters: BundleAnalysisReportFilters): [BundleAsset]!
3853
asset(name: String!): BundleAsset
3954
bundleData: BundleData!
55+
measurements(
56+
interval: MeasurementInterval!
57+
before: DateTime!
58+
after: DateTime!
59+
branch: String
60+
orderingDirection: OrderingDirection
61+
filters: BundleAnalysisMeasurementsSetFilters
62+
): [BundleAnalysisMeasurements!]
4063
}
64+
65+
type BundleAnalysisMeasurements{
66+
assetType: BundleAnalysisMeasurementsAssetType!
67+
name: String
68+
size: BundleData
69+
change: BundleData
70+
measurements: [Measurement!]
71+
}
Lines changed: 111 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
from datetime import datetime
12
from typing import List, Mapping, Optional
23

3-
from ariadne import ObjectType
4+
from ariadne import ObjectType, convert_kwargs_to_snake_case
5+
from graphql import GraphQLResolveInfo
46

7+
from codecov.db import sync_to_async
8+
from graphql_api.types.enums import OrderingDirection
59
from services.bundle_analysis import (
610
AssetReport,
11+
BundleAnalysisMeasurementData,
12+
BundleAnalysisMeasurementsAssetType,
13+
BundleAnalysisMeasurementsService,
714
BundleData,
815
BundleLoadTime,
916
BundleReport,
1017
BundleSize,
1118
ModuleReport,
1219
)
20+
from timeseries.models import Interval
1321

1422
bundle_data_bindable = ObjectType("BundleData")
1523
bundle_module_bindable = ObjectType("BundleModule")
@@ -21,108 +29,192 @@
2129

2230

2331
@bundle_data_bindable.field("size")
24-
def resolve_bundle_size(bundle_data: BundleData, info) -> BundleSize:
32+
def resolve_bundle_size(
33+
bundle_data: BundleData, info: GraphQLResolveInfo
34+
) -> BundleSize:
2535
return bundle_data.size
2636

2737

2838
@bundle_data_bindable.field("loadTime")
29-
def resolve_bundle_load_time(bundle_data: BundleData, info) -> BundleLoadTime:
39+
def resolve_bundle_load_time(
40+
bundle_data: BundleData, info: GraphQLResolveInfo
41+
) -> BundleLoadTime:
3042
return bundle_data.load_time
3143

3244

3345
# ============= Bundle Module Bindable =============
3446

3547

3648
@bundle_module_bindable.field("name")
37-
def resolve_bundle_module_name(bundle_module: ModuleReport, info) -> str:
49+
def resolve_bundle_module_name(
50+
bundle_module: ModuleReport, info: GraphQLResolveInfo
51+
) -> str:
3852
return bundle_module.name
3953

4054

4155
@bundle_module_bindable.field("bundleData")
42-
def resolve_bundle_module_bundle_data(bundle_module: ModuleReport, info) -> int:
56+
def resolve_bundle_module_bundle_data(
57+
bundle_module: ModuleReport, info: GraphQLResolveInfo
58+
) -> BundleData:
4359
return BundleData(bundle_module.size_total)
4460

4561

4662
# ============= Bundle Asset Bindable =============
4763

4864

4965
@bundle_asset_bindable.field("name")
50-
def resolve_bundle_asset_name(bundle_asset: AssetReport, info) -> str:
66+
def resolve_bundle_asset_name(
67+
bundle_asset: AssetReport, info: GraphQLResolveInfo
68+
) -> str:
5169
return bundle_asset.name
5270

5371

5472
@bundle_asset_bindable.field("normalizedName")
55-
def resolve_normalized_name(bundle_asset: AssetReport, info) -> str:
73+
def resolve_normalized_name(bundle_asset: AssetReport, info: GraphQLResolveInfo) -> str:
5674
return bundle_asset.normalized_name
5775

5876

5977
@bundle_asset_bindable.field("extension")
60-
def resolve_extension(bundle_asset: AssetReport, info) -> str:
78+
def resolve_extension(bundle_asset: AssetReport, info: GraphQLResolveInfo) -> str:
6179
return bundle_asset.extension
6280

6381

6482
@bundle_asset_bindable.field("bundleData")
65-
def resolve_bundle_asset_bundle_data(bundle_asset: AssetReport, info) -> BundleData:
83+
def resolve_bundle_asset_bundle_data(
84+
bundle_asset: AssetReport, info: GraphQLResolveInfo
85+
) -> BundleData:
6686
return BundleData(bundle_asset.size_total)
6787

6888

6989
@bundle_asset_bindable.field("modules")
70-
def resolve_modules(bundle_asset: AssetReport, info) -> List[ModuleReport]:
90+
def resolve_modules(
91+
bundle_asset: AssetReport, info: GraphQLResolveInfo
92+
) -> List[ModuleReport]:
7193
return bundle_asset.modules
7294

7395

7496
@bundle_asset_bindable.field("moduleExtensions")
7597
def resolve_bundle_asset_module_extensions(
76-
bundle_asset: AssetReport, info
98+
bundle_asset: AssetReport, info: GraphQLResolveInfo
7799
) -> List[str]:
78100
return bundle_asset.module_extensions
79101

80102

103+
@bundle_asset_bindable.field("measurements")
104+
@convert_kwargs_to_snake_case
105+
@sync_to_async
106+
def resolve_asset_report_measurements(
107+
bundle_asset: AssetReport,
108+
info: GraphQLResolveInfo,
109+
interval: Interval,
110+
before: datetime,
111+
after: datetime,
112+
branch: Optional[str] = None,
113+
) -> Optional[BundleAnalysisMeasurementData]:
114+
bundle_analysis_measurements = BundleAnalysisMeasurementsService(
115+
repository=info.context["commit"].repository,
116+
interval=interval,
117+
after=after,
118+
before=before,
119+
branch=branch,
120+
)
121+
return bundle_analysis_measurements.compute_asset(bundle_asset)
122+
123+
81124
# ============= Bundle Report Bindable =============
82125

83126

84127
@bundle_report_bindable.field("name")
85-
def resolve_name(bundle_report: BundleReport, info) -> str:
128+
def resolve_name(bundle_report: BundleReport, info: GraphQLResolveInfo) -> str:
86129
return bundle_report.name
87130

88131

89132
# TODO: depreacted with Issue 1199
90133
@bundle_report_bindable.field("sizeTotal")
91-
def resolve_size_total(bundle_report: BundleReport, info) -> int:
134+
def resolve_size_total(bundle_report: BundleReport, info: GraphQLResolveInfo) -> int:
92135
return bundle_report.size_total
93136

94137

95138
# TODO: depreacted with Issue 1199
96139
@bundle_report_bindable.field("loadTimeTotal")
97-
def resolve_load_time_total(bundle_report: BundleReport, info) -> float:
140+
def resolve_load_time_total(
141+
bundle_report: BundleReport, info: GraphQLResolveInfo
142+
) -> float:
98143
return bundle_report.load_time_total
99144

100145

101146
@bundle_report_bindable.field("moduleExtensions")
102-
def resolve_module_extensions(bundle_report: BundleReport, info) -> List[str]:
147+
def resolve_module_extensions(
148+
bundle_report: BundleReport, info: GraphQLResolveInfo
149+
) -> List[str]:
103150
return bundle_report.module_extensions
104151

105152

106153
@bundle_report_bindable.field("moduleCount")
107-
def resolve_module_count(bundle_report: BundleReport, info) -> int:
154+
def resolve_module_count(bundle_report: BundleReport, info: GraphQLResolveInfo) -> int:
108155
return bundle_report.module_count
109156

110157

111158
@bundle_report_bindable.field("assets")
112159
def resolve_assets(
113160
bundle_report: BundleReport,
114-
info,
161+
info: GraphQLResolveInfo,
115162
filters: Optional[Mapping] = None,
116163
) -> List[AssetReport]:
117164
extensions_filter = filters.get("moduleExtensions", None) if filters else None
118165
return list(bundle_report.assets(extensions_filter))
119166

120167

121168
@bundle_report_bindable.field("asset")
122-
def resolve_asset(bundle_report: BundleReport, info, name: str) -> AssetReport:
169+
def resolve_asset(
170+
bundle_report: BundleReport, info: GraphQLResolveInfo, name: str
171+
) -> Optional[AssetReport]:
123172
return bundle_report.asset(name)
124173

125174

126175
@bundle_report_bindable.field("bundleData")
127-
def resolve_bundle_data(bundle_report: BundleReport, info) -> BundleData:
176+
def resolve_bundle_data(
177+
bundle_report: BundleReport, info: GraphQLResolveInfo
178+
) -> BundleData:
128179
return BundleData(bundle_report.size_total)
180+
181+
182+
@bundle_report_bindable.field("measurements")
183+
@convert_kwargs_to_snake_case
184+
@sync_to_async
185+
def resolve_bundle_report_measurements(
186+
bundle_report: BundleReport,
187+
info: GraphQLResolveInfo,
188+
interval: Interval,
189+
before: datetime,
190+
after: datetime,
191+
branch: Optional[str] = None,
192+
filters: Mapping = {},
193+
ordering_direction: Optional[OrderingDirection] = OrderingDirection.ASC,
194+
) -> List[BundleAnalysisMeasurementData]:
195+
if not filters.get("asset_types", []):
196+
measurable_names = [item for item in list(BundleAnalysisMeasurementsAssetType)]
197+
else:
198+
measurable_names = [
199+
BundleAnalysisMeasurementsAssetType[item] for item in filters["asset_types"]
200+
]
201+
202+
bundle_analysis_measurements = BundleAnalysisMeasurementsService(
203+
repository=info.context["commit"].repository,
204+
interval=interval,
205+
after=after,
206+
before=before,
207+
branch=branch,
208+
)
209+
210+
measurements = []
211+
for name in measurable_names:
212+
measurements.extend(
213+
bundle_analysis_measurements.compute_report(bundle_report, asset_type=name)
214+
)
215+
216+
return sorted(
217+
measurements,
218+
key=lambda c: c.asset_type,
219+
reverse=ordering_direction == OrderingDirection.DESC,
220+
)

graphql_api/types/commit/commit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ def resolve_bundle_analysis_report(
198198
"request"
199199
].bundle_analysis_head_report_db_path = bundle_analysis_report.report.db_path
200200

201+
info.context["commit"] = commit
202+
201203
return bundle_analysis_report
202204

203205

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
input BundleAnalysisReportFilters {
22
moduleExtensions: [String!]
3+
}
4+
5+
input BundleAnalysisMeasurementsSetFilters {
6+
assetTypes: [BundleAnalysisMeasurementsAssetType!]
37
}

0 commit comments

Comments
 (0)