Skip to content

Commit

Permalink
[APM] Replace omitLegacyData with includeLegacyData (#34426) (#34446
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sorenlouv authored Apr 3, 2019
1 parent ff9d1fa commit c10b793
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 48 deletions.
67 changes: 23 additions & 44 deletions x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function getMockRequest() {
describe('setupRequest', () => {
it('should call callWithRequest with default args', async () => {
const { mockRequest, callWithRequestSpy } = getMockRequest();
const setup = setupRequest(mockRequest);
await setup.client('myType', { index: 'apm-*', body: { foo: 'bar' } });
const { client } = setupRequest(mockRequest);
await client('myType', { index: 'apm-*', body: { foo: 'bar' } });
expect(callWithRequestSpy).toHaveBeenCalledWith(mockRequest, 'myType', {
index: 'apm-*',
body: {
Expand All @@ -46,17 +46,17 @@ describe('setupRequest', () => {
});
});

describe('omitLegacyData', () => {
describe('observer.version_major filter', () => {
describe('if index is apm-*', () => {
it('should add `observer.version_major` filter if `omitLegacyData=true` ', async () => {
it('should merge `observer.version_major` filter with existing boolean filters', async () => {
const { mockRequest, callWithRequestSpy } = getMockRequest();
const setup = setupRequest(mockRequest);
await setup.client('myType', {
const { client } = setupRequest(mockRequest);
await client('myType', {
index: 'apm-*',
omitLegacyData: true,
body: { query: { bool: { filter: [{ term: 'someTerm' }] } } }
});
expect(callWithRequestSpy.mock.calls[0][2].body).toEqual({
const params = callWithRequestSpy.mock.calls[0][2];
expect(params.body).toEqual({
query: {
bool: {
filter: [
Expand All @@ -68,23 +68,10 @@ describe('setupRequest', () => {
});
});

it('should not add `observer.version_major` filter if `omitLegacyData=false` ', async () => {
const { mockRequest, callWithRequestSpy } = getMockRequest();
const setup = setupRequest(mockRequest);
await setup.client('myType', {
index: 'apm-*',
omitLegacyData: false,
body: { query: { bool: { filter: [{ term: 'someTerm' }] } } }
});
expect(callWithRequestSpy.mock.calls[0][2].body).toEqual({
query: { bool: { filter: [{ term: 'someTerm' }] } }
});
});

it('should add `observer.version_major` filter if none exists', async () => {
const { mockRequest, callWithRequestSpy } = getMockRequest();
const setup = setupRequest(mockRequest);
await setup.client('myType', { index: 'apm-*' });
const { client } = setupRequest(mockRequest);
await client('myType', { index: 'apm-*' });
const params = callWithRequestSpy.mock.calls[0][2];
expect(params.body).toEqual({
query: {
Expand All @@ -95,33 +82,25 @@ describe('setupRequest', () => {
});
});

it('should have `omitLegacyData=true` as default and merge boolean filters', async () => {
it('should not add `observer.version_major` filter if `includeLegacyData=true`', async () => {
const { mockRequest, callWithRequestSpy } = getMockRequest();
const setup = setupRequest(mockRequest);
await setup.client('myType', {
const { client } = setupRequest(mockRequest);
await client('myType', {
index: 'apm-*',
body: {
query: { bool: { filter: [{ term: 'someTerm' }] } }
}
includeLegacyData: true,
body: { query: { bool: { filter: [{ term: 'someTerm' }] } } }
});
const params = callWithRequestSpy.mock.calls[0][2];
expect(params.body).toEqual({
query: {
bool: {
filter: [
{ term: 'someTerm' },
{ range: { 'observer.version_major': { gte: 7 } } }
]
}
}
query: { bool: { filter: [{ term: 'someTerm' }] } }
});
});
});

it('if index is not an APM index, it should not add `observer.version_major` filter ', async () => {
it('if index is not an APM index, it should not add `observer.version_major` filter', async () => {
const { mockRequest, callWithRequestSpy } = getMockRequest();
const setup = setupRequest(mockRequest);
await setup.client('myType', {
const { client } = setupRequest(mockRequest);
await client('myType', {
index: '.ml-*',
body: {
query: { bool: { filter: [{ term: 'someTerm' }] } }
Expand All @@ -144,8 +123,8 @@ describe('setupRequest', () => {

// mock includeFrozen to return false
mockRequest.getUiSettingsService = () => ({ get: async () => false });
const setup = setupRequest(mockRequest);
await setup.client('myType', {});
const { client } = setupRequest(mockRequest);
await client('myType', {});
const params = callWithRequestSpy.mock.calls[0][2];
expect(params.ignore_throttled).toBe(true);
});
Expand All @@ -155,8 +134,8 @@ describe('setupRequest', () => {

// mock includeFrozen to return true
mockRequest.getUiSettingsService = () => ({ get: async () => true });
const setup = setupRequest(mockRequest);
await setup.client('myType', {});
const { client } = setupRequest(mockRequest);
await client('myType', {});
const params = callWithRequestSpy.mock.calls[0][2];
expect(params.ignore_throttled).toBe(false);
});
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/apm/server/lib/helpers/setup_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function decodeEsQuery(esQuery?: string) {
}

export interface APMSearchParams extends SearchParams {
omitLegacyData?: boolean;
includeLegacyData?: boolean;
}

export type ESClient = <T = void, U = void>(
Expand Down Expand Up @@ -69,10 +69,10 @@ export function isApmIndex(

function addFilterForLegacyData(
apmIndices: string[],
{ omitLegacyData = true, ...params }: APMSearchParams
{ includeLegacyData = false, ...params }: APMSearchParams
): SearchParams {
// search across all data (including data)
if (!omitLegacyData || !isApmIndex(apmIndices, params.index)) {
if (includeLegacyData || !isApmIndex(apmIndices, params.index)) {
return params;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getLegacyDataStatus(setup: Setup) {
const { client, config } = setup;

const params: APMSearchParams = {
omitLegacyData: false,
includeLegacyData: true,
terminateAfter: 1,
index: [config.get('apm_oss.transactionIndices')],
body: {
Expand Down

0 comments on commit c10b793

Please sign in to comment.