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] Changes to duration formatting #69039

Merged
merged 3 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -40,7 +40,7 @@ describe('ServiceOverview -> List', () => {
expect(renderedColumns[0]).toMatchSnapshot();
expect(renderedColumns.slice(2)).toEqual([
'python',
'92 ms',
'91.5 ms',
'86.9 tpm',
'12.6 err.',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import styled from 'styled-components';
import { ServiceListAPIResponse } from '../../../../../server/lib/services/get_services';
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n';
import { fontSizes, truncate } from '../../../../style/variables';
import { asDecimal, convertTo } from '../../../../utils/formatters';
import { asDecimal, asMillisecondDuration } from '../../../../utils/formatters';
import { ManagedTable } from '../../../shared/ManagedTable';
import { EnvironmentBadge } from '../../../shared/EnvironmentBadge';
import { TransactionOverviewLink } from '../../../shared/Links/apm/TransactionOverviewLink';
Expand Down Expand Up @@ -81,11 +81,7 @@ export const SERVICE_COLUMNS = [
}),
sortable: true,
dataType: 'number',
render: (time: number) =>
convertTo({
unit: 'milliseconds',
microseconds: time,
}).formatted,
render: (time: number) => asMillisecondDuration(time),
},
{
field: 'transactionsPerMinute',
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import styled from 'styled-components';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ITransactionGroup } from '../../../../server/lib/transaction_groups/transform';
import { fontSizes, truncate } from '../../../style/variables';
import { convertTo } from '../../../utils/formatters';
import { asMillisecondDuration } from '../../../utils/formatters';
import { EmptyMessage } from '../../shared/EmptyMessage';
import { ImpactBar } from '../../shared/ImpactBar';
import { TransactionDetailLink } from '../../shared/Links/apm/TransactionDetailLink';
Expand Down Expand Up @@ -67,11 +67,7 @@ const traceListColumns: Array<ITableColumn<ITransactionGroup>> = [
}),
sortable: true,
dataType: 'number',
render: (time: number) =>
convertTo({
unit: 'milliseconds',
microseconds: time,
}).formatted,
render: (time: number) => asMillisecondDuration(time),
},
{
field: 'transactionsPerMinute',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 { fontFamilyCode, truncate } from '../../../../style/variables';
import { asDecimal, convertTo } from '../../../../utils/formatters';
import { asDecimal, asMillisecondDuration } from '../../../../utils/formatters';
import { ImpactBar } from '../../../shared/ImpactBar';
import { ITableColumn, ManagedTable } from '../../../shared/ManagedTable';
import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt';
Expand All @@ -29,12 +29,6 @@ interface Props {
isLoading: boolean;
}

const toMilliseconds = (time: number) =>
convertTo({
unit: 'milliseconds',
microseconds: time,
}).formatted;

export function TransactionList({ items, isLoading }: Props) {
const columns: Array<ITableColumn<ITransactionGroup>> = useMemo(
() => [
Expand Down Expand Up @@ -74,7 +68,7 @@ export function TransactionList({ items, isLoading }: Props) {
),
sortable: true,
dataType: 'number',
render: (time: number) => toMilliseconds(time),
render: (time: number) => asMillisecondDuration(time),
},
{
field: 'p95',
Expand All @@ -86,7 +80,7 @@ export function TransactionList({ items, isLoading }: Props) {
),
sortable: true,
dataType: 'number',
render: (time: number) => toMilliseconds(time),
render: (time: number) => asMillisecondDuration(time),
},
{
field: 'transactionsPerMinute',
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Histogram', () => {
const tooltips = wrapper.find('Tooltip');

expect(tooltips.length).toBe(1);
expect(tooltips.prop('header')).toBe('811 - 927 ms');
expect(tooltips.prop('header')).toBe('811.1 - 926.9 ms');
expect(tooltips.prop('tooltipPoints')).toEqual([
{ value: '49.0 occurrences' },
]);
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ErrorMarker', () => {
act(() => {
fireEvent.click(component.getByTestId('popover'));
});
expectTextsInDocument(component, ['10,000 μs']);
expectTextsInDocument(component, ['10.0 ms']);
return component;
}
function getKueryDecoded(url: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class TransactionCharts extends Component<TransactionChartProps> {
'xpack.apm.metrics.transactionChart.machineLearningTooltip',
{
defaultMessage:
'The stream around the average duration shows the expected bounds. An annotation is shown for anomaly scores >= 75.',
'The stream around the average duration shows the expected bounds. An annotation is shown for anomaly scores 75.',
}
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('chartSelectors', () => {
{ x: 0, y: 100 },
{ x: 1000, y: 200 },
],
legendValue: '0 ms',
legendValue: '200 μs',
title: 'Avg.',
type: 'linemark',
},
Expand Down
7 changes: 2 additions & 5 deletions x-pack/plugins/apm/public/selectors/chartSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
RectCoordinate,
TimeSeries,
} from '../../typings/timeseries';
import { asDecimal, tpmUnit, convertTo } from '../utils/formatters';
import { asDecimal, asDuration, tpmUnit } from '../utils/formatters';
import { IUrlParams } from '../context/UrlParamsContext/types';
import { getEmptySeries } from '../components/shared/charts/CustomPlot/getEmptySeries';
import { httpStatusCodeToColor } from '../utils/httpStatusCodeToColor';
Expand Down Expand Up @@ -72,10 +72,7 @@ export function getResponseTimeSeries({
}: TimeSeriesAPIResponse) {
const { overallAvgDuration } = apmTimeseries;
const { avg, p95, p99 } = apmTimeseries.responseTimes;
const formattedDuration = convertTo({
unit: 'milliseconds',
microseconds: overallAvgDuration,
}).formatted;
const formattedDuration = asDuration(overallAvgDuration);

const series: TimeSeries[] = [
{
Expand Down
102 changes: 9 additions & 93 deletions x-pack/plugins/apm/public/utils/formatters/__test__/duration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { asDuration, convertTo, toMicroseconds } from '../duration';
import { asDuration, toMicroseconds, asMillisecondDuration } from '../duration';

describe('duration formatters', () => {
describe('asDuration', () => {
Expand All @@ -14,10 +14,10 @@ describe('duration formatters', () => {
expect(asDuration(1)).toEqual('1 μs');
expect(asDuration(toMicroseconds(1, 'milliseconds'))).toEqual('1,000 μs');
expect(asDuration(toMicroseconds(1000, 'milliseconds'))).toEqual(
'1,000 ms'
'1,000.0 ms'
);
expect(asDuration(toMicroseconds(10000, 'milliseconds'))).toEqual(
'10,000 ms'
'10,000.0 ms'
);
expect(asDuration(toMicroseconds(20, 'seconds'))).toEqual('20.0 s');
expect(asDuration(toMicroseconds(10, 'minutes'))).toEqual('10.0 min');
Expand All @@ -30,96 +30,6 @@ describe('duration formatters', () => {
});
});

describe('convertTo', () => {
it('hours', () => {
const unit = 'hours';
const oneHourAsMicro = toMicroseconds(1, 'hours');
const twoHourAsMicro = toMicroseconds(2, 'hours');
expect(convertTo({ unit, microseconds: oneHourAsMicro })).toEqual({
unit: 'h',
value: '1.0',
formatted: '1.0 h',
});
expect(convertTo({ unit, microseconds: twoHourAsMicro })).toEqual({
unit: 'h',
value: '2.0',
formatted: '2.0 h',
});
expect(
convertTo({ unit, microseconds: null, defaultValue: '1.2' })
).toEqual({ value: '1.2', formatted: '1.2' });
});

it('minutes', () => {
const unit = 'minutes';
const oneHourAsMicro = toMicroseconds(1, 'hours');
const twoHourAsMicro = toMicroseconds(2, 'hours');
expect(convertTo({ unit, microseconds: oneHourAsMicro })).toEqual({
unit: 'min',
value: '60.0',
formatted: '60.0 min',
});
expect(convertTo({ unit, microseconds: twoHourAsMicro })).toEqual({
unit: 'min',
value: '120.0',
formatted: '120.0 min',
});
expect(
convertTo({ unit, microseconds: null, defaultValue: '10' })
).toEqual({ value: '10', formatted: '10' });
});

it('seconds', () => {
const unit = 'seconds';
const twentySecondsAsMicro = toMicroseconds(20, 'seconds');
const thirtyFiveSecondsAsMicro = toMicroseconds(35, 'seconds');
expect(convertTo({ unit, microseconds: twentySecondsAsMicro })).toEqual({
unit: 's',
value: '20.0',
formatted: '20.0 s',
});
expect(
convertTo({ unit, microseconds: thirtyFiveSecondsAsMicro })
).toEqual({ unit: 's', value: '35.0', formatted: '35.0 s' });
expect(
convertTo({ unit, microseconds: null, defaultValue: '10' })
).toEqual({ value: '10', formatted: '10' });
});

it('milliseconds', () => {
const unit = 'milliseconds';
const twentyMilliAsMicro = toMicroseconds(20, 'milliseconds');
const thirtyFiveMilliAsMicro = toMicroseconds(35, 'milliseconds');
expect(convertTo({ unit, microseconds: twentyMilliAsMicro })).toEqual({
unit: 'ms',
value: '20',
formatted: '20 ms',
});
expect(
convertTo({ unit, microseconds: thirtyFiveMilliAsMicro })
).toEqual({ unit: 'ms', value: '35', formatted: '35 ms' });
expect(
convertTo({ unit, microseconds: null, defaultValue: '10' })
).toEqual({ value: '10', formatted: '10' });
});

it('microseconds', () => {
const unit = 'microseconds';
expect(convertTo({ unit, microseconds: 20 })).toEqual({
unit: 'μs',
value: '20',
formatted: '20 μs',
});
expect(convertTo({ unit, microseconds: 35 })).toEqual({
unit: 'μs',
value: '35',
formatted: '35 μs',
});
expect(
convertTo({ unit, microseconds: null, defaultValue: '10' })
).toEqual({ value: '10', formatted: '10' });
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Are these no longer needed?

Copy link
Member

Choose a reason for hiding this comment

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

... oh, it's because convertTo is no longer public but only used internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. And we still have 100% coverage.

describe('toMicroseconds', () => {
it('transformes to microseconds', () => {
expect(toMicroseconds(1, 'hours')).toEqual(3600000000);
Expand All @@ -128,4 +38,10 @@ describe('duration formatters', () => {
expect(toMicroseconds(10, 'milliseconds')).toEqual(10000);
});
});

describe('asMilliseconds', () => {
it('converts to formatted decimal milliseconds', () => {
expect(asMillisecondDuration(0)).toEqual('0.0 ms');
});
});
});
Loading