Skip to content

Commit

Permalink
adding filter by transaction name
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jul 21, 2020
1 parent 103f722 commit 148b827
Show file tree
Hide file tree
Showing 6 changed files with 761 additions and 4 deletions.
5 changes: 3 additions & 2 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 },
urlParams: { serviceName, start, end, transactionName },
uiFilters,
} = useUrlParams();

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

return {
Expand Down
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
10 changes: 9 additions & 1 deletion x-pack/plugins/apm/server/routes/transaction_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,23 @@ export const transactionGroupsAvgDurationByBrowser = createRoute(() => ({
path: t.type({
serviceName: t.string,
}),
query: t.intersection([uiFiltersRt, rangeRt]),
query: t.intersection([
t.partial({
transactionName: t.string,
}),
uiFiltersRt,
rangeRt,
]),
},
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
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', () => {
Expand All @@ -38,6 +40,14 @@ export default function ApiTest({ getService }: FtrProviderContext) {
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}&_debug=true`
);

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

0 comments on commit 148b827

Please sign in to comment.