Skip to content

Commit

Permalink
adding api test for transaction_groups /breakdown and /avg_duration_b…
Browse files Browse the repository at this point in the history
…y_browser
  • Loading branch information
cauemarcondes committed Jul 21, 2020
1 parent c5073f4 commit 103f722
Show file tree
Hide file tree
Showing 8 changed files with 1,094 additions and 11 deletions.
5 changes: 2 additions & 3 deletions x-pack/plugins/apm/public/hooks/useAvgDurationByBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function toTimeSeries(data?: AvgDurationByBrowserAPIResponse): TimeSeries[] {

export function useAvgDurationByBrowser() {
const {
urlParams: { serviceName, start, end, transactionName },
urlParams: { serviceName, start, end },
uiFilters,
} = useUrlParams();

Expand All @@ -43,14 +43,13 @@ export function useAvgDurationByBrowser() {
query: {
start,
end,
transactionName,
uiFilters: JSON.stringify(uiFilters),
},
},
});
}
},
[serviceName, start, end, transactionName, uiFilters]
[serviceName, start, end, uiFilters]
);

return {
Expand Down
9 changes: 1 addition & 8 deletions x-pack/plugins/apm/server/routes/transaction_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,7 @@ export const transactionGroupsAvgDurationByBrowser = createRoute(() => ({
path: t.type({
serviceName: t.string,
}),
query: t.intersection([
t.partial({
transactionType: t.string,
transactionName: t.string,
}),
uiFiltersRt,
rangeRt,
]),
query: t.intersection([uiFiltersRt, rangeRt]),
},
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
Expand Down
2 changes: 2 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 @@ -35,6 +35,8 @@ export default function apmApiIntegrationTests({ loadTestFile }: FtrProviderCont
loadTestFile(require.resolve('./transaction_groups/top_transaction_groups'));
loadTestFile(require.resolve('./transaction_groups/transaction_charts'));
loadTestFile(require.resolve('./transaction_groups/error_rate'));
loadTestFile(require.resolve('./transaction_groups/breakdown'));
loadTestFile(require.resolve('./transaction_groups/avg_duration_by_browser'));
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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';
import expectedAvgDurationByBrowser from './expectation/avg_duration_by_browser.json';

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

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

describe('Average duration by browser', () => {
describe('when data is not loaded', () => {
it('handles the empty state', async () => {
const response = await supertest.get(
`/api/apm/services/client/transaction_groups/avg_duration_by_browser?start=${start}&end=${end}&uiFilters=${uiFilters}`
);
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 average duration by browser', async () => {
const response = await supertest.get(
`/api/apm/services/client/transaction_groups/avg_duration_by_browser?start=${start}&end=${end}&uiFilters=${uiFilters}`
);

expect(response.status).to.be(200);
expect(response.body).to.eql(expectedAvgDurationByBrowser);
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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';
import expectedBreakdown from './expectation/breakdown.json';
import expectedBreakdownWithTransactionName from './expectation/breakdown_transaction_name.json';

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

const start = encodeURIComponent('2020-06-29T06:45:00.000Z');
const end = encodeURIComponent('2020-06-29T06:49:00.000Z');
const transactionType = 'request';
const transactionName = 'GET /api';
const uiFilters = encodeURIComponent(JSON.stringify({}));

describe('Breakdown', () => {
describe('when data is not loaded', () => {
it('handles the empty state', async () => {
const response = await supertest.get(
`/api/apm/services/opbeans-node/transaction_groups/breakdown?start=${start}&end=${end}&uiFilters=${uiFilters}&transactionType=${transactionType}`
);
expect(response.status).to.be(200);
expect(response.body).to.eql({ kpis: [], timeseries: [] });
});
});

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

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

expect(response.status).to.be(200);
expect(response.body).to.eql(expectedBreakdown);
});
it('returns the transaction breakdown with transaction name', async () => {
const response = await supertest.get(
`/api/apm/services/opbeans-node/transaction_groups/breakdown?start=${start}&end=${end}&uiFilters=${uiFilters}&transactionType=${transactionType}&transactionName=${transactionName}`
);

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

0 comments on commit 103f722

Please sign in to comment.