import { ProcessorEvent } from '../../../../common/processor_event' ; import { Setup } from '../../../lib/helpers/setup_request' ; import { SERVICE_NAME } from '../../../../common/elasticsearch_fieldnames' ; import { ALL_OPTION_VALUE } from '../../../../common/agent_configuration/all_option' ; import { getProcessorEventForTransactions } from '../../../lib/helpers/transactions' ; export async function getServiceNames ( { setup , searchAggregatedTransactions , size , } ) { const { apmEventClient } = setup ; const params = { apm : { events : [ getProcessorEventForTransactions ( searchAggregatedTransactions ) , ProcessorEvent . error , ProcessorEvent . metric , ] , } , body : { timeout : '1ms' , size : 0 , aggs : { services : { terms : { field : SERVICE_NAME , min_doc_count : 0 , size , } , } , } , } , } ; const resp = await apmEventClient . search ( 'get_service_names_for_agent_config' , params ) ; const serviceNames = resp . aggregations ?. services . buckets . map ( ( bucket ) => bucket . key as string ) . sort ( ) || [ ] ; return [ ALL_OPTION_VALUE , ... serviceNames ] ; }