Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX] Migrate long task metric to UX #134711

Merged
merged 6 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

12 changes: 0 additions & 12 deletions x-pack/plugins/apm/server/routes/rum_client/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '../../utils/test_helpers';
import { getPageViewTrends } from './get_page_view_trends';
import { getPageLoadDistribution } from './get_page_load_distribution';
import { getLongTaskMetrics } from './get_long_task_metrics';

describe('rum client dashboard queries', () => {
let mock: SearchParamsMock;
Expand Down Expand Up @@ -48,15 +47,4 @@ describe('rum client dashboard queries', () => {
);
expect(mock.params).toMatchSnapshot();
});

it('fetches long task metrics', async () => {
mock = await inspectSearchParams((setup) =>
getLongTaskMetrics({
setup,
start: 0,
end: 50000,
})
);
expect(mock.params).toMatchSnapshot();
});
});
31 changes: 0 additions & 31 deletions x-pack/plugins/apm/server/routes/rum_client/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import * as t from 'io-ts';
import { Logger } from '@kbn/core/server';
import { setupRequest, Setup } from '../../lib/helpers/setup_request';
import { getLongTaskMetrics } from './get_long_task_metrics';
import { getPageLoadDistribution } from './get_page_load_distribution';
import { getPageViewTrends } from './get_page_view_trends';
import { getPageLoadDistBreakdown } from './get_pl_dist_breakdown';
Expand Down Expand Up @@ -180,35 +179,6 @@ const rumVisitorsBreakdownRoute = createApmServerRoute({
},
});

const rumLongTaskMetrics = createApmServerRoute({
endpoint: 'GET /internal/apm/ux/long-task-metrics',
params: t.type({
query: uxQueryRt,
}),
options: { tags: ['access:apm'] },
handler: async (
resources
): Promise<{
noOfLongTasks: number;
sumOfLongTasks: number;
longestLongTask: number;
}> => {
const setup = await setupUXRequest(resources);

const {
query: { urlQuery, percentile, start, end },
} = resources.params;

return getLongTaskMetrics({
setup,
urlQuery,
percentile: percentile ? Number(percentile) : undefined,
start,
end,
});
},
});

