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 (#72623) (#72840)

* adding api test for transaction_groups /breakdown and /avg_duration_by_browser

* adding filter by transaction name

* adding filter by transaction name

* addressing pr comments

* fixing TS issue

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Cauê Marcondes <55978943+cauemarcondes@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 22, 2020
1 parent 2c0e089 commit 45eb60a
Show file tree
Hide file tree
Showing 10 changed files with 1,855 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TRANSACTION_TYPE,
USER_AGENT_NAME,
TRANSACTION_DURATION,
TRANSACTION_NAME,
} from '../../../../common/elasticsearch_fieldnames';
import { rangeFilter } from '../../../../common/utils/range_filter';
import { getBucketSize } from '../../helpers/get_bucket_size';
Expand All @@ -23,15 +24,20 @@ export type ESResponse = PromiseReturnType<typeof fetcher>;

export function fetcher(options: Options) {
const { end, client, indices, start, uiFiltersES } = options.setup;
const { serviceName } = options;
const { serviceName, transactionName } = options;
const { intervalString } = getBucketSize(start, end, 'auto');

const transactionNameFilter = transactionName
? [{ term: { [TRANSACTION_NAME]: transactionName } }]
: [];

const filter: ESFilter[] = [
{ term: { [PROCESSOR_EVENT]: ProcessorEvent.transaction } },
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [TRANSACTION_TYPE]: TRANSACTION_PAGE_LOAD } },
{ range: rangeFilter(start, end) },
...uiFiltersES,
...transactionNameFilter,
];

const params = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { transformer } from './transformer';
export interface Options {
serviceName: string;
setup: Setup & SetupTimeRange & SetupUIFilters;
transactionName?: string;
}

export type AvgDurationByBrowserAPIResponse = Array<{
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/routes/transaction_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export const transactionGroupsAvgDurationByBrowser = createRoute(() => ({
}),
query: t.intersection([
t.partial({
transactionType: t.string,
transactionName: t.string,
}),
uiFiltersRt,
Expand All @@ -174,10 +173,12 @@ export const transactionGroupsAvgDurationByBrowser = createRoute(() => ({
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.path;
const { transactionName } = context.params.query;

return getTransactionAvgDurationByBrowser({
serviceName,
setup,
transactionName,
});
},
}));
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'));
});

describe('Observability overview', function () {
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.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../common/ftr_provider_context';
import expectedAvgDurationByBrowser from './expectation/avg_duration_by_browser.json';
import expectedAvgDurationByBrowserWithTransactionName from './expectation/avg_duration_by_browser_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 transactionName = '/products';
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);
});
it('returns the average duration by browser filtering by transaction name', async () => {
const response = await supertest.get(
`/api/apm/services/client/transaction_groups/avg_duration_by_browser?start=${start}&end=${end}&uiFilters=${uiFilters}&transactionName=${transactionName}`
);

expect(response.status).to.be(200);
expect(response.body).to.eql(expectedAvgDurationByBrowserWithTransactionName);
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 for a service', 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 for a transaction group', 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);
});
it('returns the top 4 by percentage and sorts them by name', 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.kpis.map((kpi: { name: string }) => kpi.name)).to.eql([
'app',
'http',
'postgresql',
'redis',
]);
});
});
});
}
Loading

0 comments on commit 45eb60a

Please sign in to comment.