Skip to content

Commit

Permalink
[APM] Add API tests
Browse files Browse the repository at this point in the history
remove raw json

Sort service items

Fix tsc

Add test for trace overview

Move sorting to test

replace “should”

Update x-pack/test/apm_api_integration/basic/tests/services/top_services.ts

Co-authored-by: Nathan L Smith <nathan.smith@elastic.co>

Update x-pack/test/apm_api_integration/basic/tests/services/transactions/agent_name.ts

Co-authored-by: Nathan L Smith <nathan.smith@elastic.co>

Update x-pack/test/apm_api_integration/basic/tests/services/transactions/transaction_charts.ts

Co-authored-by: Nathan L Smith <nathan.smith@elastic.co>

Add additional agent config test
  • Loading branch information
sorenlouv committed Jul 7, 2020
1 parent 7d44d02 commit 95d684f
Show file tree
Hide file tree
Showing 15 changed files with 33,409 additions and 11 deletions.
Binary file not shown.
25,698 changes: 25,698 additions & 0 deletions x-pack/test/apm_api_integration/basic/fixtures/es_archiver/8.0.0/mappings.json

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions x-pack/test/apm_api_integration/basic/tests/agent_configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ export default function agentConfigurationTests({ getService }: FtrProviderConte
const supertestRead = getService('supertestAsApmReadUser');
const supertestWrite = getService('supertestAsApmWriteUser');
const log = getService('log');
const esArchiver = getService('esArchiver');

function getServices() {
return supertestRead
.get(`/api/apm/settings/agent-configuration/services`)
.set('kbn-xsrf', 'foo');
}

function getEnvironments(serviceName: string) {
return supertestRead
.get(`/api/apm/settings/agent-configuration/environments?serviceName=${serviceName}`)
.set('kbn-xsrf', 'foo');
}

function getAgentName(serviceName: string) {
return supertestRead
.get(`/api/apm/settings/agent-configuration/agent_name?serviceName=${serviceName}`)
.set('kbn-xsrf', 'foo');
}

function searchConfigurations(configuration: any) {
return supertestRead
Expand Down Expand Up @@ -68,6 +87,46 @@ export default function agentConfigurationTests({ getService }: FtrProviderConte
}

describe('agent configuration', () => {
describe('when no data is loaded', () => {
it('handles the empty state for services', async () => {
const { body } = await getServices();
expect(body).to.eql(['ALL_OPTION_VALUE']);
});

it('handles the empty state for environments', async () => {
const { body } = await getEnvironments('myservice');
expect(body).to.eql([{ name: 'ALL_OPTION_VALUE', alreadyConfigured: false }]);
});

it('handles the empty state for agent names', async () => {
const { body } = await getAgentName('myservice');
expect(body).to.eql({});
});
});

describe('when data is loaded', () => {
before(() => esArchiver.load('8.0.0'));
after(() => esArchiver.unload('8.0.0'));

it('returns all services', async () => {
const { body } = await getServices();
expect(body).to.eql(['ALL_OPTION_VALUE', 'client', 'opbeans-java', 'opbeans-node']);
});

it('returns the environments', async () => {
const { body } = await getEnvironments('opbeans-node');
expect(body).to.eql([
{ name: 'ALL_OPTION_VALUE', alreadyConfigured: false },
{ name: 'production', alreadyConfigured: false },
]);
});

it('returns the agent names', async () => {
const { body } = await getAgentName('opbeans-node');
expect(body).to.eql({ agentName: 'nodejs' });
});
});

describe('when creating one configuration', () => {
const newConfig = {
service: {},
Expand Down
12 changes: 12 additions & 0 deletions x-pack/test/apm_api_integration/basic/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,17 @@ export default function apmApiIntegrationTests({ loadTestFile }: FtrProviderCont
loadTestFile(require.resolve('./agent_configuration'));
loadTestFile(require.resolve('./custom_link'));
loadTestFile(require.resolve('./service_maps'));

// traces
loadTestFile(require.resolve('./traces/top_traces'));

// services
loadTestFile(require.resolve('./services/top_services'));

// services/transaction
loadTestFile(require.resolve('./services/transactions/top_transaction_groups'));
loadTestFile(require.resolve('./services/transactions/transaction_charts'));
loadTestFile(require.resolve('./services/transactions/agent_name'));
loadTestFile(require.resolve('./services/transactions/transaction_types'));
});
}
10 changes: 6 additions & 4 deletions x-pack/test/apm_api_integration/basic/tests/service_maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { FtrProviderContext } from '../../common/ftr_provider_context';
export default function serviceMapsApiTests({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

// url parameters
const start = encodeURIComponent('2020-06-29T06:45:00.000Z');
const end = encodeURIComponent('2020-06-29T06:49:00.000Z');

describe('Service Maps', () => {
it('should only be available to users with Platinum license (or higher)', async () => {
const response = await supertest.get(
'/api/apm/service-map?start=2020-06-28T10%3A24%3A46.055Z&end=2020-06-29T10%3A24%3A46.055Z'
);
it('is only be available to users with Platinum license (or higher)', async () => {
const response = await supertest.get(`/api/apm/service-map?start=${start}&end=${end}`);

expect(response.status).to.be(403);
expect(response.body.message).to.be(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.
*/

import { sortBy } from 'lodash';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');

// url parameters
const start = encodeURIComponent('2020-06-29T06:45:00.000Z');
const end = encodeURIComponent('2020-06-29T06:49:00.000Z');
const uiFilters = encodeURIComponent(JSON.stringify({}));

describe('APM Services Overview', () => {
describe('when data is not loaded ', () => {
it('handles the empty state', async () => {
const response = await supertest.get(
`/api/apm/services?start=${start}&end=${end}&uiFilters=${uiFilters}`
);

expect(response.status).to.be(200);
expect(response.body).to.eql({ hasHistoricalData: false, hasLegacyData: false, items: [] });
});
});

describe('when data is loaded', () => {
before(() => esArchiver.load('8.0.0'));
after(() => esArchiver.unload('8.0.0'));

it('returns a list of services', async () => {
const response = await supertest.get(
`/api/apm/services?start=${start}&end=${end}&uiFilters=${uiFilters}`
);
// sort services to mitigate unstable sort order
const services = sortBy(response.body.items, ['serviceName']);

expect(response.status).to.be(200);
expect(services).to.eql([
{
serviceName: 'client',
agentName: 'rum-js',
transactionsPerMinute: 2,
errorsPerMinute: 2.75,
avgResponseTime: 116375,
environments: [],
},
{
serviceName: 'opbeans-java',
agentName: 'java',
transactionsPerMinute: 30.75,
errorsPerMinute: 4.5,
avgResponseTime: 25636.349593495936,
environments: ['production'],
},
{
serviceName: 'opbeans-node',
agentName: 'nodejs',
transactionsPerMinute: 31,
errorsPerMinute: 3.75,
avgResponseTime: 38682.52419354839,
environments: ['production'],
},
]);

expect(response.body.hasHistoricalData).to.be(true);
expect(response.body.hasLegacyData).to.be(false);
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');

// url parameters
const start = encodeURIComponent('2020-06-29T06:45:00.000Z');
const end = encodeURIComponent('2020-06-29T06:49:00.000Z');

describe('Agent name', () => {
describe('when data is not loaded ', () => {
it('handles the empty state', async () => {
const response = await supertest.get(
`/api/apm/services/opbeans-node/agent_name?start=${start}&end=${end}`
);

expect(response.status).to.be(200);
expect(response.body).to.eql({});
});
});

describe('when data is loaded', () => {
before(() => esArchiver.load('8.0.0'));
after(() => esArchiver.unload('8.0.0'));

it('returns the agent name', async () => {
const response = await supertest.get(
`/api/apm/services/opbeans-node/agent_name?start=${start}&end=${end}`
);

expect(response.status).to.be(200);
expect(response.body).to.eql({ agentName: 'nodejs' });
});
});
});
}
Loading

0 comments on commit 95d684f

Please sign in to comment.