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

[kbn/optimizer] report sizes of assets produced by optimizer #71319

Merged
merged 18 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cac0717
Revert "Report page load asset size (#66224)"
spalger Jul 9, 2020
2a69e2c
[kbn/optimizer] report sizes of assets produced by optimizer
spalger Jul 9, 2020
4201fb6
coalese the fast-glob versions we're using to prevent additional inst…
spalger Jul 9, 2020
5a3c757
Merge branch 'master' of github.com:elastic/kibana into implement/ass…
spalger Jul 9, 2020
68e24f0
update kbn/pm dist
spalger Jul 9, 2020
ba369f4
Revert "update kbn/pm dist"
spalger Jul 9, 2020
fd27ad8
Revert "coalese the fast-glob versions we're using to prevent additio…
spalger Jul 9, 2020
30118e8
remove fast-glob, just recursivly call readdirSync()
spalger Jul 9, 2020
e6ce0a1
Merge branch 'master' of github.com:elastic/kibana into implement/ass…
spalger Jul 9, 2020
c152195
Merge branch 'master' of github.com:elastic/kibana into implement/ass…
spalger Jul 9, 2020
a2ddcbe
Merge branch 'master' of github.com:elastic/kibana into implement/ass…
spalger Jul 9, 2020
e9c374f
Merge branch 'master' of github.com:elastic/kibana into implement/ass…
spalger Jul 10, 2020
78a18c5
update integration tests to use new chunk filename
spalger Jul 10, 2020
85da88f
Merge branch 'master' of github.com:elastic/kibana into implement/ass…
spalger Jul 10, 2020
88f9229
Merge branch 'master' into implement/asset-size-metrics
elasticmachine Jul 14, 2020
2afda68
Merge branch 'master' into implement/asset-size-metrics
elasticmachine Jul 14, 2020
3b2611a
Merge branch 'master' of github.com:elastic/kibana into implement/ass…
spalger Jul 14, 2020
8bcc99f
Merge branch 'implement/asset-size-metrics' of github.com:spalger/kib…
spalger Jul 14, 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: 0 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true, setCommitStatus: true)
'xpack-ciGroup10': kibanaPipeline.xpackCiGroupProcess(10),
'xpack-accessibility': kibanaPipeline.functionalTestProcess('xpack-accessibility', './test/scripts/jenkins_xpack_accessibility.sh'),
'xpack-savedObjectsFieldMetrics': kibanaPipeline.functionalTestProcess('xpack-savedObjectsFieldMetrics', './test/scripts/jenkins_xpack_saved_objects_field_metrics.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
1 change: 1 addition & 0 deletions packages/kbn-optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"css-loader": "^3.4.2",
"del": "^5.1.0",
"execa": "^4.0.2",
"fast-glob": "^3.2.4",
spalger marked this conversation as resolved.
Show resolved Hide resolved
"file-loader": "^4.2.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jest-diff": "^25.5.0",
Expand Down
70 changes: 60 additions & 10 deletions packages/kbn-optimizer/src/report_optimizer_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@
* under the License.
*/

import { Stats } from 'fs';

import { materialize, mergeMap, dematerialize } from 'rxjs/operators';
import { CiStatsReporter } from '@kbn/dev-utils';
import fastGlob, { Entry } from 'fast-glob';

import { OptimizerUpdate$ } from './run_optimizer';
import { OptimizerState, OptimizerConfig } from './optimizer';
import { pipeClosure } from './common';

const flatten = <T>(arr: Array<T | T[]>): T[] =>
arr.reduce((acc: T[], item) => acc.concat(item), []);

export function reportOptimizerStats(reporter: CiStatsReporter, config: OptimizerConfig) {
return pipeClosure((update$: OptimizerUpdate$) => {
let lastState: OptimizerState | undefined;
Expand All @@ -36,16 +42,60 @@ export function reportOptimizerStats(reporter: CiStatsReporter, config: Optimize

if (n.kind === 'C' && lastState) {
await reporter.metrics(
config.bundles.map((bundle) => {
// make the cache read from the cache file since it was likely updated by the worker
bundle.cache.refresh();

return {
group: `@kbn/optimizer bundle module count`,
id: bundle.id,
value: bundle.cache.getModuleCount() || 0,
};
})
flatten(
config.bundles.map((bundle) => {
// make the cache read from the cache file since it was likely updated by the worker
bundle.cache.refresh();

const outputFiles = fastGlob.sync('**/*', {
cwd: bundle.outputDir,
onlyFiles: true,
unique: true,
stats: true,
absolute: false,
ignore: ['!**/*.map'],
});

const entryName = `${bundle.id}.${bundle.type}.js`;
const entry = outputFiles.find((f) => f.path === entryName);
if (!entry) {
throw new Error(
`Unable to find bundle entry named [${entryName}] in [${bundle.outputDir}]`
);
}

const chunkPrefix = `${bundle.id}.chunk.`;
const asyncChunks = outputFiles.filter((f) => f.path.startsWith(chunkPrefix));
const miscFiles = outputFiles.filter(
(f) => f !== entry && !asyncChunks.includes(f)
);
const sumSize = (files: Entry[]) =>
files.reduce((acc: number, f) => acc + f.stats!.size, 0);

return [
{
group: `@kbn/optimizer bundle module count`,
id: bundle.id,
value: bundle.cache.getModuleCount() || 0,
},
{
group: `page load bundle size`,
id: bundle.id,
value: entry.stats!.size,
},
{
group: `async chunks size`,
id: bundle.id,
value: sumSize(asyncChunks),
},
{
group: `miscellaneous assets size`,
id: bundle.id,
value: sumSize(miscFiles),
},
];
})
)
);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:

output: {
path: bundle.outputDir,
filename: `[name].${bundle.type}.js`,
filename: `${bundle.id}.${bundle.type}.js`,
chunkFilename: `${bundle.id}.chunk.[id].js`,
devtoolModuleFilenameTemplate: (info) =>
`/${bundle.type}:${bundle.id}/${Path.relative(
bundle.sourceRoot,
Expand Down
2 changes: 0 additions & 2 deletions packages/kbn-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"@types/joi": "^13.4.2",
"@types/lodash": "^4.14.155",
"@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 @@ -31,7 +30,6 @@
"joi": "^13.5.2",
"lodash": "^4.17.15",
"parse-link-header": "^1.0.1",
"puppeteer": "^3.3.0",
"rxjs": "^6.5.5",
"strip-ansi": "^5.2.0",
"tar-fs": "^1.16.3",
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ export { makeJunitReportPath } from './junit_report_path';
export { CI_PARALLEL_PROCESS_PREFIX } from './ci_parallel_process_prefix';

export * from './functional_test_runner';
export * from './page_load_metrics';

This file was deleted.

90 changes: 0 additions & 90 deletions packages/kbn-test/src/page_load_metrics/cli.ts

This file was deleted.

34 changes: 0 additions & 34 deletions packages/kbn-test/src/page_load_metrics/event.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/kbn-test/src/page_load_metrics/index.ts

This file was deleted.

Loading