Skip to content

Commit 87ad564

Browse files
[APM] Use transaction metrics for distribution charts (#78484)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 2fbf9b9 commit 87ad564

14 files changed

Lines changed: 354 additions & 188 deletions

File tree

x-pack/plugins/apm/public/components/app/TransactionDetails/Distribution/__test__/distribution.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66

77
import { getFormattedBuckets } from '../index';
8-
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
9-
import { IBucket } from '../../../../../../server/lib/transactions/distribution/get_buckets/transform';
108

119
describe('Distribution', () => {
1210
it('getFormattedBuckets', () => {
@@ -20,6 +18,7 @@ describe('Distribution', () => {
2018
samples: [
2119
{
2220
transactionId: 'someTransactionId',
21+
traceId: 'someTraceId',
2322
},
2423
],
2524
},
@@ -29,10 +28,12 @@ describe('Distribution', () => {
2928
samples: [
3029
{
3130
transactionId: 'anotherTransactionId',
31+
traceId: 'anotherTraceId',
3232
},
3333
],
3434
},
35-
] as IBucket[];
35+
];
36+
3637
expect(getFormattedBuckets(buckets, 20)).toEqual([
3738
{ x: 20, x0: 0, y: 0, style: { cursor: 'default' } },
3839
{ x: 40, x0: 20, y: 0, style: { cursor: 'default' } },

x-pack/plugins/apm/public/components/app/TransactionDetails/Distribution/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ValuesType } from 'utility-types';
1313
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1414
import { TransactionDistributionAPIResponse } from '../../../../../server/lib/transactions/distribution';
1515
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
16-
import { IBucket } from '../../../../../server/lib/transactions/distribution/get_buckets/transform';
16+
import { DistributionBucket } from '../../../../../server/lib/transactions/distribution/get_buckets';
1717
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
1818
import { getDurationFormatter } from '../../../../utils/formatters';
1919
// @ts-expect-error
@@ -30,7 +30,10 @@ interface IChartPoint {
3030
};
3131
}
3232

33-
export function getFormattedBuckets(buckets: IBucket[], bucketSize: number) {
33+
export function getFormattedBuckets(
34+
buckets: DistributionBucket[],
35+
bucketSize: number
36+
) {
3437
if (!buckets) {
3538
return [];
3639
}

x-pack/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Location } from 'history';
1818
import React, { useEffect, useState } from 'react';
1919
import { useHistory } from 'react-router-dom';
2020
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
21-
import { IBucket } from '../../../../../server/lib/transactions/distribution/get_buckets/transform';
21+
import { DistributionBucket } from '../../../../../server/lib/transactions/distribution/get_buckets';
2222
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
2323
import { fromQuery, toQuery } from '../../../shared/Links/url_helpers';
2424
import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt';
@@ -34,7 +34,7 @@ interface Props {
3434
waterfall: IWaterfall;
3535
exceedsMax: boolean;
3636
isLoading: boolean;
37-
traceSamples: IBucket['samples'];
37+
traceSamples: DistributionBucket['samples'];
3838
}
3939

4040
export function WaterfallWithSummmary({

x-pack/plugins/apm/public/hooks/useTransactionDistribution.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { flatten, omit } from 'lodash';
7+
import { flatten, omit, isEmpty } from 'lodash';
88
import { useHistory, useParams } from 'react-router-dom';
99
import { IUrlParams } from '../context/UrlParamsContext/types';
1010
import { useFetcher } from './useFetcher';
@@ -69,10 +69,12 @@ export function useTransactionDistribution(urlParams: IUrlParams) {
6969
// selected sample was not found. select a new one:
7070
// sorted by total number of requests, but only pick
7171
// from buckets that have samples
72+
const bucketsSortedByPreference = response.buckets
73+
.filter((bucket) => !isEmpty(bucket.samples))
74+
.sort((bucket) => bucket.count);
75+
7276
const preferredSample = maybe(
73-
response.buckets
74-
.filter((bucket) => bucket.samples.length > 0)
75-
.sort((bucket) => bucket.count)[0]?.samples[0]
77+
bucketsSortedByPreference[0]?.samples[0]
7678
);
7779

7880
history.push({

x-pack/plugins/apm/server/lib/transactions/__snapshots__/queries.test.ts.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/fetcher.ts

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)