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] Use transaction metrics for distribution charts #78484

Merged
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
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
Copy link
Member

@sorenlouv sorenlouv Sep 29, 2020

Choose a reason for hiding this comment

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

From the name it sounds like the sorting depends on something. But they are always sorted by count, no?

Suggested change
const bucketsSortedByPreference = response.buckets
const bucketsSortedByCount = response.buckets

or perhaps

Suggested change
const bucketsSortedByPreference = response.buckets
const bucketsSorted = response.buckets

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes - will change it to bucketsSortedByCount.

.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