Skip to content

Commit 00db7ea

Browse files
bartvanremortelesorenlouv
authored andcommitted
[APM] Add support for very high durations (minutes and hours) (#41640) (#42068)
1 parent e7c945f commit 00db7ea

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

x-pack/legacy/plugins/apm/public/utils/__test__/formatters.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ describe('formatters', () => {
2222
expect(asTime(1000 * 1000)).toEqual('1,000 ms');
2323
expect(asTime(1000 * 1000 * 10)).toEqual('10,000 ms');
2424
expect(asTime(1000 * 1000 * 20)).toEqual('20.0 s');
25+
expect(asTime(60000000 * 10)).toEqual('10.0 min');
26+
expect(asTime(3600000000 * 1.5)).toEqual('1.5 h');
2527
});
2628

2729
it('formats without unit', () => {

x-pack/legacy/plugins/apm/public/utils/formatters.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { i18n } from '@kbn/i18n';
99
import { memoize } from 'lodash';
1010
import { NOT_AVAILABLE_LABEL } from '../../common/i18n';
1111

12+
const HOURS_CUT_OFF = 3600000000; // 1 hour (in microseconds)
13+
const MINUTES_CUT_OFF = 60000000; // 1 minute (in microseconds)
1214
const SECONDS_CUT_OFF = 10 * 1000000; // 10 seconds (in microseconds)
1315
const MILLISECONDS_CUT_OFF = 10 * 1000; // 10 milliseconds (in microseconds)
1416
const SPACE = ' ';
@@ -24,6 +26,38 @@ interface FormatterOptions {
2426
defaultValue?: string;
2527
}
2628

29+
export function asHours(
30+
value: FormatterValue,
31+
{ withUnit = true, defaultValue = NOT_AVAILABLE_LABEL }: FormatterOptions = {}
32+
) {
33+
if (value == null) {
34+
return defaultValue;
35+
}
36+
const hoursLabel =
37+
SPACE +
38+
i18n.translate('xpack.apm.formatters.hoursTimeUnitLabel', {
39+
defaultMessage: 'h'
40+
});
41+
const formatted = asDecimal(value / 3600000000);
42+
return `${formatted}${withUnit ? hoursLabel : ''}`;
43+
}
44+
45+
export function asMinutes(
46+
value: FormatterValue,
47+
{ withUnit = true, defaultValue = NOT_AVAILABLE_LABEL }: FormatterOptions = {}
48+
) {
49+
if (value == null) {
50+
return defaultValue;
51+
}
52+
const minutesLabel =
53+
SPACE +
54+
i18n.translate('xpack.apm.formatters.minutesTimeUnitLabel', {
55+
defaultMessage: 'min'
56+
});
57+
const formatted = asDecimal(value / 60000000);
58+
return `${formatted}${withUnit ? minutesLabel : ''}`;
59+
}
60+
2761
export function asSeconds(
2862
value: FormatterValue,
2963
{ withUnit = true, defaultValue = NOT_AVAILABLE_LABEL }: FormatterOptions = {}
@@ -81,6 +115,10 @@ type TimeFormatter = (
81115
export const getTimeFormatter: TimeFormatter = memoize((max: number) => {
82116
const unit = timeUnit(max);
83117
switch (unit) {
118+
case 'h':
119+
return asHours;
120+
case 'm':
121+
return asMinutes;
84122
case 's':
85123
return asSeconds;
86124
case 'ms':
@@ -91,7 +129,11 @@ export const getTimeFormatter: TimeFormatter = memoize((max: number) => {
91129
});
92130

93131
export function timeUnit(max: number) {
94-
if (max > SECONDS_CUT_OFF) {
132+
if (max > HOURS_CUT_OFF) {
133+
return 'h';
134+
} else if (max > MINUTES_CUT_OFF) {
135+
return 'm';
136+
} else if (max > SECONDS_CUT_OFF) {
95137
return 's';
96138
} else if (max > MILLISECONDS_CUT_OFF) {
97139
return 'ms';

x-pack/plugins/translations/translations/ja-JP.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,6 +3784,8 @@
37843784
"xpack.apm.formatters.millisTimeUnitLabel": "ミリ秒",
37853785
"xpack.apm.formatters.requestsPerMinLabel": "1分あたりリクエスト数",
37863786
"xpack.apm.formatters.secondsTimeUnitLabel": "秒",
3787+
"xpack.apm.formatters.minutesTimeUnitLabel": "分",
3788+
"xpack.apm.formatters.hoursTimeUnitLabel": "時",
37873789
"xpack.apm.formatters.transactionsPerMinLabel": "1分あたりトランザクション数",
37883790
"xpack.apm.header.badge.readOnly.text": "読み込み専用",
37893791
"xpack.apm.header.badge.readOnly.tooltip": "を保存できませんでした",

x-pack/plugins/translations/translations/zh-CN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,8 @@
37853785
"xpack.apm.formatters.millisTimeUnitLabel": "ms",
37863786
"xpack.apm.formatters.requestsPerMinLabel": "rpm",
37873787
"xpack.apm.formatters.secondsTimeUnitLabel": "s",
3788+
"xpack.apm.formatters.minutesTimeUnitLabel": "m",
3789+
"xpack.apm.formatters.hoursTimeUnitLabel": "h",
37883790
"xpack.apm.formatters.transactionsPerMinLabel": "tpm",
37893791
"xpack.apm.header.badge.readOnly.text": "只读",
37903792
"xpack.apm.header.badge.readOnly.tooltip": "无法保存",

0 commit comments

Comments
 (0)