[kbn/optimizer] log info about the metrics being reported even when reporter is disabled (#73389)
Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
parent
0149c65221
commit
3d5d4de63c
|
@ -29,6 +29,8 @@ interface Config {
|
|||
buildId: string;
|
||||
}
|
||||
|
||||
export type CiStatsMetrics = Array<{ group: string; id: string; value: number }>;
|
||||
|
||||
function parseConfig(log: ToolingLog) {
|
||||
const configJson = process.env.KIBANA_CI_STATS_CONFIG;
|
||||
if (!configJson) {
|
||||
|
@ -84,7 +86,7 @@ export class CiStatsReporter {
|
|||
return !!this.config;
|
||||
}
|
||||
|
||||
async metrics(metrics: Array<{ group: string; id: string; value: number }>) {
|
||||
async metrics(metrics: CiStatsMetrics) {
|
||||
if (!this.config) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ run(
|
|||
log.warning('Unable to initialize CiStatsReporter from env');
|
||||
}
|
||||
|
||||
update$ = update$.pipe(reportOptimizerStats(reporter, config));
|
||||
update$ = update$.pipe(reportOptimizerStats(reporter, config, log));
|
||||
}
|
||||
|
||||
await update$.pipe(logOptimizerState(log, config)).toPromise();
|
||||
|
|
|
@ -104,7 +104,7 @@ export function logOptimizerState(log: ToolingLog, config: OptimizerConfig) {
|
|||
}
|
||||
|
||||
if (state.phase === 'running' || state.phase === 'initializing') {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.phase === 'issue') {
|
||||
|
@ -119,7 +119,7 @@ export function logOptimizerState(log: ToolingLog, config: OptimizerConfig) {
|
|||
}
|
||||
}
|
||||
log.indent(-4);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.phase === 'success') {
|
||||
|
@ -135,7 +135,7 @@ export function logOptimizerState(log: ToolingLog, config: OptimizerConfig) {
|
|||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(`unhandled optimizer message: ${inspect(update)}`);
|
||||
|
|
|
@ -21,7 +21,7 @@ import Fs from 'fs';
|
|||
import Path from 'path';
|
||||
|
||||
import { materialize, mergeMap, dematerialize } from 'rxjs/operators';
|
||||
import { CiStatsReporter } from '@kbn/dev-utils';
|
||||
import { CiStatsReporter, CiStatsMetrics, ToolingLog } from '@kbn/dev-utils';
|
||||
|
||||
import { OptimizerUpdate$ } from './run_optimizer';
|
||||
import { OptimizerState, OptimizerConfig } from './optimizer';
|
||||
|
@ -67,7 +67,11 @@ const getFiles = (dir: string, parent?: string) =>
|
|||
return true;
|
||||
});
|
||||
|
||||
export function reportOptimizerStats(reporter: CiStatsReporter, config: OptimizerConfig) {
|
||||
export function reportOptimizerStats(
|
||||
reporter: CiStatsReporter,
|
||||
config: OptimizerConfig,
|
||||
log: ToolingLog
|
||||
) {
|
||||
return pipeClosure((update$: OptimizerUpdate$) => {
|
||||
let lastState: OptimizerState | undefined;
|
||||
return update$.pipe(
|
||||
|
@ -98,10 +102,18 @@ export function reportOptimizerStats(reporter: CiStatsReporter, config: Optimize
|
|||
const miscFiles = outputFiles.filter(
|
||||
(f) => f !== entry && !asyncChunks.includes(f)
|
||||
);
|
||||
|
||||
if (asyncChunks.length) {
|
||||
log.verbose(bundle.id, 'async chunks', asyncChunks);
|
||||
}
|
||||
if (miscFiles.length) {
|
||||
log.verbose(bundle.id, 'misc files', asyncChunks);
|
||||
}
|
||||
|
||||
const sumSize = (files: Entry[]) =>
|
||||
files.reduce((acc: number, f) => acc + f.stats!.size, 0);
|
||||
|
||||
return [
|
||||
const metrics: CiStatsMetrics = [
|
||||
{
|
||||
group: `@kbn/optimizer bundle module count`,
|
||||
id: bundle.id,
|
||||
|
@ -123,6 +135,10 @@ export function reportOptimizerStats(reporter: CiStatsReporter, config: Optimize
|
|||
value: sumSize(miscFiles),
|
||||
},
|
||||
];
|
||||
|
||||
log.info(bundle.id, 'metrics', metrics);
|
||||
|
||||
return metrics;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
|
|
@ -44,7 +44,7 @@ export const BuildKibanaPlatformPlugins: Task = {
|
|||
|
||||
await runOptimizer(optimizerConfig)
|
||||
.pipe(
|
||||
reportOptimizerStats(reporter, optimizerConfig),
|
||||
reportOptimizerStats(reporter, optimizerConfig, log),
|
||||
logOptimizerState(log, optimizerConfig)
|
||||
)
|
||||
.toPromise();
|
||||
|
|
Loading…
Reference in a new issue