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] Optimize traces overview #70200

Merged
merged 21 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2b1f4c3
[APM] Optimize traces overview
dgieselaar Jun 29, 2020
e7ac578
Separate queries into separate file
dgieselaar Jun 29, 2020
bfac5c2
Support union types for aggregations
dgieselaar Jun 29, 2020
43bec06
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jun 29, 2020
fcf18b2
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jun 30, 2020
fd73424
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jun 30, 2020
f80ff38
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jul 1, 2020
0395763
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jul 3, 2020
dff5fdc
Separate function for calculating relative impact
dgieselaar Jul 3, 2020
5126db9
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jul 5, 2020
804df26
Merge branch 'master' into optimize-traces-overview
elasticmachine Jul 6, 2020
6bf8dbb
Merge branch 'master' into optimize-traces-overview
elasticmachine Jul 6, 2020
0bee339
Merge branch 'master' into optimize-traces-overview
elasticmachine Jul 8, 2020
381304f
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jul 9, 2020
a13cfc6
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jul 27, 2020
9fb2d12
Update traces functional test
dgieselaar Jul 27, 2020
ccf9654
Update API tests
dgieselaar Jul 27, 2020
b040a40
Update responses for functional tests
dgieselaar Jul 27, 2020
861cf63
Merge branch 'optimize-traces-overview' of github.com:dgieselaar/kiba…
dgieselaar Jul 27, 2020
72eb667
Merge branch 'master' of github.com:elastic/kibana into optimize-trac…
dgieselaar Jul 28, 2020
a86551b
Review feedback
dgieselaar Jul 28, 2020
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
14 changes: 14 additions & 0 deletions x-pack/plugins/apm/common/utils/array_union_to_callable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 { ValuesType } from 'utility-types';

// work around a TypeScript limitation described in https://stackoverflow.com/posts/49511416

export const arrayUnionToCallable = <T extends any[] | undefined>(
array: T
): Array<ValuesType<Exclude<T, undefined>>> => {
return array ?? [];
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n';
import React from 'react';
import styled from 'styled-components';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ITransactionGroup } from '../../../../server/lib/transaction_groups/transform';
import { TransactionGroup } from '../../../../server/lib/transaction_groups/fetcher';
import { fontSizes, truncate } from '../../../style/variables';
import { asMillisecondDuration } from '../../../utils/formatters';
import { EmptyMessage } from '../../shared/EmptyMessage';
Expand All @@ -24,28 +24,31 @@ const StyledTransactionLink = styled(TransactionDetailLink)`
`;

interface Props {
items: ITransactionGroup[];
items: TransactionGroup[];
isLoading: boolean;
}

