Skip to content

Commit

Permalink
Query adjustments for getClientMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Oct 26, 2020
1 parent a91fbae commit 4e9479d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions x-pack/plugins/apm/server/lib/rum_client/get_client_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { TRANSACTION_DURATION } from '../../../common/elasticsearch_fieldnames';
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
import { mergeProjection } from '../../projections/util/merge_projection';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
Expand All @@ -25,17 +24,14 @@ export async function getClientMetrics({
const projection = getRumPageLoadTransactionsProjection({
setup,
urlQuery,
checkFetchStartFieldExists: false,
});

const params = mergeProjection(projection, {
body: {
size: 0,
track_total_hits: true,
aggs: {
pageViews: {
value_count: {
field: TRANSACTION_DURATION,
},
},
backEnd: {
percentiles: {
field: TRANSACTION_TIME_TO_FIRST_BYTE,
Expand All @@ -59,15 +55,14 @@ export async function getClientMetrics({
});

const { apmEventClient } = setup;

const response = await apmEventClient.search(params);
const { backEnd, domInteractive, pageViews } = response.aggregations!;
const { backEnd, domInteractive } = response.aggregations!;

const pkey = percentile.toFixed(1);

// Divide by 1000 to convert ms into seconds
return {
pageViews,
pageViews: { value: response.hits.total.value ?? 0 },
backEnd: { value: backEnd.values[pkey] || 0 },
frontEnd: {
value: (domInteractive.values[pkey] || 0) - (backEnd.values[pkey] || 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,29 @@ import { TRANSACTION_PAGE_LOAD } from '../../common/transaction_types';
export function getRumPageLoadTransactionsProjection({
setup,
urlQuery,
checkFetchStartFieldExists = true,
}: {
setup: Setup & SetupTimeRange;
urlQuery?: string;
checkFetchStartFieldExists?: boolean;
}) {
const { start, end, esFilter } = setup;

const bool = {
filter: [
{ range: rangeFilter(start, end) },
{ term: { [TRANSACTION_TYPE]: TRANSACTION_PAGE_LOAD } },
{
// Adding this filter to cater for some inconsistent rum data
// not available on aggregated transactions
exists: {
field: 'transaction.marks.navigationTiming.fetchStart',
},
},
...(checkFetchStartFieldExists
? [
{
// Adding this filter to cater for some inconsistent rum data
// not available on aggregated transactions
exists: {
field: 'transaction.marks.navigationTiming.fetchStart',
},
},
]
: []),
...(urlQuery
? [
{
Expand Down

0 comments on commit 4e9479d

Please sign in to comment.