import { ProcessorEvent } from '../../../common/processor_event' ; import { rangeQuery } from '../../../../observability/server' ; import { SERVICE_NAME } from '../../../common/elasticsearch_fieldnames' ; import { Setup } from '../../lib/helpers/setup_request' ; import { getProcessorEventForTransactions } from '../../lib/helpers/transactions' ; export async function getServiceCount ( { setup , searchAggregatedTransactions , start , end , } ) { const { apmEventClient } = setup ; const params = { apm : { events : [ getProcessorEventForTransactions ( searchAggregatedTransactions ) , ProcessorEvent . error , ProcessorEvent . metric , ] , } , body : { size : 0 , query : { bool : { filter : rangeQuery ( start , end ) , } , } , aggs : { serviceCount : { cardinality : { field : SERVICE_NAME } } } , } , } ; const { aggregations } = await apmEventClient . search ( 'observability_overview_get_service_count' , params ) ; return aggregations ?. serviceCount . value || 0 ; }