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

[APM] Break down error table api removing the sparklines #89138

Merged
merged 22 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
af0e4d4
breaking error table api
cauemarcondes Jan 25, 2021
d258dca
shows loading state while fetching metrics
cauemarcondes Jan 25, 2021
020370d
adding api tests
cauemarcondes Jan 25, 2021
1f9d447
Merge branch 'master' of github.com:elastic/kibana into apm-error-tab…
cauemarcondes Feb 1, 2021
a97ae4c
removing pagination from server
cauemarcondes Feb 1, 2021
d3bee4e
Merge branch 'master' of github.com:elastic/kibana into apm-error-tab…
cauemarcondes Feb 2, 2021
92e9e53
adding API test
cauemarcondes Feb 2, 2021
f84a3ae
Merge branch 'master' of github.com:elastic/kibana into apm-error-tab…
cauemarcondes Feb 3, 2021
926de0b
refactoring
cauemarcondes Feb 3, 2021
8c671b4
Merge branch 'master' of github.com:elastic/kibana into apm-error-tab…
cauemarcondes Feb 4, 2021
47792e0
fixing license
cauemarcondes Feb 5, 2021
fd3a05a
Merge branch 'master' into apm-error-table-api
kibanamachine Feb 8, 2021
4b6f1c4
renaming apis
cauemarcondes Feb 8, 2021
63fcf6a
fixing some stuff
cauemarcondes Feb 8, 2021
b181310
Merge branch 'master' of github.com:elastic/kibana into apm-error-tab…
dgieselaar Feb 12, 2021
feca96d
Merge branch 'master' into apm-error-table-api
kibanamachine Feb 13, 2021
51dec3a
Merge branch 'master' of github.com:elastic/kibana into apm-error-tab…
cauemarcondes Feb 13, 2021
ac5f9a5
addressing PR comments
cauemarcondes Feb 15, 2021
d8f19a0
Merge branch 'master' of github.com:elastic/kibana into apm-error-tab…
cauemarcondes Feb 15, 2021
1ab4b0e
Merge branch 'master' of github.com:elastic/kibana into apm-error-tab…
cauemarcondes Feb 18, 2021
3b02302
adding request id
cauemarcondes Feb 18, 2021
9af5714
addressing PR comments
cauemarcondes Feb 19, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ describe('ServiceOverview', () => {

/* eslint-disable @typescript-eslint/naming-convention */
const calls = {
'GET /api/apm/services/{serviceName}/error_groups': {
'GET /api/apm/services/{serviceName}/error_groups/primary_statistics': {
error_groups: [],
total_error_groups: 0,
},
'GET /api/apm/services/{serviceName}/transactions/groups/primary_statistics': {
transactionGroups: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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 { EuiBasicTableColumn } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { asInteger } from '../../../../../common/utils/formatters';
import { px, unit } from '../../../../style/variables';
import { SparkPlot } from '../../../shared/charts/spark_plot';
import { ErrorDetailLink } from '../../../shared/Links/apm/ErrorDetailLink';
import { TimestampTooltip } from '../../../shared/TimestampTooltip';
import { TruncateWithTooltip } from '../../../shared/truncate_with_tooltip';
import { APIReturnType } from '../../../../services/rest/createCallApmApi';

type ErrorGroupPrimaryStatistics = APIReturnType<'GET /api/apm/services/{serviceName}/error_groups/primary_statistics'>;
type ErrorGroupComparisonStatistics = APIReturnType<'GET /api/apm/services/{serviceName}/error_groups/comparison_statistics'>;

export function getColumns({
serviceName,
errorGroupComparisonStatistics,
}: {
serviceName: string;
errorGroupComparisonStatistics: ErrorGroupComparisonStatistics;
}): Array<EuiBasicTableColumn<ErrorGroupPrimaryStatistics['error_groups'][0]>> {
return [
{
field: 'name',
name: i18n.translate('xpack.apm.serviceOverview.errorsTableColumnName', {
defaultMessage: 'Name',
}),
render: (_, { name, group_id: errorGroupId }) => {
return (
<TruncateWithTooltip
text={name}
content={
<ErrorDetailLink
serviceName={serviceName}
errorGroupId={errorGroupId}
>
{name}
</ErrorDetailLink>
}
/>
);
},
},
{
field: 'last_seen',
name: i18n.translate(
'xpack.apm.serviceOverview.errorsTableColumnLastSeen',
{
defaultMessage: 'Last seen',
}
),
render: (_, { last_seen: lastSeen }) => {
return <TimestampTooltip time={lastSeen} timeUnit="minutes" />;
},
width: px(unit * 9),
},
{
field: 'occurrences',
name: i18n.translate(
'xpack.apm.serviceOverview.errorsTableColumnOccurrences',
{
defaultMessage: 'Occurrences',
}
),
width: px(unit * 12),
render: (_, { occurrences, group_id: errorGroupId }) => {
const timeseries =
errorGroupComparisonStatistics?.[errorGroupId]?.timeseries;
return (
<SparkPlot
color="euiColorVis7"
series={timeseries}
valueLabel={i18n.translate(
'xpack.apm.serviceOveriew.errorsTableOccurrences',
{
defaultMessage: `{occurrencesCount} occ.`,
values: {
occurrencesCount: asInteger(occurrences),
},
}
)}
/>
);
},
},
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,26 @@

import {
EuiBasicTable,
EuiBasicTableColumn,
EuiFlexGroup,
EuiFlexItem,
EuiTitle,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { orderBy } from 'lodash';
import React, { useState } from 'react';
import { asInteger } from '../../../../../common/utils/formatters';
import uuid from 'uuid';
import { useApmServiceContext } from '../../../../context/apm_service/use_apm_service_context';
import { useUrlParams } from '../../../../context/url_params_context/use_url_params';
import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher';
import { px, unit } from '../../../../style/variables';
import { SparkPlot } from '../../../shared/charts/spark_plot';
import { ErrorDetailLink } from '../../../shared/Links/apm/ErrorDetailLink';
import { ErrorOverviewLink } from '../../../shared/Links/apm/ErrorOverviewLink';
import { TableFetchWrapper } from '../../../shared/table_fetch_wrapper';
import { TimestampTooltip } from '../../../shared/TimestampTooltip';
import { TruncateWithTooltip } from '../../../shared/truncate_with_tooltip';
import { ServiceOverviewTableContainer } from '../service_overview_table_container';
import { getColumns } from './get_column';

interface Props {
serviceName: string;
}

interface ErrorGroupItem {
name: string;
last_seen: number;
group_id: string;
occurrences: {
value: number;
timeseries: Array<{ x: number; y: number }> | null;
};
}

type SortDirection = 'asc' | 'desc';
type SortField = 'name' | 'last_seen' | 'occurrences';

Expand All @@ -50,6 +36,11 @@ const DEFAULT_SORT = {
field: 'occurrences' as const,
};

const INITIAL_STATE = {
items: [],
requestId: undefined,
};

export function ServiceOverviewErrorsTable({ serviceName }: Props) {
const {
urlParams: { environment, start, end },
Expand All @@ -67,135 +58,85 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
sort: DEFAULT_SORT,
});

const columns: Array<EuiBasicTableColumn<ErrorGroupItem>> = [
{
field: 'name',
name: i18n.translate('xpack.apm.serviceOverview.errorsTableColumnName', {
defaultMessage: 'Name',
}),
render: (_, { name, group_id: errorGroupId }) => {
return (
<TruncateWithTooltip
text={name}
content={
<ErrorDetailLink
serviceName={serviceName}
errorGroupId={errorGroupId}
>
{name}
</ErrorDetailLink>
}
/>
);
},
},
{
field: 'last_seen',
name: i18n.translate(
'xpack.apm.serviceOverview.errorsTableColumnLastSeen',
{
defaultMessage: 'Last seen',
}
),
render: (_, { last_seen: lastSeen }) => {
return <TimestampTooltip time={lastSeen} timeUnit="minutes" />;
},
width: px(unit * 9),
},
{
field: 'occurrences',
name: i18n.translate(
'xpack.apm.serviceOverview.errorsTableColumnOccurrences',
{
defaultMessage: 'Occurrences',
}
),
width: px(unit * 12),
render: (_, { occurrences }) => {
return (
<SparkPlot
color="euiColorVis7"
series={occurrences.timeseries ?? undefined}
valueLabel={i18n.translate(
'xpack.apm.serviceOveriew.errorsTableOccurrences',
{
defaultMessage: `{occurrencesCount} occ.`,
values: {
occurrencesCount: asInteger(occurrences.value),
},
}
)}
/>
);
},
},
];
const { pageIndex, sort } = tableOptions;

const {
data = {
totalItemCount: 0,
items: [],
tableOptions: {
pageIndex: 0,
sort: DEFAULT_SORT,
},
},
status,
} = useFetcher(
const { data = INITIAL_STATE, status } = useFetcher(
(callApmApi) => {
if (!start || !end || !transactionType) {
return;
}

return callApmApi({
endpoint: 'GET /api/apm/services/{serviceName}/error_groups',
endpoint:
'GET /api/apm/services/{serviceName}/error_groups/primary_statistics',
params: {
path: { serviceName },
query: {
environment,
start,
end,
uiFilters: JSON.stringify(uiFilters),
size: PAGE_SIZE,
numBuckets: 20,
pageIndex: tableOptions.pageIndex,
sortField: tableOptions.sort.field,
sortDirection: tableOptions.sort.direction,
transactionType,
},
},
}).then((response) => {
return {
requestId: uuid(),
items: response.error_groups,
totalItemCount: response.total_error_groups,
tableOptions: {
pageIndex: tableOptions.pageIndex,
sort: {
field: tableOptions.sort.field,
direction: tableOptions.sort.direction,
},
},
};
});
},
[
environment,
start,
end,
serviceName,
uiFilters,
tableOptions.pageIndex,
tableOptions.sort.field,
tableOptions.sort.direction,
transactionType,
]
[environment, start, end, serviceName, uiFilters, transactionType]
);

const {
const { requestId, items } = data;
const currentPageErrorGroups = orderBy(
items,
totalItemCount,
tableOptions: { pageIndex, sort },
} = data;
sort.field,
sort.direction
).slice(pageIndex * PAGE_SIZE, (pageIndex + 1) * PAGE_SIZE);

const groupIds = JSON.stringify(
currentPageErrorGroups.map(({ group_id: groupId }) => groupId).sort()
);
const {
data: errorGroupComparisonStatistics,
status: errorGroupComparisonStatisticsStatus,
} = useFetcher(
(callApmApi) => {
if (
requestId &&
currentPageErrorGroups.length &&
start &&
end &&
transactionType
) {
return callApmApi({
endpoint:
'GET /api/apm/services/{serviceName}/error_groups/comparison_statistics',
params: {
path: { serviceName },
query: {
start,
end,
uiFilters: JSON.stringify(uiFilters),
numBuckets: 20,
transactionType,
groupIds,
},
},
});
}
},
// only fetches agg results when requestId or group ids change
// eslint-disable-next-line react-hooks/exhaustive-deps
[requestId, groupIds],
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
{ preservePreviousData: false }
);

const columns = getColumns({
serviceName,
errorGroupComparisonStatistics: errorGroupComparisonStatistics ?? {},
});

return (
<EuiFlexGroup direction="column" gutterSize="s">
Expand Down Expand Up @@ -228,15 +169,18 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
>
<EuiBasicTable
columns={columns}
items={items}
items={currentPageErrorGroups}
pagination={{
pageIndex,
pageSize: PAGE_SIZE,
totalItemCount,
totalItemCount: items.length,
pageSizeOptions: [PAGE_SIZE],
hidePerPageOptions: true,
}}
loading={status === FETCH_STATUS.LOADING}
loading={
status === FETCH_STATUS.LOADING ||
errorGroupComparisonStatisticsStatus === FETCH_STATUS.LOADING
}
onChange={(newTableOptions: {
page?: {
index: number;
Expand All @@ -255,10 +199,7 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
}}
sorting={{
enableAllColumns: true,
sort: {
direction: sort.direction,
field: sort.field,
},
sort,
}}
/>
</ServiceOverviewTableContainer>
Expand Down
Loading