[kbn/optimizer] report timings when run from CLI or build (#94764)

Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Spencer 2021-03-17 14:04:28 -07:00 committed by GitHub
parent 645545ebdf
commit 6242c7ed4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 3 deletions

View file

@ -6,6 +6,7 @@ To help us provide a good developer experience, we track some straightforward me
The operations we current report timing data for:
* Total execution time of `yarn kbn bootstrap`
* Total execution time of `@kbn/optimizer` runs as well as the following metadata about the runs: The number of bundles created, the number of bundles which were cached, usage of `--watch`, `--dist`, `--workers` and `--no-cache` flags, and the count of themes being built.
Along with the execution time of each execution, we ship the following information about your machine to the service:

View file

@ -18,6 +18,7 @@ import { logOptimizerState } from './log_optimizer_state';
import { OptimizerConfig } from './optimizer';
import { runOptimizer } from './run_optimizer';
import { validateLimitsForAllBundles, updateBundleLimits } from './limits';
import { reportOptimizerTimings } from './report_optimizer_timings';
function getLimitsPath(flags: Flags, defaultPath: string) {
if (flags.limits) {
@ -144,7 +145,9 @@ export function runKbnOptimizerCli(options: { defaultLimitsPath: string }) {
const update$ = runOptimizer(config);
await lastValueFrom(update$.pipe(logOptimizerState(log, config)));
await lastValueFrom(
update$.pipe(logOptimizerState(log, config), reportOptimizerTimings(log, config))
);
if (updateLimits) {
updateBundleLimits({

View file

@ -12,3 +12,4 @@ export * from './log_optimizer_state';
export * from './node';
export * from './limits';
export * from './cli';
export * from './report_optimizer_timings';

View file

@ -0,0 +1,73 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { concatMap } from 'rxjs/operators';
import { CiStatsReporter, ToolingLog } from '@kbn/dev-utils';
import { OptimizerConfig } from './optimizer';
import { OptimizerUpdate$ } from './run_optimizer';
import { pipeClosure } from './common';
export function reportOptimizerTimings(log: ToolingLog, config: OptimizerConfig) {
return pipeClosure((update$: OptimizerUpdate$) => {
let sent = false;
const cachedBundles = new Set<string>();
const notCachedBundles = new Set<string>();
return update$.pipe(
concatMap(async (update) => {
// if we've already sent timing data then move on
if (sent) {
return update;
}
if (update.event?.type === 'bundle cached') {
cachedBundles.add(update.event.bundle.id);
}
if (update.event?.type === 'bundle not cached') {
notCachedBundles.add(update.event.bundle.id);
}
// wait for the optimizer to complete, either with a success or failure
if (update.state.phase !== 'issue' && update.state.phase !== 'success') {
return update;
}
sent = true;
const reporter = CiStatsReporter.fromEnv(log);
const time = Date.now() - update.state.startTime;
await reporter.timings({
timings: [
{
group: '@kbn/optimizer',
id: 'overall time',
ms: time,
meta: {
optimizerBundleCount: config.bundles.length,
optimizerBundleCacheCount: cachedBundles.size,
optimizerBundleCachePct: Math.floor(
(cachedBundles.size / config.bundles.length) * 100
),
optimizerWatch: config.watch,
optimizerProduction: config.dist,
optimizerProfileWebpack: config.profileWebpack,
optimizerBundleThemeTagsCount: config.themeTags.length,
optimizerCache: config.cache,
optimizerMaxWorkerCount: config.maxWorkerCount,
},
},
],
});
return update;
})
);
});
}

View file

@ -11,7 +11,12 @@ import Path from 'path';
import { REPO_ROOT } from '@kbn/utils';
import { lastValueFrom } from '@kbn/std';
import { CiStatsMetric } from '@kbn/dev-utils';
import { runOptimizer, OptimizerConfig, logOptimizerState } from '@kbn/optimizer';
import {
runOptimizer,
OptimizerConfig,
logOptimizerState,
reportOptimizerTimings,
} from '@kbn/optimizer';
import { Task, deleteAll, write, read } from '../lib';
@ -30,7 +35,9 @@ export const BuildKibanaPlatformPlugins: Task = {
limitsPath: Path.resolve(REPO_ROOT, 'packages/kbn-optimizer/limits.yml'),
});
await lastValueFrom(runOptimizer(config).pipe(logOptimizerState(log, config)));
await lastValueFrom(
runOptimizer(config).pipe(logOptimizerState(log, config), reportOptimizerTimings(log, config))
);
const combinedMetrics: CiStatsMetric[] = [];
const metricFilePaths: string[] = [];