Skip to content

Commit d53c86f

Browse files
committed
Merge branch 'master' into search/telemetry
2 parents b5c1262 + a0f7dce commit d53c86f

File tree

47 files changed

+337
-3306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+337
-3306
lines changed

Jenkinsfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true, setCommitStatus: true)
4242
'xpack-ciGroup10': kibanaPipeline.xpackCiGroupProcess(10),
4343
'xpack-accessibility': kibanaPipeline.functionalTestProcess('xpack-accessibility', './test/scripts/jenkins_xpack_accessibility.sh'),
4444
'xpack-savedObjectsFieldMetrics': kibanaPipeline.functionalTestProcess('xpack-savedObjectsFieldMetrics', './test/scripts/jenkins_xpack_saved_objects_field_metrics.sh'),
45-
// 'xpack-pageLoadMetrics': kibanaPipeline.functionalTestProcess('xpack-pageLoadMetrics', './test/scripts/jenkins_xpack_page_load_metrics.sh'),
4645
'xpack-securitySolutionCypress': { processNumber ->
4746
whenChanged(['x-pack/plugins/security_solution/', 'x-pack/test/security_solution_cypress/']) {
4847
kibanaPipeline.functionalTestProcess('xpack-securitySolutionCypress', './test/scripts/jenkins_security_solution_cypress.sh')(processNumber)

packages/kbn-optimizer/src/integration_tests/__snapshots__/basic_optimization.test.ts.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/kbn-optimizer/src/integration_tests/basic_optimization.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ it('prepares assets for distribution', async () => {
220220

221221
expectFileMatchesSnapshotWithCompression('plugins/foo/target/public/foo.plugin.js', 'foo bundle');
222222
expectFileMatchesSnapshotWithCompression(
223-
'plugins/foo/target/public/1.plugin.js',
223+
'plugins/foo/target/public/foo.chunk.1.js',
224224
'foo async bundle'
225225
);
226226
expectFileMatchesSnapshotWithCompression('plugins/bar/target/public/bar.plugin.js', 'bar bundle');

packages/kbn-optimizer/src/report_optimizer_stats.ts

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,42 @@
1717
* under the License.
1818
*/
1919

20+
import Fs from 'fs';
21+
import Path from 'path';
22+
2023
import { materialize, mergeMap, dematerialize } from 'rxjs/operators';
2124
import { CiStatsReporter } from '@kbn/dev-utils';
2225

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

30+
const flatten = <T>(arr: Array<T | T[]>): T[] =>
31+
arr.reduce((acc: T[], item) => acc.concat(item), []);
32+
33+
interface Entry {
34+
relPath: string;
35+
stats: Fs.Stats;
36+
}
37+
38+
const getFiles = (dir: string, parent?: string) =>
39+
flatten(
40+
Fs.readdirSync(dir).map((name): Entry | Entry[] => {
41+
const absPath = Path.join(dir, name);
42+
const relPath = parent ? Path.join(parent, name) : name;
43+
const stats = Fs.statSync(absPath);
44+
45+
if (stats.isDirectory()) {
46+
return getFiles(absPath, relPath);
47+
}
48+
49+
return {
50+
relPath,
51+
stats,
52+
};
53+
})
54+
);
55+
2756
export function reportOptimizerStats(reporter: CiStatsReporter, config: OptimizerConfig) {
2857
return pipeClosure((update$: OptimizerUpdate$) => {
2958
let lastState: OptimizerState | undefined;
@@ -36,16 +65,55 @@ export function reportOptimizerStats(reporter: CiStatsReporter, config: Optimize
3665

3766
if (n.kind === 'C' && lastState) {
3867
await reporter.metrics(
39-
config.bundles.map((bundle) => {
40-
// make the cache read from the cache file since it was likely updated by the worker
41-
bundle.cache.refresh();
42-
43-
return {
44-
group: `@kbn/optimizer bundle module count`,
45-
id: bundle.id,
46-
value: bundle.cache.getModuleCount() || 0,
47-
};
48-
})
68+
flatten(
69+
config.bundles.map((bundle) => {
70+
// make the cache read from the cache file since it was likely updated by the worker
71+
bundle.cache.refresh();
72+
73+
const outputFiles = getFiles(bundle.outputDir).filter(
74+
(file) => !(file.relPath.startsWith('.') || file.relPath.endsWith('.map'))
75+
);
76+
77+
const entryName = `${bundle.id}.${bundle.type}.js`;
78+
const entry = outputFiles.find((f) => f.relPath === entryName);
79+
if (!entry) {
80+
throw new Error(
81+
`Unable to find bundle entry named [${entryName}] in [${bundle.outputDir}]`
82+
);
83+
}
84+
85+
const chunkPrefix = `${bundle.id}.chunk.`;
86+
const asyncChunks = outputFiles.filter((f) => f.relPath.startsWith(chunkPrefix));
87+
const miscFiles = outputFiles.filter(
88+
(f) => f !== entry && !asyncChunks.includes(f)
89+
);
90+
const sumSize = (files: Entry[]) =>
91+
files.reduce((acc: number, f) => acc + f.stats!.size, 0);
92+
93+
return [
94+
{
95+
group: `@kbn/optimizer bundle module count`,
96+
id: bundle.id,
97+
value: bundle.cache.getModuleCount() || 0,
98+
},
99+
{
100+
group: `page load bundle size`,
101+
id: bundle.id,
102+
value: entry.stats!.size,
103+
},
104+
{
105+
group: `async chunks size`,
106+
id: bundle.id,
107+
value: sumSize(asyncChunks),
108+
},
109+
{
110+
group: `miscellaneous assets size`,
111+
id: bundle.id,
112+
value: sumSize(miscFiles),
113+
},
114+
];
115+
})
116+
)
49117
);
50118
}
51119

packages/kbn-optimizer/src/worker/webpack.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
5252

5353
output: {
5454
path: bundle.outputDir,
55-
filename: `[name].${bundle.type}.js`,
55+
filename: `${bundle.id}.${bundle.type}.js`,
56+
chunkFilename: `${bundle.id}.chunk.[id].js`,
5657
devtoolModuleFilenameTemplate: (info) =>
5758
`/${bundle.type}:${bundle.id}/${Path.relative(
5859
bundle.sourceRoot,

packages/kbn-test/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@types/joi": "^13.4.2",
1717
"@types/lodash": "^4.14.155",
1818
"@types/parse-link-header": "^1.0.0",
19-
"@types/puppeteer": "^3.0.0",
2019
"@types/strip-ansi": "^5.2.1",
2120
"@types/xml2js": "^0.4.5",
2221
"diff": "^4.0.1"
@@ -31,7 +30,6 @@
3130
"joi": "^13.5.2",
3231
"lodash": "^4.17.15",
3332
"parse-link-header": "^1.0.1",
34-
"puppeteer": "^3.3.0",
3533
"rxjs": "^6.5.5",
3634
"strip-ansi": "^5.2.0",
3735
"tar-fs": "^1.16.3",

packages/kbn-test/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ export { makeJunitReportPath } from './junit_report_path';
6060
export { CI_PARALLEL_PROCESS_PREFIX } from './ci_parallel_process_prefix';
6161

6262
export * from './functional_test_runner';
63-
export * from './page_load_metrics';

0 commit comments

Comments
 (0)