import { isActivePlatinumLicense } from '../../../common/license_check' ; import { APMConfig } from '../..' ; import { KibanaRequest } from '../../../../../../src/core/server' ; import { UI_SETTINGS } from '../../../../../../src/plugins/data/common' ; import { APMRouteHandlerResources } from '../../routes/typings' ; import { ApmIndicesConfig , getApmIndices , } from '../../routes/settings/apm_indices/get_apm_indices' ; import { APMEventClient } from './create_es_client/create_apm_event_client' ; import { APMInternalClient , createInternalESClient , } from './create_es_client/create_internal_es_client' ; import { withApmSpan } from '../../utils/with_apm_span' ; export interface Setup { apmEventClient : APMEventClient ; internalClient : APMInternalClient ; ml ? : ReturnType < typeof getMlSetup > ; config : APMConfig ; indices : ApmIndicesConfig ; } export async function setupRequest ( { context , params , core , plugins , request , config , } ) { return withApmSpan ( 'setup_request' , async ( ) => { const { query } = params ; const [ indices , includeFrozen ] = await Promise . all ( [ getApmIndices ( { savedObjectsClient : context . core . savedObjects . client , config , } ) , withApmSpan ( 'get_ui_settings' , ( ) => context . core . uiSettings . client . get ( UI_SETTINGS . SEARCH_INCLUDE_FROZEN ) ) , ] ) ; return { indices , apmEventClient : new APMEventClient ( { esClient : context . core . elasticsearch . client . asCurrentUser , debug : query . _inspect , request , indices , options : { includeFrozen } , } ) , internalClient : createInternalESClient ( { context , request , debug : query . _inspect , } ) , ml : plugins . ml && isActivePlatinumLicense ( context . licensing . license ) ? getMlSetup ( plugins . ml . setup , context . core . savedObjects . client , request ) : undefined , config , } ; } ) ; } function getMlSetup ( ml , savedObjectsClient , request ) { return { mlSystem : ml . mlSystemProvider ( request , savedObjectsClient ) , anomalyDetectors : ml . anomalyDetectorsProvider ( request , savedObjectsClient ) , modules : ml . modulesProvider ( request , savedObjectsClient ) , } ; }