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

Report page load asset size #66224

Merged
merged 45 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
37365bf
performance_tests: draft version
dmlemeshko May 12, 2020
bf24b82
Merge remote-tracking branch 'upstream/master' into ftr/report-all-fi…
dmlemeshko May 14, 2020
4b1a9e0
Merge remote-tracking branch 'upstream/master' into ftr/report-all-fi…
dmlemeshko May 14, 2020
ba5f384
update cli runner and script
dmlemeshko May 14, 2020
8e9f0b1
ingest metrics
dmlemeshko May 19, 2020
d4e2f0c
save asset type for plugins
dmlemeshko May 19, 2020
fc06477
Update src/dev/performance/ingest_metrics.ts
dmlemeshko May 19, 2020
6b9e68c
Merge remote-tracking branch 'upstream/master' into ftr/report-all-fi…
dmlemeshko May 27, 2020
1551910
follow review comments
dmlemeshko May 28, 2020
816cb4b
Merge branch 'ftr/report-all-file-sizes' of github.com:dmlemeshko/kib…
dmlemeshko May 28, 2020
bebd189
fix size calc, add FTR config, move src to kbn/test
dmlemeshko May 28, 2020
4aa25a6
fix import, remove unused interface
dmlemeshko May 28, 2020
fb37a19
Merge branch 'master' into ftr/report-all-file-sizes
elasticmachine May 29, 2020
d9133d3
Update packages/kbn-test/src/page_load_metrics/capture_page_load_metr…
dmlemeshko May 29, 2020
1d4cb34
start chromium with no-sandbox
dmlemeshko May 29, 2020
cf8dd9c
Merge branch 'ftr/report-all-file-sizes' of github.com:dmlemeshko/kib…
dmlemeshko May 29, 2020
f379b60
add logging
dmlemeshko May 29, 2020
34047f7
check page contains expected element, cut apps to 5
dmlemeshko May 29, 2020
ffb7da9
fix locator & typo
dmlemeshko May 29, 2020
bc56b6b
Merge branch 'master' into ftr/report-all-file-sizes
elasticmachine Jun 1, 2020
4554940
Update packages/kbn-test/src/page_load_metrics/navigation.ts
dmlemeshko Jun 2, 2020
c1b092a
Merge branch 'master' into ftr/report-all-file-sizes
elasticmachine Jun 2, 2020
060a844
Update navigation.ts
mshustov Jun 2, 2020
c18ce02
Update navigation.ts
mshustov Jun 2, 2020
b15ce8c
bump puppeteer version
dmlemeshko Jun 3, 2020
8a7cc12
fix typo
dmlemeshko Jun 3, 2020
da9a923
update navigation script
dmlemeshko Jun 3, 2020
bd6c908
update config file
dmlemeshko Jun 3, 2020
bf8a0a8
update yarn.lock
dmlemeshko Jun 3, 2020
342afd2
Merge remote-tracking branch 'upstream/master' into ftr/report-all-fi…
dmlemeshko Jun 3, 2020
f848c4e
fix
dmlemeshko Jun 3, 2020
7b04014
take screenshot on failure
dmlemeshko Jun 3, 2020
f440143
update screenshot title
dmlemeshko Jun 4, 2020
5b16040
Merge remote-tracking branch 'upstream/master' into ftr/report-all-fi…
dmlemeshko Jun 4, 2020
6b3e7fa
fix screenshot saving and error
dmlemeshko Jun 4, 2020
3007539
invalid locator
dmlemeshko Jun 4, 2020
19979b5
Revert "invalid locator"
dmlemeshko Jun 4, 2020
6cfa219
run script in a loop 10 times
dmlemeshko Jun 4, 2020
ecdb569
Merge branch 'master' into ftr/report-all-file-sizes
elasticmachine Jun 4, 2020
1421388
Revert "run script in a loop 10 times"
dmlemeshko Jun 4, 2020
a6946e0
Merge branch 'ftr/report-all-file-sizes' of github.com:dmlemeshko/kib…
dmlemeshko Jun 4, 2020
ddc5617
Merge remote-tracking branch 'upstream/master' into ftr/report-all-fi…
dmlemeshko Jun 4, 2020
a19828f
path config value directly
dmlemeshko Jun 4, 2020
fec3c4e
fix screenshots directory setup
dmlemeshko Jun 5, 2020
d6ee29b
update maps locator, common for landing and new map
dmlemeshko Jun 5, 2020
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
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true) {
'xpack-ciGroup9': kibanaPipeline.xpackCiGroupProcess(9),
'xpack-ciGroup10': kibanaPipeline.xpackCiGroupProcess(10),
'xpack-accessibility': kibanaPipeline.functionalTestProcess('xpack-accessibility', './test/scripts/jenkins_xpack_accessibility.sh'),
'xpack-pageLoadMetrics': kibanaPipeline.functionalTestProcess('xpack-pageLoadMetrics', './test/scripts/jenkins_xpack_page_load_metrics.sh'),
'xpack-securitySolutionCypress': { processNumber ->
whenChanged(['x-pack/plugins/security_solution/', 'x-pack/test/security_solution_cypress/']) {
kibanaPipeline.functionalTestProcess('xpack-securitySolutionCypress', './test/scripts/jenkins_security_solution_cypress.sh')(processNumber)
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@kbn/babel-preset": "1.0.0",
"@kbn/dev-utils": "1.0.0",
"@types/parse-link-header": "^1.0.0",
"@types/puppeteer": "^3.0.0",
"@types/strip-ansi": "^5.2.1",
"@types/xml2js": "^0.4.5",
"diff": "^4.0.1"
Expand All @@ -25,6 +26,7 @@
"getopts": "^2.2.4",
"glob": "^7.1.2",
"parse-link-header": "^1.0.1",
"puppeteer": "^3.3.0",
"strip-ansi": "^5.2.0",
"rxjs": "^6.5.3",
"tar-fs": "^1.16.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ export { runFailedTestsReporterCli } from './failed_tests_reporter';
export { makeJunitReportPath } from './junit_report_path';

export { CI_PARALLEL_PROCESS_PREFIX } from './ci_parallel_process_prefix';

export * from './page_load_metrics';
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { ToolingLog } from '@kbn/dev-utils';
import { NavigationOptions, createUrl, navigateToApps } from './navigation';

export async function capturePageLoadMetrics(log: ToolingLog, options: NavigationOptions) {
const responsesByPageView = await navigateToApps(log, options);

const assetSizeMeasurements = new Map<string, number[]>();

const numberOfPagesVisited = responsesByPageView.size;

for (const [, frameResponses] of responsesByPageView) {
for (const [, { url, dataLength }] of frameResponses) {
if (url.length === 0) {
throw new Error('navigateToApps(); failed to identify the url of the request');
}
if (assetSizeMeasurements.has(url)) {
assetSizeMeasurements.set(url, [dataLength].concat(assetSizeMeasurements.get(url) || []));
} else {
assetSizeMeasurements.set(url, [dataLength]);
}
}
}

return Array.from(assetSizeMeasurements.entries())
.map(([url, measurements]) => {
const baseUrl = createUrl('/', options.appConfig.url);
const relativeUrl = url
// remove the baseUrl (expect the trailing slash) to make url relative
.replace(baseUrl.slice(0, -1), '')
// strip the build number from asset urls
.replace(/^\/\d+\//, '/');
return [relativeUrl, measurements] as const;
})
.filter(([url, measurements]) => {
if (measurements.length !== numberOfPagesVisited) {
// ignore urls seen only on some pages
return false;
}

if (url.startsWith('data:')) {
// ignore data urls since they are already counted by other assets
return false;
}

if (url.startsWith('/api/') || url.startsWith('/internal/')) {
// ignore api requests since they don't have deterministic sizes
return false;
}

const allMetricsAreEqual = measurements.every((x, i) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

The case when using loop might simplify reading.

i === 0 ? true : x === measurements[i - 1]
);
if (!allMetricsAreEqual) {
throw new Error(`measurements for url [${url}] are not equal [${measurements.join(',')}]`);
}

return true;
})
.map(([url, measurements]) => {
return { group: 'page load asset size', id: url, value: measurements[0] };
});
}
90 changes: 90 additions & 0 deletions packages/kbn-test/src/page_load_metrics/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import Url from 'url';

import { run, createFlagError } from '@kbn/dev-utils';
import { resolve, basename } from 'path';
import { capturePageLoadMetrics } from './capture_page_load_metrics';

const defaultScreenshotsDir = resolve(__dirname, 'screenshots');

export function runPageLoadMetricsCli() {
run(
async ({ flags, log }) => {
const kibanaUrl = flags['kibana-url'];
if (!kibanaUrl || typeof kibanaUrl !== 'string') {
throw createFlagError('Expect --kibana-url to be a string');
}

const parsedUrl = Url.parse(kibanaUrl);

const [username, password] = parsedUrl.auth
? parsedUrl.auth.split(':')
: [flags.username, flags.password];

if (typeof username !== 'string' || typeof password !== 'string') {
throw createFlagError(
'Mising username and/or password, either specify in --kibana-url or pass --username and --password'
);
}

const headless = !flags.head;
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't use the same headless flag?

Copy link
Member Author

@dmlemeshko dmlemeshko Jun 3, 2020

Choose a reason for hiding this comment

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

The default option is headless: true per design on Puppeteer side, I thought we might use --head over --headless=false


const screenshotsDir = flags.screenshotsDir || defaultScreenshotsDir;

if (typeof screenshotsDir !== 'string' || screenshotsDir === basename(screenshotsDir)) {
throw createFlagError('Expect screenshotsDir to be valid path string');
}

const metrics = await capturePageLoadMetrics(log, {
headless,
appConfig: {
url: kibanaUrl,
username,
password,
},
screenshotsDir,
});
for (const metric of metrics) {
log.info(`${metric.id}: ${metric.value}`);
}
},
{
description: `Loads several pages with Puppeteer to capture the size of assets`,
flags: {
string: ['kibana-url', 'username', 'password', 'screenshotsDir'],
boolean: ['head'],
default: {
username: 'elastic',
password: 'changeme',
debug: true,
screenshotsDir: defaultScreenshotsDir,
},
help: `
--kibana-url Url for Kibana we should connect to, can include login info
--head Run puppeteer with graphical user interface
--username Set username, defaults to 'elastic'
--password Set password, defaults to 'changeme'
--screenshotsDir Set screenshots directory, defaults to '${defaultScreenshotsDir}'
`,
},
}
);
}
34 changes: 34 additions & 0 deletions packages/kbn-test/src/page_load_metrics/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export interface ResponseReceivedEvent {
frameId: string;
loaderId: string;
requestId: string;
response: Record<string, any>;
timestamp: number;
type: string;
}

export interface DataReceivedEvent {
encodedDataLength: number;
dataLength: number;
requestId: string;
timestamp: number;
}
21 changes: 21 additions & 0 deletions packages/kbn-test/src/page_load_metrics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './cli';
export { capturePageLoadMetrics } from './capture_page_load_metrics';
Loading