@@ -42,6 +42,24 @@ function retrieveDataPointsForAudits(results: Result, audits: string[]) {
42
42
return values
43
43
}
44
44
45
+ /**
46
+ * Adds `rand={123..}` param to the urls to ensure we never hit a CDN cache.
47
+ */
48
+ function addRandomParamToUrl ( inspectList : Record < string , string [ ] > ) : Record < string , string [ ] > {
49
+ const updatedInspectList : Record < string , string [ ] > = structuredClone ( inspectList ) ;
50
+
51
+ for ( const pageType in updatedInspectList ) {
52
+ const urls = updatedInspectList [ pageType ] ;
53
+
54
+ updatedInspectList [ pageType ] = urls . map ( url => {
55
+ const urlObject = new URL ( url ) ;
56
+ urlObject . searchParams . append ( 'rand' , Math . floor ( Math . random ( ) * 1000000 ) . toString ( ) ) ;
57
+ return urlObject . toString ( ) ;
58
+ } ) ;
59
+ }
60
+ return updatedInspectList ;
61
+ }
62
+
45
63
async function sendMetricsToDatadog ( metricName : string , dataPoints : v2 . MetricPoint [ ] , tags : Record < string , string > ) {
46
64
const dd = new Datadog ( {
47
65
api_key : process . env . DD_API_KEY || '' ,
@@ -83,7 +101,8 @@ async function captureLighthouseMetrics(pageType: string, url: string, audits: s
83
101
console . log ( `Done running Lighthouse for ${ url } with form factor: ${ formFactor } \n` ) ;
84
102
}
85
103
( async ( ) => {
86
- const inspectList : Record < string , string [ ] > = JSON . parse ( await fs . promises . readFile ( 'urls.json' , 'utf8' ) ) ;
104
+ let inspectList : Record < string , string [ ] > = JSON . parse ( await fs . promises . readFile ( 'urls.json' , 'utf8' ) ) ;
105
+ inspectList = addRandomParamToUrl ( inspectList ) ;
87
106
88
107
const coreMetrics : Record < string , string [ ] > = JSON . parse ( await fs . promises . readFile ( 'metrics-config.json' , 'utf8' ) ) ;
89
108
0 commit comments