Skip to content

Commit

Permalink
[APM] Migrate /mobile API tests to deployment agnostic folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kpatticha committed Nov 5, 2024
1 parent 06e7f74 commit 4870a81
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import {
APIReturnType,
} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { RecursivePartial } from '@kbn/apm-plugin/typings/common';
import { FtrProviderContext } from '../../../common/ftr_provider_context';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context';

type ErrorGroups =
APIReturnType<'GET /internal/apm/mobile-services/{serviceName}/crashes/groups/main_statistics'>['errorGroups'];

export default function ApiTest({ getService }: FtrProviderContext) {
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const apmApiClient = getService('apmApi');
const synthtrace = getService('synthtrace');

const serviceName = 'synth-swift';
const start = new Date('2021-01-01T00:00:00.000Z').getTime();
Expand All @@ -45,7 +46,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});
}

registry.when('when data is not loaded', { config: 'basic', archives: [] }, () => {
registry.when('when data is not loaded', () => {
it('handles empty state', async () => {
const response = await callApi();
expect(response.status).to.be(200);
Expand All @@ -54,8 +55,10 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

// FLAKY: https://github.com/elastic/kibana/issues/177651
registry.when.skip('when data is loaded', { config: 'basic', archives: [] }, () => {
registry.when.skip('when data is loaded', () => {
describe('errors group', () => {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;

const appleTransaction = {
name: 'GET /apple 🍎 ',
successRate: 75,
Expand All @@ -73,6 +76,8 @@ export default function ApiTest({ getService }: FtrProviderContext) {
.service({ name: serviceName, environment: 'production', agentName: 'swift' })
.instance('instance-a');

apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();

await apmSynthtraceEsClient.index([
timerange(start, end)
.interval('1m')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import {
APIClientRequestParamsOf,
APIReturnType,
} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';

import { RecursivePartial } from '@kbn/apm-plugin/typings/common';
import { FtrProviderContext } from '../../../common/ftr_provider_context';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context';
import { config, generateData } from './generate_data';

type ErrorsDistribution =
APIReturnType<'GET /internal/apm/mobile-services/{serviceName}/crashes/distribution'>;

export default function ApiTest({ getService }: FtrProviderContext) {
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const apmApiClient = getService('apmApi');
const synthtrace = getService('synthtrace');

const serviceName = 'synth-swift';
const start = new Date('2021-01-01T00:00:00.000Z').getTime();
Expand Down Expand Up @@ -51,7 +53,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
return response;
}

registry.when('when data is not loaded', { config: 'basic', archives: [] }, () => {
registry.when('when data is not loaded', () => {
it('handles the empty state', async () => {
const response = await callApi();
expect(response.status).to.be(200);
Expand All @@ -61,10 +63,13 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

// FLAKY: https://github.com/elastic/kibana/issues/177652
registry.when.skip('when data is loaded', { config: 'basic', archives: [] }, () => {
registry.when.skip('when data is loaded', () => {
describe('errors distribution', () => {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;

const { appleTransaction, bananaTransaction } = config;
before(async () => {
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();
await generateData({ serviceName, start, end, apmSynthtraceEsClient });
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { service } from '@kbn/apm-synthtrace-client/src/lib/apm/service';
import { orderBy } from 'lodash';
import { APIReturnType } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { getErrorGroupingKey } from '@kbn/apm-synthtrace-client/src/lib/apm/instance';
import { FtrProviderContext } from '../../../common/ftr_provider_context';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context';
import { config, generateData } from './generate_data';

type ErrorGroupSamples =
Expand All @@ -19,10 +19,10 @@ type ErrorGroupSamples =
type ErrorSampleDetails =
APIReturnType<'GET /internal/apm/services/{serviceName}/errors/{groupId}/error/{errorId}'>;

export default function ApiTest({ getService }: FtrProviderContext) {
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const apmApiClient = getService('apmApi');
const synthtrace = getService('synthtrace');

const serviceName = 'synth-go';
const start = new Date('2021-01-01T00:00:00.000Z').getTime();
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
return response;
}

registry.when('when data is not loaded', { config: 'basic', archives: [] }, () => {
registry.when('when data is not loaded', () => {
it('handles the empty state', async () => {
const response = await callErrorGroupSamplesApi({ groupId: 'foo' });
expect(response.status).to.be(200);
Expand All @@ -76,7 +76,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

// FLAKY: https://github.com/elastic/kibana/issues/177654
registry.when.skip('when samples data is loaded', { config: 'basic', archives: [] }, () => {
registry.when.skip('when samples data is loaded', () => {
const { bananaTransaction } = config;
describe('error group id', () => {
before(async () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

// FLAKY: https://github.com/elastic/kibana/issues/177665
registry.when.skip('when error sample data is loaded', { config: 'basic', archives: [] }, () => {
registry.when.skip('when error sample data is loaded', () => {
describe('error sample id', () => {
before(async () => {
await generateData({ serviceName, start, end, apmSynthtraceEsClient });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import { ENVIRONMENT_ALL } from '@kbn/apm-plugin/common/environment_filter_value
import { isEmpty } from 'lodash';
import moment from 'moment';
import { APIReturnType } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';
import { generateMobileData, SERVICE_VERSIONS } from './generate_mobile_data';

type MobileDetailedStatisticsResponse =
APIReturnType<'GET /internal/apm/mobile-services/{serviceName}/detailed_statistics'>;

export default function ApiTest({ getService }: FtrProviderContext) {
const apmApiClient = getService('apmApiClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const registry = getService('registry');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const synthtrace = getService('synthtrace');
let apmSynthtraceEsClient: ApmSynthtraceEsClient;

const start = new Date('2023-01-01T00:00:00.000Z').getTime();
const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1;
Expand Down Expand Up @@ -58,7 +60,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

registry.when(
'Mobile detailed statistics when data is not loaded',
{ config: 'basic', archives: [] },

() => {
describe('when no data', () => {
it('handles empty state', async () => {
Expand All @@ -73,11 +75,11 @@ export default function ApiTest({ getService }: FtrProviderContext) {
);

// FLAKY: https://github.com/elastic/kibana/issues/177388
registry.when.skip(
'Mobile detailed statistics when data is loaded',
{ config: 'basic', archives: [] },
() => {
registry.when.skip('Mobile detailed statistics when data is loaded', () => {
describe('Mobile detailed statistics', () => {
before(async () => {
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();

await generateMobileData({
apmSynthtraceEsClient,
start,
Expand Down Expand Up @@ -133,6 +135,6 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});
});
});
}
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { APIReturnType } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { ENVIRONMENT_ALL } from '@kbn/apm-plugin/common/environment_filter_values';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

type MobileFilters = APIReturnType<'GET /internal/apm/services/{serviceName}/mobile/filters'>;

Expand Down Expand Up @@ -133,10 +133,10 @@ async function generateData({
]);
}

export default function ApiTest({ getService }: FtrProviderContext) {
const apmApiClient = getService('apmApiClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const registry = getService('registry');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const synthtrace = getService('synthtrace');

const start = new Date('2023-01-01T00:00:00.000Z').getTime();
const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1;
Expand Down Expand Up @@ -166,7 +166,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
.then(({ body }) => body);
}

registry.when('Mobile filters when data is not loaded', { config: 'basic', archives: [] }, () => {
registry.when('Mobile filters when data is not loaded', () => {
describe('when no data', () => {
it('handles empty state', async () => {
const response = await getMobileFilters({ serviceName: 'foo' });
Expand All @@ -178,7 +178,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

// FLAKY: https://github.com/elastic/kibana/issues/177389
registry.when.skip('Mobile filters', { config: 'basic', archives: [] }, () => {
registry.when.skip('Mobile filters', () => {
before(async () => {
await generateData({
apmSynthtraceEsClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import expect from '@kbn/expect';
import { ENVIRONMENT_ALL } from '@kbn/apm-plugin/common/environment_filter_values';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';
import { generateMobileData } from './generate_mobile_data';

export default function ApiTest({ getService }: FtrProviderContext) {
const apmApiClient = getService('apmApiClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const registry = getService('registry');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const synthtrace = getService('synthtrace');

const start = new Date('2023-01-01T00:00:00.000Z').getTime();
const end = new Date('2023-01-01T02:00:00.000Z').getTime();
Expand Down Expand Up @@ -49,7 +49,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

registry.when.skip(
'Mobile HTTP requests without data loaded',
{ config: 'basic', archives: [] },

() => {
describe('when no data', () => {
it('handles empty state', async () => {
Expand All @@ -65,7 +65,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
// FLAKY: https://github.com/elastic/kibana/issues/177390
registry.when.skip(
'Mobile HTTP requests with data loaded',
{ config: 'basic', archives: [] },

() => {
before(async () => {
await generateMobileData({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { APIReturnType } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { ENVIRONMENT_ALL } from '@kbn/apm-plugin/common/environment_filter_values';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

type MobileLocationStats =
APIReturnType<'GET /internal/apm/mobile-services/{serviceName}/location/stats'>;
Expand Down Expand Up @@ -176,10 +176,10 @@ async function generateData({
]);
}

export default function ApiTest({ getService }: FtrProviderContext) {
const apmApiClient = getService('apmApiClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const registry = getService('registry');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const synthtrace = getService('synthtrace');

const start = new Date('2023-01-01T00:00:00.000Z').getTime();
const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1;
Expand Down Expand Up @@ -212,7 +212,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
.then(({ body }) => body);
}

registry.when('Location stats when data is not loaded', { config: 'basic', archives: [] }, () => {
registry.when('Location stats when data is not loaded', () => {
describe('when no data', () => {
it('handles empty state', async () => {
const response = await getMobileLocationStats({ serviceName: 'foo' });
Expand All @@ -233,7 +233,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

// FLAKY: https://github.com/elastic/kibana/issues/177396
registry.when.skip('Location stats', { config: 'basic', archives: [] }, () => {
registry.when.skip('Location stats', () => {
before(async () => {
await generateData({
apmSynthtraceEsClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import expect from '@kbn/expect';
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { ENVIRONMENT_ALL } from '@kbn/apm-plugin/common/environment_filter_values';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

const GALAXY_DURATION = 500;
const HUAWEI_DURATION = 20;
Expand Down Expand Up @@ -126,10 +126,10 @@ async function generateData({
]);
}

export default function ApiTest({ getService }: FtrProviderContext) {
const apmApiClient = getService('apmApiClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const registry = getService('registry');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const synthtrace = getService('synthtrace');

const start = new Date('2023-01-01T00:00:00.000Z').getTime();
const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1;
Expand Down Expand Up @@ -164,7 +164,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

registry.when(
'Mobile main statistics when data is not loaded',
{ config: 'basic', archives: [] },

() => {
describe('when no data', () => {
it('handles empty state', async () => {
Expand All @@ -179,7 +179,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
);

// FLAKY: https://github.com/elastic/kibana/issues/177395
registry.when.skip('Mobile main statistics', { config: 'basic', archives: [] }, () => {
registry.when.skip('Mobile main statistics', () => {
before(async () => {
await generateData({
apmSynthtraceEsClient,
Expand Down
Loading

0 comments on commit 4870a81

Please sign in to comment.