diff --git a/x-pack/plugins/apm/common/processor_event.ts b/x-pack/plugins/apm/common/processor_event.ts index 63cbb18cacc97d6..9eb9ee60c199811 100644 --- a/x-pack/plugins/apm/common/processor_event.ts +++ b/x-pack/plugins/apm/common/processor_event.ts @@ -10,8 +10,6 @@ export enum ProcessorEvent { error = 'error', metric = 'metric', span = 'span', - onboarding = 'onboarding', - sourcemap = 'sourcemap', } /** * Processor events that are searchable in the UI via the query bar. diff --git a/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/index.ts b/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/index.ts index 8b2c83804b526e0..b93513646fb9f7f 100644 --- a/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/index.ts +++ b/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/index.ts @@ -41,8 +41,6 @@ type TypeOfProcessorEvent = { [ProcessorEvent.transaction]: Transaction; [ProcessorEvent.span]: Span; [ProcessorEvent.metric]: Metric; - [ProcessorEvent.onboarding]: unknown; - [ProcessorEvent.sourcemap]: unknown; }[T]; type ESSearchRequestOf = Omit< diff --git a/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/unpack_processor_events.test.ts b/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/unpack_processor_events.test.ts new file mode 100644 index 000000000000000..560d9c7906ec2af --- /dev/null +++ b/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/unpack_processor_events.test.ts @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +/* eslint-disable @typescript-eslint/naming-convention */ +import { APMEventESSearchRequest } from '.'; +import { ApmIndicesConfig } from '../../../settings/apm_indices/get_apm_indices'; +import { unpackProcessorEvents } from './unpack_processor_events'; + +describe('unpackProcessorEvents', () => { + let res: ReturnType; + beforeEach(() => { + const request = { + apm: { events: ['transaction', 'error'] }, + body: { query: { bool: { filter: [{ terms: { foo: 'bar' } }] } } }, + } as APMEventESSearchRequest; + + const indices = { + 'apm_oss.transactionIndices': 'my-apm-*-transaction-*', + 'apm_oss.metricsIndices': 'my-apm-*-metric-*', + 'apm_oss.errorIndices': 'my-apm-*-error-*', + 'apm_oss.spanIndices': 'my-apm-*-span-*', + 'apm_oss.onboardingIndices': 'my-apm-*-onboarding-', + 'apm_oss.sourcemapIndices': 'my-apm-*-sourcemap-*', + } as ApmIndicesConfig; + + res = unpackProcessorEvents(request, indices); + }); + + it('adds terms filter for apm events', () => { + expect(res.body.query.bool.filter).toContainEqual({ + terms: { 'processor.event': ['transaction', 'error'] }, + }); + }); + + it('merges queries', () => { + expect(res.body.query.bool.filter).toEqual([ + { terms: { foo: 'bar' } }, + { terms: { 'processor.event': ['transaction', 'error'] } }, + ]); + }); + + it('searches legacy and data stream indices', () => { + expect(res.index).toEqual([ + 'traces-apm*', + 'my-apm-*-transaction-*', + 'logs-apm*', + 'my-apm-*-error-*', + ]); + }); +}); diff --git a/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/unpack_processor_events.ts b/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/unpack_processor_events.ts index e5e766069fa61c1..73dc46b69a6b869 100644 --- a/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/unpack_processor_events.ts +++ b/x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/unpack_processor_events.ts @@ -18,13 +18,18 @@ import { ApmIndicesName, } from '../../../settings/apm_indices/get_apm_indices'; -export const processorEventIndexMap: Record = { +const processorEventIndexMap: Record = { [ProcessorEvent.transaction]: 'apm_oss.transactionIndices', [ProcessorEvent.span]: 'apm_oss.spanIndices', [ProcessorEvent.metric]: 'apm_oss.metricsIndices', [ProcessorEvent.error]: 'apm_oss.errorIndices', - [ProcessorEvent.sourcemap]: 'apm_oss.sourcemapIndices', - [ProcessorEvent.onboarding]: 'apm_oss.onboardingIndices', +}; + +const dataStreamsIndexMap: Record = { + [ProcessorEvent.transaction]: 'traces-apm*', + [ProcessorEvent.span]: 'traces-apm*', + [ProcessorEvent.metric]: 'metrics-apm*', + [ProcessorEvent.error]: 'logs-apm*', }; export function unpackProcessorEvents( @@ -35,7 +40,10 @@ export function unpackProcessorEvents( const events = uniq(apm.events); - const index = events.map((event) => indices[processorEventIndexMap[event]]); + const index = events.flatMap((event) => [ + dataStreamsIndexMap[event], + indices[processorEventIndexMap[event]], + ]); const withFilterForProcessorEvent: ESSearchRequest & { body: { query: { bool: { filter: ESFilter[] } } }; diff --git a/x-pack/plugins/apm/server/lib/services/get_services/has_historical_agent_data.ts b/x-pack/plugins/apm/server/lib/services/get_services/has_historical_agent_data.ts index b1877533ca51482..8363e59f2522ed5 100644 --- a/x-pack/plugins/apm/server/lib/services/get_services/has_historical_agent_data.ts +++ b/x-pack/plugins/apm/server/lib/services/get_services/has_historical_agent_data.ts @@ -18,7 +18,6 @@ export async function hasHistoricalAgentData(setup: Setup) { events: [ ProcessorEvent.error, ProcessorEvent.metric, - ProcessorEvent.sourcemap, ProcessorEvent.transaction, ], },