import { SERVICE_NAME , TRANSACTION_NAME , TRANSACTION_TYPE , } from '../../../common/elasticsearch_fieldnames' ; import { kqlQuery , rangeQuery , termQuery , } from '../../../../observability/server' ; import { environmentQuery } from '../../../common/utils/environment_query' ; import { getDocumentTypeFilterForTransactions , getProcessorEventForTransactions , } from '../../lib/helpers/transactions' ; import { Setup } from '../../lib/helpers/setup_request' ; interface Options { environment : string ; kuery : string ; searchAggregatedTransactions : boolean ; serviceName : string ; setup : Setup ; transactionType : string ; transactionName ? : string ; start : number ; end : number ; intervalString : string ; bucketSize : number ; } export async function getThroughput ( { environment , kuery , searchAggregatedTransactions , serviceName , setup , transactionType , transactionName , start , end , intervalString , bucketSize , } ) { const { apmEventClient } = setup ; const params = { apm : { events : [ getProcessorEventForTransactions ( searchAggregatedTransactions ) ] , } , body : { size : 0 , query : { bool : { filter : [ { term : { [ SERVICE_NAME ] : serviceName } } , { term : { [ TRANSACTION_TYPE ] : transactionType } } , ... getDocumentTypeFilterForTransactions ( searchAggregatedTransactions ) , ... rangeQuery ( start , end ) , ... environmentQuery ( environment ) , ... kqlQuery ( kuery ) , ... termQuery ( TRANSACTION_NAME , transactionName ) , ] , } , } , aggs : { timeseries : { date_histogram : { field : '@timestamp' , fixed_interval : intervalString , min_doc_count : 0 , extended_bounds : { min : start , max : end } , } , aggs : { throughput : { rate : { unit : 'minute' as const } , } , } , } , } , } , } ; const response = await apmEventClient . search ( 'get_throughput_for_service' , params ) ; return ( response . aggregations ?. timeseries . buckets . map ( ( bucket ) => { return { x : bucket . key , y : bucket . throughput . value , } ; } ) ?? [ ] ) ; }