import { EVENT_KIND } from '@kbn/rule-data-utils' ; import { IRuleDataClient } from '../../../../rule_registry/server' ; import { SERVICE_NAME , TRANSACTION_TYPE , } from '../../../common/elasticsearch_fieldnames' ; import { rangeQuery } from '../../../../observability/server' ; import { environmentQuery } from '../../../common/utils/environment_query' ; export async function getServiceAlerts ( { ruleDataClient , start , end , serviceName , environment , transactionType , } ) { const response = await ruleDataClient . getReader ( ) . search ( { body : { query : { bool : { filter : [ ... rangeQuery ( start , end ) , ... environmentQuery ( environment ) , { term : { [ SERVICE_NAME ] : serviceName } } , { term : { [ EVENT_KIND ] : 'signal' } } , ] , should : [ { bool : { filter : [ { term : { [ TRANSACTION_TYPE ] : transactionType , } , } , ] , } , } , { bool : { must_not : { exists : { field : TRANSACTION_TYPE , } , } , } , } , ] , minimum_should_match : 1 , } , } , size : 100 , fields : [ '*' ] , sort : { '@timestamp' : 'desc' , } , } , allow_no_indices : true , } ) ; return response . hits . hits . map ( ( hit ) => hit . fields ) ; }