import { CiStatsReporter } from '@kbn/dev-utils' ; import { FtrProviderContext } from './../functional/ftr_provider_context' ; const IGNORED_FIELDS = [ '_seq_no' , '_id' , '_version' , '_field_names' , '_ignored' , '_feature' , '_index' , '_routing' , '_source' , '_type' , '_nested_path' , '_timestamp' , 'migrationVersion' , ] ; export async function testRunner ( { getService } ) { const log = getService ( 'log' ) ; const es = getService ( 'es' ) ; const reporter = CiStatsReporter . fromEnv ( log ) ; log . debug ( 'Saved Objects field count metrics starting' ) ; const { fields } = await es . fieldCaps ( { index : '.kibana' , fields : '*' , } ) ; const fieldCountPerTypeMap = Object . keys ( fields ) . map ( ( f ) => f . split ( '.' ) [ 0 ] ) . filter ( ( f ) => ! IGNORED_FIELDS . includes ( f ) ) . reduce ( ( accumulator , f ) => { accumulator . set ( f , accumulator . get ( f ) + 1 || 1 ) ; return accumulator ; } , new Map ( ) ) ; const metrics = Array . from ( fieldCountPerTypeMap . entries ( ) ) . sort ( ( a , b ) => a [ 0 ] . localeCompare ( b [ 0 ] ) ) . map ( ( [ fieldType , count ] ) => ( { group : 'Saved Objects .kibana field count' , id : fieldType , value : count , } ) ) ; log . debug ( 'Saved Objects field count metrics:\n' , metrics . map ( ( { id , value } ) => `${ id }:${ value }` ) . join ( '\n' ) ) ; await reporter . metrics ( metrics ) ; log . debug ( 'Saved Objects field count metrics done' ) ; }