kibana/x-pack/plugins/apm/server/lib/rum_client/get_client_metrics.ts
Søren Louv-Jansen 4ddcd1d2a6
[APM] Fix anomalies not showing up on transaction charts (#76930)
* [APM] Fix anomalies not showing up on transaction charts

* Added API tests to check transaction groups charts for anomaly data

* Improve test names and assertions from PR feedback

* Updated the transaction groups chart API to make `environment` a
required param while making `uiFilters` optional

* updates the basic API tests for transaction_groups/charts with the
required `environment` param

* makes uiFIltersES default to [] on core setup and removes SetupUIFilters type

* fixes vertical shade

* - replaces uiFiltersES with esFilter & uiFilters and cleans up related code around these
- deduplicates the required environment in the transaction_groups/charts API

* updates basic apm_api_integration tests

* pr feedback

* updates api test snapshots with correct anomaly data

* removed environment query param from useTransactionCharts and ensures
it's included in uiFilters returned from useUrlParams

Co-authored-by: Oliver Gupte <olivergupte@gmail.com>
2020-10-02 00:45:50 -07:00

76 lines
2.1 KiB
TypeScript

/*
* 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 { 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';
import {
TRANSACTION_DOM_INTERACTIVE,
TRANSACTION_TIME_TO_FIRST_BYTE,
} from '../../../common/elasticsearch_fieldnames';
export async function getClientMetrics({
setup,
urlQuery,
percentile = 50,
}: {
setup: Setup & SetupTimeRange;
urlQuery?: string;
percentile?: number;
}) {
const projection = getRumPageLoadTransactionsProjection({
setup,
urlQuery,
});
const params = mergeProjection(projection, {
body: {
size: 0,
aggs: {
pageViews: {
value_count: {
field: TRANSACTION_DURATION,
},
},
backEnd: {
percentiles: {
field: TRANSACTION_TIME_TO_FIRST_BYTE,
percents: [percentile],
hdr: {
number_of_significant_value_digits: 3,
},
},
},
domInteractive: {
percentiles: {
field: TRANSACTION_DOM_INTERACTIVE,
percents: [percentile],
hdr: {
number_of_significant_value_digits: 3,
},
},
},
},
},
});
const { apmEventClient } = setup;
const response = await apmEventClient.search(params);
const { backEnd, domInteractive, pageViews } = response.aggregations!;
const pkey = percentile.toFixed(1);
// Divide by 1000 to convert ms into seconds
return {
pageViews,
backEnd: { value: backEnd.values[pkey] || 0 },
frontEnd: {
value: (domInteractive.values[pkey] || 0) - (backEnd.values[pkey] || 0),
},
};
}