function decodeUiFilters(
logger: Logger,
uiFiltersEncoded?: string
Expand Down Expand Up @@ -243,5 +213,4 @@ export const rumRouteRepository = {
...rumPageLoadDistBreakdownRoute,
...rumPageViewsTrendRoute,
...rumVisitorsBreakdownRoute,
...rumLongTaskMetrics,
};
1 change: 1 addition & 0 deletions x-pack/plugins/ux/e2e/journeys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './core_web_vitals';
export * from './url_ux_query.journey';
export * from './ux_js_errors.journey';
export * from './ux_client_metrics.journey';
export * from './ux_long_task_metric_journey';
79 changes: 79 additions & 0 deletions x-pack/plugins/ux/e2e/journeys/ux_long_task_metric_journey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { journey, step, before, expect } from '@elastic/synthetics';
import { UXDashboardDatePicker } from '../page_objects/date_picker';
import { byTestId, loginToKibana, waitForLoadingToFinish } from './utils';

const longestMetric = 'uxLongestTask';
const countMetric = 'uxLongTaskCount';
const sumMetric = 'uxSumLongTask';

const longestMetricValue = `Longest long task duration

237 ms`;
const countMetricValue = `No. of long tasks

3`;
const sumMetricValue = `Total long tasks duration

428 ms`;

journey('UX LongTaskMetrics', async ({ page, params }) => {
before(async () => {
await waitForLoadingToFinish({ page });
});

const queryParams = {
percentile: '50',
rangeFrom: '2020-05-18T11:51:00.000Z',
rangeTo: '2021-10-30T06:37:15.536Z',
};
const queryString = new URLSearchParams(queryParams).toString();

const baseUrl = `${params.kibanaUrl}/app/ux`;

step('Go to UX Dashboard', async () => {
await page.goto(`${baseUrl}?${queryString}`, {
waitUntil: 'networkidle',
});
await loginToKibana({
page,
user: { username: 'viewer', password: 'changeme' },
});
});

step('Set date range', async () => {
const datePickerPage = new UXDashboardDatePicker(page);
await datePickerPage.setDefaultE2eRange();
});

step('Confirm metrics values', async () => {
// Wait until chart data is loaded
page.waitForLoadState('networkidle');
// wait for first metric to be shown
page.waitForSelector(`text="237 ms"`);

let metric = await (
await page.waitForSelector(byTestId(longestMetric))
).innerText();

expect(metric).toBe(longestMetricValue);

metric = await (
await page.waitForSelector(byTestId(countMetric))
).innerText();

expect(metric).toBe(countMetricValue);

metric = await (
await page.waitForSelector(byTestId(sumMetric))
).innerText();

expect(metric).toBe(sumMetricValue);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@

import React from 'react';
import { render, Matcher } from '@testing-library/react';
import * as fetcherHook from '../../../../hooks/use_fetcher';
import * as queryHook from '../../../../hooks/use_long_task_metrics_query';
import { KeyUXMetrics } from './key_ux_metrics';
import { FETCH_STATUS } from '@kbn/observability-plugin/public';

describe('KeyUXMetrics', () => {
it('renders metrics with correct formats', () => {
jest.spyOn(fetcherHook, 'useFetcher').mockReturnValue({
jest.spyOn(queryHook, 'useLongTaskMetricsQuery').mockReturnValue({
data: {
noOfLongTasks: 3.0009765625,
sumOfLongTasks: 520.4375,
longestLongTask: 271.4375,
},
status: FETCH_STATUS.SUCCESS,
refetch: jest.fn(),
loading: false,
});
const { getAllByText } = render(
<KeyUXMetrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import { EuiFlexItem, EuiStat, EuiFlexGroup, EuiIconTip } from '@elastic/eui';
import numeral from '@elastic/numeral';
import { UXMetrics } from '@kbn/observability-plugin/public';
import { useLongTaskMetricsQuery } from '../../../../hooks/use_long_task_metrics_query';
import {
DATA_UNDEFINED_LABEL,
FCP_LABEL,
Expand All @@ -22,8 +23,6 @@ import {
TBT_LABEL,
TBT_TOOLTIP,
} from './translations';
import { useFetcher } from '../../../../hooks/use_fetcher';
import { useUxQuery } from '../hooks/use_ux_query';

export function formatToSec(
value?: number | string,
Expand All @@ -50,23 +49,8 @@ function formatTitle(unit: string, value?: number | null) {
}

export function KeyUXMetrics({ data, loading }: Props) {
const uxQuery = useUxQuery();

const { data: longTaskData, status } = useFetcher(
(callApmApi) => {
if (uxQuery) {
return callApmApi('GET /internal/apm/ux/long-task-metrics', {
params: {
query: {
...uxQuery,
},
},
});
}
return Promise.resolve(null);
},
[uxQuery]
);
const { data: longTaskData, loading: loadingLongTask } =
useLongTaskMetricsQuery();

// Note: FCP value is in ms unit
return (
Expand Down Expand Up @@ -99,6 +83,7 @@ export function KeyUXMetrics({ data, loading }: Props) {
</EuiFlexItem>
<EuiFlexItem grow={false} style={STAT_STYLE}>
<EuiStat
data-test-subj="uxLongTaskCount"
titleSize="s"
title={
longTaskData?.noOfLongTasks !== undefined
Expand All @@ -114,11 +99,12 @@ export function KeyUXMetrics({ data, loading }: Props) {
/>
</>
}
isLoading={status !== 'success'}
isLoading={!!loadingLongTask}
/>
</EuiFlexItem>
<EuiFlexItem grow={false} style={STAT_STYLE}>
<EuiStat
data-test-subj="uxLongestTask"
titleSize="s"
title={formatTitle('ms', longTaskData?.longestLongTask)}
description={
Expand All @@ -130,11 +116,12 @@ export function KeyUXMetrics({ data, loading }: Props) {
/>
</>
}
isLoading={status !== 'success'}
isLoading={!!loadingLongTask}
/>
</EuiFlexItem>
<EuiFlexItem grow={false} style={STAT_STYLE}>
<EuiStat
data-test-subj="uxSumLongTask"
titleSize="s"
title={formatTitle('ms', longTaskData?.sumOfLongTasks)}
description={
Expand All @@ -146,7 +133,7 @@ export function KeyUXMetrics({ data, loading }: Props) {
/>
</>
}
isLoading={status !== 'success'}
isLoading={!!loadingLongTask}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Loading