Skip to content

Add function to add rand={randomNumber} to the urls to inspect #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Changes from 2 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
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ function retrieveDataPointsForAudits(results: Result, audits: string[]) {
return values
}

/**
* Adds `rand={123..}` param to the urls to ensure we never hit a CDN cache.
*/
function addRandomParamToUrl(inspectList: Record<string, string[]>): void {
for (const pageType in inspectList) {
const urls = inspectList[pageType];

inspectList[pageType] = urls.map(url => {
const urlObject = new URL(url);
urlObject.searchParams.append('rand', Math.floor(Math.random() * 1000000).toString());
return urlObject.toString();
});
}
}

async function sendMetricsToDatadog(metricName: string, dataPoints: v2.MetricPoint[], tags: Record<string, string>) {
const dd = new Datadog({
api_key: process.env.DD_API_KEY || '',
Expand Down Expand Up @@ -84,6 +99,7 @@ async function captureLighthouseMetrics(pageType: string, url: string, audits: s
}
(async() => {
const inspectList: Record<string, string[]> = JSON.parse(await fs.promises.readFile('urls.json', 'utf8'));
addRandomParamToUrl(inspectList);

const coreMetrics: Record<string, string[]> = JSON.parse(await fs.promises.readFile('metrics-config.json', 'utf8'));

Expand Down