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 , config ) { return pipeClosure ( ( update$ ) => { let sent = false ; const cachedBundles = new Set < string > ( ) ; const notCachedBundles = new Set < string > ( ) ; return update$ . pipe ( concatMap ( async ( update ) => { 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 ) ; } 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 : 'scripts/build_kibana_platform_plugins' , id : 'total' , ms : time , meta : { optimizerBundleCount : config . filteredBundles . length , optimizerBundleCacheCount : cachedBundles . size , optimizerBundleCachePct : Math . floor ( ( cachedBundles . size / config . filteredBundles . length ) * 100 ) , optimizerWatch : config . watch , optimizerProduction : config . dist , optimizerProfileWebpack : config . profileWebpack , optimizerBundleThemeTagsCount : config . themeTags . length , optimizerCache : config . cache , optimizerMaxWorkerCount : config . maxWorkerCount , } , } , ] , } ) ; return update ; } ) ) ; } ) ; }