Skip to content

Commit

Permalink
Use transaction metrics for distribution charts
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Sep 24, 2020
1 parent 744238f commit 0b15c03
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/

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

describe('Distribution', () => {
it('getFormattedBuckets', () => {
Expand All @@ -20,6 +18,7 @@ describe('Distribution', () => {
samples: [
{
transactionId: 'someTransactionId',
traceId: 'someTraceId',
},
],
},
Expand All @@ -29,10 +28,12 @@ describe('Distribution', () => {
samples: [
{
transactionId: 'anotherTransactionId',
traceId: 'anotherTraceId',
},
],
},
] as IBucket[];
];

expect(getFormattedBuckets(buckets, 20)).toEqual([
{ x: 20, x0: 0, y: 0, style: { cursor: 'default' } },
{ x: 40, x0: 20, y: 0, style: { cursor: 'default' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ValuesType } from 'utility-types';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { TransactionDistributionAPIResponse } from '../../../../../server/lib/transactions/distribution';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { IBucket } from '../../../../../server/lib/transactions/distribution/get_buckets/transform';
import { DistributionBucket } from '../../../../../server/lib/transactions/distribution/get_buckets';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { getDurationFormatter } from '../../../../utils/formatters';
// @ts-expect-error
Expand All @@ -30,7 +30,10 @@ interface IChartPoint {
};
}

export function getFormattedBuckets(buckets: IBucket[], bucketSize: number) {
export function getFormattedBuckets(
buckets: DistributionBucket[],
bucketSize: number
) {
if (!buckets) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Location } from 'history';
import React, { useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { IBucket } from '../../../../../server/lib/transactions/distribution/get_buckets/transform';
import { DistributionBucket } from '../../../../../server/lib/transactions/distribution/get_buckets';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { fromQuery, toQuery } from '../../../shared/Links/url_helpers';
import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt';
Expand All @@ -34,7 +34,7 @@ interface Props {
waterfall: IWaterfall;
exceedsMax: boolean;
isLoading: boolean;
traceSamples: IBucket['samples'];
traceSamples: DistributionBucket['samples'];
}

export function WaterfallWithSummmary({
Expand Down
10 changes: 6 additions & 4 deletions x-pack/plugins/apm/public/hooks/useTransactionDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { flatten, omit } from 'lodash';
import { flatten, omit, isEmpty } from 'lodash';
import { useHistory, useParams } from 'react-router-dom';
import { IUrlParams } from '../context/UrlParamsContext/types';
import { useFetcher } from './useFetcher';
Expand Down Expand Up @@ -69,10 +69,12 @@ export function useTransactionDistribution(urlParams: IUrlParams) {
// selected sample was not found. select a new one:
// sorted by total number of requests, but only pick
// from buckets that have samples
const bucketsSortedByPreference = response.buckets
.filter((bucket) => !isEmpty(bucket.samples))
.sort((bucket) => bucket.count);

const preferredSample = maybe(
response.buckets
.filter((bucket) => bucket.samples.length > 0)
.sort((bucket) => bucket.count)[0]?.samples[0]
bucketsSortedByPreference[0]?.samples[0]
);

history.push({
Expand Down

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

This file was deleted.

Loading

0 comments on commit 0b15c03

Please sign in to comment.