const traceListColumns: Array<ITableColumn<ITransactionGroup>> = [
const traceListColumns: Array<ITableColumn<TransactionGroup>> = [
{
field: 'name',
name: i18n.translate('xpack.apm.tracesTable.nameColumnLabel', {
defaultMessage: 'Name',
}),
width: '40%',
sortable: true,
render: (name: string, { sample }: ITransactionGroup) => (
<EuiToolTip id="trace-transaction-link-tooltip" content={name}>
render: (_: string, { sample }: TransactionGroup) => (
<EuiToolTip
id="trace-transaction-link-tooltip"
Copy link
Contributor

@ogupte ogupte Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this line was just name changes, but still: I don't think the id trace-transaction-link-tooltip is necessary anymore. I don't see it referenced anywhere, and i don't think it's used in any unit/functional testing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

content={sample.transaction.name}
>
<StyledTransactionLink
serviceName={sample.service.name}
transactionId={sample.transaction.id}
traceId={sample.trace.id}
transactionName={sample.transaction.name}
transactionType={sample.transaction.type}
>
{name}
{sample.transaction.name}
</StyledTransactionLink>
</EuiToolTip>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useMemo } from 'react';
import styled from 'styled-components';
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ITransactionGroup } from '../../../../../server/lib/transaction_groups/transform';
import { TransactionGroup } from '../../../../../server/lib/transaction_groups/fetcher';
import { fontFamilyCode, truncate } from '../../../../style/variables';
import { asDecimal, asMillisecondDuration } from '../../../../utils/formatters';
import { ImpactBar } from '../../../shared/ImpactBar';
Expand All @@ -25,12 +25,12 @@ const TransactionNameLink = styled(TransactionDetailLink)`
`;

interface Props {
items: ITransactionGroup[];
items: TransactionGroup[];
isLoading: boolean;
}

export function TransactionList({ items, isLoading }: Props) {
const columns: Array<ITableColumn<ITransactionGroup>> = useMemo(
const columns: Array<ITableColumn<TransactionGroup>> = useMemo(
() => [
{
field: 'name',
Expand All @@ -39,11 +39,11 @@ export function TransactionList({ items, isLoading }: Props) {
}),
width: '50%',
sortable: true,
render: (transactionName: string, { sample }: ITransactionGroup) => {
render: (_, { sample }: TransactionGroup) => {
return (
<EuiToolTip
id="transaction-name-link-tooltip"
content={transactionName || NOT_AVAILABLE_LABEL}
content={sample.transaction.name || NOT_AVAILABLE_LABEL}
>
<TransactionNameLink
serviceName={sample.service.name}
Expand All @@ -52,7 +52,7 @@ export function TransactionList({ items, isLoading }: Props) {
transactionName={sample.transaction.name}
transactionType={sample.transaction.type}
>
{transactionName || NOT_AVAILABLE_LABEL}
{sample.transaction.name || NOT_AVAILABLE_LABEL}
</TransactionNameLink>
</EuiToolTip>
);
Expand Down
40 changes: 1 addition & 39 deletions x-pack/plugins/apm/public/hooks/useTransactionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { useMemo } from 'react';
import { IUrlParams } from '../context/UrlParamsContext/types';
import { useUiFilters } from '../context/UrlParamsContext';
import { useFetcher } from './useFetcher';
import { APIReturnType } from '../services/rest/createCallApmApi';

const getRelativeImpact = (
impact: number,
impactMin: number,
impactMax: number
) =>
Math.max(
((impact - impactMin) / Math.max(impactMax - impactMin, 1)) * 100,
1
);

type TransactionsAPIResponse = APIReturnType<
'/api/apm/services/{serviceName}/transaction_groups'
>;

function getWithRelativeImpact(items: TransactionsAPIResponse['items']) {
const impacts = items
.map(({ impact }) => impact)
.filter((impact) => impact !== null) as number[];

const impactMin = Math.min(...impacts);
const impactMax = Math.max(...impacts);

return items.map((item) => {
return {
...item,
impactRelative:
item.impact !== null
? getRelativeImpact(item.impact, impactMin, impactMax)
: null,
};
});
}

const DEFAULT_RESPONSE: TransactionsAPIResponse = {
items: [],
isAggregationAccurate: true,
Expand Down Expand Up @@ -72,16 +42,8 @@ export function useTransactionList(urlParams: IUrlParams) {
[serviceName, start, end, transactionType, uiFilters]
);

const memoizedData = useMemo(
() => ({
items: getWithRelativeImpact(data.items),
isAggregationAccurate: data.isAggregationAccurate,
bucketSize: data.bucketSize,
}),
[data]
);
return {
data: memoizedData,
data,
status,
error,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning up 👍

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function registerTransactionDurationAlertType({

const { agg } = response.aggregations;

const value = 'values' in agg ? agg.values[0] : agg?.value;
const value = 'values' in agg ? Object.values(agg.values)[0] : agg?.value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this an unrelated change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is a bug fix now that I think of it. This code (written by me of course) assumes that the response of a percentiles aggregation is number[], but it's actually Record<string, number> where the key is the percentile. I'll verify whether that is the case and file a separate bug for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (value && value > alertParams.threshold * 1000) {
const alertInstance = services.alertInstanceFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Unionize } from 'utility-types';
import { Unionize, Overwrite } from 'utility-types';
import { ESSearchRequest } from '../../../typings/elasticsearch';
import {
Setup,
SetupTimeRange,
Expand All @@ -17,14 +18,28 @@ import { getMetricsProjection } from '../../../common/projections/metrics';
import { mergeProjection } from '../../../common/projections/util/merge_projection';
import { AggregationOptionsByType } from '../../../typings/elasticsearch/aggregations';

interface Aggs {
[key: string]: Unionize<{
min: AggregationOptionsByType['min'];
max: AggregationOptionsByType['max'];
sum: AggregationOptionsByType['sum'];
avg: AggregationOptionsByType['avg'];
}>;
}
type MetricsAggregationMap = Unionize<{
min: AggregationOptionsByType['min'];
max: AggregationOptionsByType['max'];
sum: AggregationOptionsByType['sum'];
avg: AggregationOptionsByType['avg'];
}>;

type Aggs = Record<string, MetricsAggregationMap>;

export type GenericMetricsRequest = Overwrite<
ESSearchRequest,
{
body: {
aggs: {
timeseriesData: {
date_histogram: AggregationOptionsByType['date_histogram'];
aggs: Record<string, MetricsAggregationMap>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this just be:

Suggested change
aggs: Record<string, MetricsAggregationMap>;
aggs: Aggs;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep! Changed it to MetricAggs in all places.

};
} & Record<string, MetricsAggregationMap>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this just be:

Suggested change
} & Record<string, MetricsAggregationMap>;
} & Aggs;

};
}
>;

interface Filter {
exists?: {
Expand Down Expand Up @@ -58,7 +73,7 @@ export async function fetchAndTransformMetrics<T extends Aggs>({
serviceNodeName,
});

const params = mergeProjection(projection, {
const params: GenericMetricsRequest = mergeProjection(projection, {
body: {
size: 0,
query: {
Expand Down
37 changes: 4 additions & 33 deletions x-pack/plugins/apm/server/lib/metrics/transform_metrics_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/
import theme from '@elastic/eui/dist/eui_theme_light.json';
import { Unionize, Overwrite } from 'utility-types';
import { ChartBase } from './types';
import {
ESSearchResponse,
ESSearchRequest,
} from '../../../typings/elasticsearch';
import { AggregationOptionsByType } from '../../../typings/elasticsearch/aggregations';
import { ESSearchResponse } from '../../../typings/elasticsearch';
import { getVizColorForIndex } from '../../../common/viz_colors';
import { GenericMetricsRequest } from './fetch_and_transform_metrics';

export type GenericMetricsChart = ReturnType<
typeof transformDataToMetricsChart
>;

interface MetricsAggregationMap {
min: AggregationOptionsByType['min'];
max: AggregationOptionsByType['max'];
sum: AggregationOptionsByType['sum'];
avg: AggregationOptionsByType['avg'];
}

type GenericMetricsRequest = Overwrite<
ESSearchRequest,
{
body: {
aggs: {
timeseriesData: {
date_histogram: AggregationOptionsByType['date_histogram'];
aggs: Record<string, Unionize<MetricsAggregationMap>>;
};
} & Record<string, Unionize<MetricsAggregationMap>>;
};
}
>;

export function transformDataToMetricsChart(
result: ESSearchResponse<unknown, GenericMetricsRequest>,
chartBase: ChartBase
Expand All @@ -51,11 +26,7 @@ export function transformDataToMetricsChart(
yUnit: chartBase.yUnit,
noHits: hits.total.value === 0,
series: Object.keys(chartBase.series).map((seriesKey, i) => {
const overallValue = (aggregations?.[seriesKey] as
| {
value: number | null;
}
| undefined)?.value;
const overallValue = aggregations?.[seriesKey]?.value;

return {
title: chartBase.series[seriesKey].title,
Expand All @@ -66,7 +37,7 @@ export function transformDataToMetricsChart(
overallValue,
data:
timeseriesData?.buckets.map((bucket) => {
const { value } = bucket[seriesKey] as { value: number | null };
const { value } = bucket[seriesKey];
const y = value === null || isNaN(value) ? null : value;
return {
x: bucket.key,
Expand Down
Loading