diff --git a/x-pack/plugins/apm/public/components/app/service_logs/index.test.ts b/x-pack/plugins/apm/public/components/app/service_logs/index.test.ts index d8d2b1de4d302..dc0c486deeed9 100644 --- a/x-pack/plugins/apm/public/components/app/service_logs/index.test.ts +++ b/x-pack/plugins/apm/public/components/app/service_logs/index.test.ts @@ -14,10 +14,9 @@ describe('service logs', () => { expect( getInfrastructureKQLFilter( { - serviceInfrastructure: { - containerIds: [], - hostNames: [], - }, + containerIds: [], + hostNames: [], + podNames: [], }, serviceName ) @@ -28,10 +27,9 @@ describe('service logs', () => { expect( getInfrastructureKQLFilter( { - serviceInfrastructure: { - containerIds: ['foo', 'bar'], - hostNames: ['baz', `quz`], - }, + containerIds: ['foo', 'bar'], + hostNames: ['baz', `quz`], + podNames: [], }, serviceName ) @@ -44,10 +42,9 @@ describe('service logs', () => { expect( getInfrastructureKQLFilter( { - serviceInfrastructure: { - containerIds: [], - hostNames: ['baz', `quz`], - }, + containerIds: [], + hostNames: ['baz', `quz`], + podNames: [], }, serviceName ) diff --git a/x-pack/plugins/apm/public/components/app/service_logs/index.tsx b/x-pack/plugins/apm/public/components/app/service_logs/index.tsx index e282727f0881e..1ea26c08e7fd6 100644 --- a/x-pack/plugins/apm/public/components/app/service_logs/index.tsx +++ b/x-pack/plugins/apm/public/components/app/service_logs/index.tsx @@ -36,7 +36,7 @@ export function ServiceLogs() { (callApmApi) => { if (start && end) { return callApmApi( - 'GET /internal/apm/services/{serviceName}/infrastructure_attributes_for_logs', + 'GET /internal/apm/services/{serviceName}/infrastructure_attributes', { params: { path: { serviceName }, @@ -55,10 +55,7 @@ export function ServiceLogs() { ); const noInfrastructureData = useMemo(() => { - return ( - isEmpty(data?.serviceInfrastructure?.containerIds) && - isEmpty(data?.serviceInfrastructure?.hostNames) - ); + return isEmpty(data?.containerIds) && isEmpty(data?.hostNames); }, [data]); if (status === FETCH_STATUS.LOADING) { @@ -98,12 +95,12 @@ export function ServiceLogs() { export const getInfrastructureKQLFilter = ( data: - | APIReturnType<'GET /internal/apm/services/{serviceName}/infrastructure_attributes_for_logs'> + | APIReturnType<'GET /internal/apm/services/{serviceName}/infrastructure_attributes'> | undefined, serviceName: string ) => { - const containerIds = data?.serviceInfrastructure?.containerIds ?? []; - const hostNames = data?.serviceInfrastructure?.hostNames ?? []; + const containerIds = data?.containerIds ?? []; + const hostNames = data?.hostNames ?? []; const infraAttributes = containerIds.length ? containerIds.map((id) => `${CONTAINER_ID}: "${id}"`) diff --git a/x-pack/plugins/apm/server/routes/services/get_service_infrastructure.ts b/x-pack/plugins/apm/server/routes/services/get_service_infrastructure.ts deleted file mode 100644 index e4e44ac44082b..0000000000000 --- a/x-pack/plugins/apm/server/routes/services/get_service_infrastructure.ts +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { rangeQuery, kqlQuery } from '@kbn/observability-plugin/server'; -import { Setup } from '../../lib/helpers/setup_request'; -import { environmentQuery } from '../../../common/utils/environment_query'; -import { ProcessorEvent } from '../../../common/processor_event'; -import { - SERVICE_NAME, - CONTAINER_ID, - HOST_NAME, -} from '../../../common/elasticsearch_fieldnames'; - -export const getServiceInfrastructure = async ({ - kuery, - serviceName, - environment, - setup, - start, - end, -}: { - kuery: string; - serviceName: string; - environment: string; - setup: Setup; - start: number; - end: number; -}) => { - const { apmEventClient } = setup; - - const response = await apmEventClient.search('get_service_infrastructure', { - apm: { - events: [ProcessorEvent.metric], - }, - body: { - size: 0, - query: { - bool: { - filter: [ - { term: { [SERVICE_NAME]: serviceName } }, - ...rangeQuery(start, end), - ...environmentQuery(environment), - ...kqlQuery(kuery), - ], - }, - }, - aggs: { - containerIds: { - terms: { - field: CONTAINER_ID, - size: 500, - }, - }, - hostNames: { - terms: { - field: HOST_NAME, - size: 500, - }, - }, - }, - }, - }); - - return { - containerIds: - response.aggregations?.containerIds?.buckets.map( - (bucket) => bucket.key as string - ) ?? [], - hostNames: - response.aggregations?.hostNames?.buckets.map( - (bucket) => bucket.key as string - ) ?? [], - }; -}; diff --git a/x-pack/plugins/apm/server/routes/services/route.ts b/x-pack/plugins/apm/server/routes/services/route.ts index bc224b1315f8c..ce9184d8397f5 100644 --- a/x-pack/plugins/apm/server/routes/services/route.ts +++ b/x-pack/plugins/apm/server/routes/services/route.ts @@ -33,7 +33,6 @@ import { getServiceTransactionTypes } from './get_service_transaction_types'; import { getThroughput } from './get_throughput'; import { getServiceProfilingStatistics } from './profiling/get_service_profiling_statistics'; import { getServiceProfilingTimeline } from './profiling/get_service_profiling_timeline'; -import { getServiceInfrastructure } from './get_service_infrastructure'; import { withApmSpan } from '../../utils/with_apm_span'; import { createApmServerRoute } from '../apm_routes/create_apm_server_route'; import { @@ -1130,43 +1129,6 @@ const serviceProfilingStatisticsRoute = createApmServerRoute({ }, }); -// TODO: remove this endpoint in favour of -const serviceInfrastructureRoute = createApmServerRoute({ - endpoint: - 'GET /internal/apm/services/{serviceName}/infrastructure_attributes_for_logs', - params: t.type({ - path: t.type({ - serviceName: t.string, - }), - query: t.intersection([kueryRt, rangeRt, environmentRt]), - }), - options: { tags: ['access:apm'] }, - handler: async ( - resources - ): Promise<{ - serviceInfrastructure: { containerIds: string[]; hostNames: string[] }; - }> => { - const setup = await setupRequest(resources); - - const { params } = resources; - - const { - path: { serviceName }, - query: { environment, kuery, start, end }, - } = params; - - const serviceInfrastructure = await getServiceInfrastructure({ - setup, - serviceName, - environment, - kuery, - start, - end, - }); - return { serviceInfrastructure }; - }, -}); - const serviceAnomalyChartsRoute = createApmServerRoute({ endpoint: 'GET /internal/apm/services/{serviceName}/anomaly_charts', params: t.type({ @@ -1298,7 +1260,6 @@ export const serviceRouteRepository = { ...serviceDependenciesBreakdownRoute, ...serviceProfilingTimelineRoute, ...serviceProfilingStatisticsRoute, - ...serviceInfrastructureRoute, ...serviceAnomalyChartsRoute, ...sortedAndFilteredServicesRoute, };