Skip to content
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

clients(lr): run benchmark repeatedly given special query parameter #14075

Merged
merged 9 commits into from
Jun 8, 2022
Merged
1 change: 1 addition & 0 deletions lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const BASE_ARTIFACT_BLANKS = {
HostUserAgent: '',
NetworkUserAgent: '',
BenchmarkIndex: '',
BenchmarkIndexes: '',
WebAppManifest: '',
GatherContext: '',
InstallabilityErrors: '',
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/fraggle-rock/config/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const baseArtifactKeySource = {
fetchTime: '',
LighthouseRunWarnings: '',
BenchmarkIndex: '',
BenchmarkIndexes: '',
settings: '',
Timing: '',
URL: '',
Expand Down
15 changes: 15 additions & 0 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const WebAppManifest = require('./gatherers/web-app-manifest.js');
const InstallabilityErrors = require('./gatherers/installability-errors.js');
const NetworkUserAgent = require('./gatherers/network-user-agent.js');
const Stacks = require('./gatherers/stacks.js');
const URL = require('../lib/url-shim.js');
const {finalizeArtifacts} = require('../fraggle-rock/gather/base-artifacts.js');

/** @typedef {import('../gather/driver.js')} Driver */
Expand Down Expand Up @@ -491,6 +492,20 @@ class GatherRunner {
const baseArtifacts = await GatherRunner.initializeBaseArtifacts(options);
baseArtifacts.BenchmarkIndex = await getBenchmarkIndex(driver.executionContext);

// Hack for running benchmarkIndex extra times.
// Add a `bidx=20` query param, eg: https://www.example.com/?bidx=50
const parsedUrl = URL.isValid(options.requestedUrl) && new URL(options.requestedUrl);
if (options.settings.channel === 'lr' && parsedUrl && parsedUrl.searchParams.has('bidx')) {
const bidxRunCount = parsedUrl.searchParams.get('bidx') || 0;
// Add the first bidx into the new set
const indexes = [baseArtifacts.BenchmarkIndex];
for (let i = 0; i < bidxRunCount; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be simpler if the internal setting was just minus one'd here (And we asserted it either doesn't exist or is >= 1).

Copy link
Member Author

Choose a reason for hiding this comment

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

as we're the only users i think this isn't a huge deal. and it'd complicate the impl

const bidx = await getBenchmarkIndex(driver.executionContext);
indexes.push(bidx);
}
baseArtifacts.BenchmarkIndexes = indexes;
}

await GatherRunner.setupDriver(driver, options);

let isFirstPass = true;
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Runner {
networkUserAgent: artifacts.NetworkUserAgent,
hostUserAgent: artifacts.HostUserAgent,
benchmarkIndex: artifacts.BenchmarkIndex,
benchmarkIndexes: artifacts.BenchmarkIndexes,
credits,
},
audits: auditResultsById,
Expand Down
2 changes: 2 additions & 0 deletions types/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ interface UniversalBaseArtifacts {
LighthouseRunWarnings: Array<string | IcuMessage>;
/** The benchmark index that indicates rough device class. */
BenchmarkIndex: number;
/** Many benchmark indexes. Many. */
BenchmarkIndexes?: number[];
/** An object containing information about the testing configuration used by Lighthouse. */
settings: Config.Settings;
/** The timing instrumentation of the gather portion of a run. */
Expand Down
2 changes: 2 additions & 0 deletions types/lhr/lhr.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ declare module Result {
networkUserAgent: string;
/** The benchmark index number that indicates rough device class. */
benchmarkIndex: number;
/** Many benchmark indexes. */
benchmarkIndexes?: number[];
/** The version of libraries with which these results were generated. Ex: axe-core. */
credits?: Record<string, string|undefined>,
}
Expand Down