Skip to content

Commit

Permalink
[User experience] Fix JS error rate (#81512) (#81889)
Browse files Browse the repository at this point in the history
* Query adjustments for getClientMetrics
* Remove error rate from JS errors section
  • Loading branch information
Kerry350 committed Oct 28, 2020
1 parent 393050e commit 19db1ea
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ Then(`it displays list of relevant js errors`, () => {
cy.get('.euiBasicTable-loading').should('not.be.visible');
cy.get('.euiStat__title-isLoading').should('not.be.visible');

getDataTestSubj('uxJsErrorsTotal').should('have.text', 'Total errors110');

getDataTestSubj('uxJsErrorRate').should(
'have.text',
'Error rate100 %Error rate 100 %'
);
getDataTestSubj('uxJsErrorsTotal').should('have.text', 'Total errors112');

getDataTestSubj('uxJsErrorTable').within(() => {
cy.get('tr.euiTableRow', DEFAULT_TIMEOUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
EuiToolTip,
} from '@elastic/eui';
import numeral from '@elastic/numeral';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { useUrlParams } from '../../../../hooks/useUrlParams';
import { useFetcher } from '../../../../hooks/useFetcher';
Expand Down Expand Up @@ -102,11 +101,6 @@ export function JSErrors() {
});
};

const errorRate =
totalPageViews > 0
? ((data?.totalErrorPages ?? 0) / totalPageViews) * 100
: 0;

const totalErrors = data?.totalErrors ?? 0;

return (
Expand All @@ -133,20 +127,6 @@ export function JSErrors() {
isLoading={status !== 'success'}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiStat
data-test-subj={'uxJsErrorRate'}
titleSize="s"
title={i18n.translate('xpack.apm.rum.jsErrors.errorRateValue', {
defaultMessage: '{errorRate} %',
values: {
errorRate: errorRate.toFixed(0),
},
})}
description={I18LABELS.errorRate}
isLoading={status !== 'success'}
/>
</EuiFlexItem>{' '}
</EuiFlexGroup>
<EuiSpacer size="s" />
<EuiBasicTable
Expand Down

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

48 changes: 26 additions & 22 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,32 +24,36 @@ 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,
hasFetchStartField: {
filter: {
exists: { field: 'transaction.marks.navigationTiming.fetchStart' },
},
},
backEnd: {
percentiles: {
field: TRANSACTION_TIME_TO_FIRST_BYTE,
percents: [percentile],
hdr: {
number_of_significant_value_digits: 3,
aggs: {
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,
domInteractive: {
percentiles: {
field: TRANSACTION_DOM_INTERACTIVE,
percents: [percentile],
hdr: {
number_of_significant_value_digits: 3,
},
},
},
},
},
Expand All @@ -59,15 +62,16 @@ export async function getClientMetrics({
});

const { apmEventClient } = setup;

const response = await apmEventClient.search(params);
const { backEnd, domInteractive, pageViews } = response.aggregations!;
const {
hasFetchStartField: { 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 @@ -20,6 +20,7 @@ export async function getPageViewTrends({
const projection = getRumPageLoadTransactionsProjection({
setup,
urlQuery,
checkFetchStartFieldExists: false,
});
let breakdownItem: BreakdownItem | null = null;
if (breakdowns) {
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 Expand Up @@ -74,7 +80,6 @@ export function getRumErrorsProjection({
filter: [
{ range: rangeFilter(start, end) },
{ term: { [AGENT_NAME]: 'rum-js' } },
{ term: { [TRANSACTION_TYPE]: TRANSACTION_PAGE_LOAD } },
{
term: {
[SERVICE_LANGUAGE_NAME]: 'javascript',
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -5048,7 +5048,6 @@
"xpack.apm.rum.filters.url.noResults": "結果がありません",
"xpack.apm.rum.jsErrors.errorMessage": "エラーメッセージ",
"xpack.apm.rum.jsErrors.errorRate": "エラー率",
"xpack.apm.rum.jsErrors.errorRateValue": "{errorRate} %",
"xpack.apm.rum.jsErrors.impactedPageLoads": "影響を受けるページ読み込み数",
"xpack.apm.rum.jsErrors.totalErrors": "合計エラー数",
"xpack.apm.rum.userExperienceMetrics": "ユーザーエクスペリエンスメトリック",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -5052,7 +5052,6 @@
"xpack.apm.rum.filters.url.noResults": "没有可用结果",
"xpack.apm.rum.jsErrors.errorMessage": "错误消息",
"xpack.apm.rum.jsErrors.errorRate": "错误率",
"xpack.apm.rum.jsErrors.errorRateValue": "{errorRate}%",
"xpack.apm.rum.jsErrors.impactedPageLoads": "受影响的页面加载",
"xpack.apm.rum.jsErrors.totalErrors": "错误总数",
"xpack.apm.rum.userExperienceMetrics": "用户体验指标",
Expand Down

0 comments on commit 19db1ea

Please sign in to comment.