Skip to content

Commit

Permalink
Add data stream indicies
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Feb 4, 2021
1 parent bb3ed33 commit 23879a0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/apm/common/processor_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ type TypeOfProcessorEvent<T extends ProcessorEvent> = {
[ProcessorEvent.transaction]: Transaction;
[ProcessorEvent.span]: Span;
[ProcessorEvent.metric]: Metric;
[ProcessorEvent.onboarding]: unknown;
[ProcessorEvent.sourcemap]: unknown;
}[T];

type ESSearchRequestOf<TParams extends APMEventESSearchRequest> = Omit<
Expand Down
Original file line number Diff line number Diff line change
@@ -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<typeof unpackProcessorEvents>;
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-*',
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ import {
ApmIndicesName,
} from '../../../settings/apm_indices/get_apm_indices';

export const processorEventIndexMap: Record<ProcessorEvent, ApmIndicesName> = {
const processorEventIndexMap: Record<ProcessorEvent, ApmIndicesName> = {
[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, string> = {
[ProcessorEvent.transaction]: 'traces-apm*',
[ProcessorEvent.span]: 'traces-apm*',
[ProcessorEvent.metric]: 'metrics-apm*',
[ProcessorEvent.error]: 'logs-apm*',
};

export function unpackProcessorEvents(
Expand All @@ -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[] } } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export async function hasHistoricalAgentData(setup: Setup) {
events: [
ProcessorEvent.error,
ProcessorEvent.metric,
ProcessorEvent.sourcemap,
ProcessorEvent.transaction,
],
},
Expand Down

0 comments on commit 23879a0

Please sign in to comment.