Skip to content

Commit d12208c

Browse files
authored
[APM] Fix confusing request/minute viz (#69143)
1 parent c98845c commit d12208c

File tree

7 files changed

+327
-288
lines changed

7 files changed

+327
-288
lines changed

x-pack/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import { Coordinate, TimeSeries } from '../../../../../typings/timeseries';
2424
import { ITransactionChartData } from '../../../../selectors/chartSelectors';
2525
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
2626
import {
27-
asInteger,
2827
tpmUnit,
2928
TimeFormatter,
3029
getDurationFormatter,
30+
asDecimal,
3131
} from '../../../../utils/formatters';
3232
import { MLJobLink } from '../../Links/MachineLearningLinks/MLJobLink';
3333
import { LicenseContext } from '../../../../context/LicenseContext';
@@ -86,7 +86,7 @@ export class TransactionCharts extends Component<TransactionChartProps> {
8686
public getTPMFormatter = (t: number) => {
8787
const { urlParams } = this.props;
8888
const unit = tpmUnit(urlParams.transactionType);
89-
return `${asInteger(t)} ${unit}`;
89+
return `${asDecimal(t)} ${unit}`;
9090
};
9191

9292
public getTPMTooltipFormatter = (p: Coordinate) => {

x-pack/plugins/apm/public/selectors/__tests__/chartSelectors.test.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
warningColor,
1616
errorColor,
1717
} from '../../utils/httpStatusCodeToColor';
18+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
19+
import { ApmTimeSeriesResponse } from '../../../server/lib/transactions/charts/get_timeseries_data/transform';
1820

1921
describe('chartSelectors', () => {
2022
describe('getAnomalyScoreSeries', () => {
@@ -98,7 +100,7 @@ describe('chartSelectors', () => {
98100
});
99101

100102
describe('getTpmSeries', () => {
101-
const apmTimeseries = {
103+
const apmTimeseries: ApmTimeSeriesResponse = {
102104
responseTimes: {
103105
avg: [],
104106
p95: [],
@@ -107,13 +109,14 @@ describe('chartSelectors', () => {
107109
tpmBuckets: [
108110
{
109111
key: 'HTTP 2xx',
112+
avg: 3.5,
110113
dataPoints: [
111114
{ x: 0, y: 5 },
112-
{ x: 0, y: 2 },
115+
{ x: 1, y: 2 },
113116
],
114117
},
115-
{ key: 'HTTP 4xx', dataPoints: [{ x: 0, y: 1 }] },
116-
{ key: 'HTTP 5xx', dataPoints: [{ x: 0, y: 0 }] },
118+
{ key: 'HTTP 4xx', avg: 1, dataPoints: [{ x: 0, y: 1 }] },
119+
{ key: 'HTTP 5xx', avg: 0, dataPoints: [{ x: 0, y: 0 }] },
117120
],
118121
overallAvgDuration: 200,
119122
};
@@ -125,7 +128,7 @@ describe('chartSelectors', () => {
125128
color: successColor,
126129
data: [
127130
{ x: 0, y: 5 },
128-
{ x: 0, y: 2 },
131+
{ x: 1, y: 2 },
129132
],
130133
legendValue: '3.5 tpm',
131134
title: 'HTTP 2xx',
@@ -154,7 +157,7 @@ describe('chartSelectors', () => {
154157
expect(
155158
getTpmSeries({
156159
...apmTimeseries,
157-
tpmBuckets: [{ key, dataPoints: [{ x: 0, y: 0 }] }],
160+
tpmBuckets: [{ key, avg: 0, dataPoints: [{ x: 0, y: 0 }] }],
158161
})[0].color
159162
).toEqual(theme.euiColorSecondary);
160163
});
@@ -166,7 +169,7 @@ describe('chartSelectors', () => {
166169
expect(
167170
getTpmSeries({
168171
...apmTimeseries,
169-
tpmBuckets: [{ key, dataPoints: [{ x: 0, y: 0 }] }],
172+
tpmBuckets: [{ key, avg: 0, dataPoints: [{ x: 0, y: 0 }] }],
170173
})[0].color
171174
).toEqual(theme.euiColorSecondary);
172175
});
@@ -178,7 +181,7 @@ describe('chartSelectors', () => {
178181
expect(
179182
getTpmSeries({
180183
...apmTimeseries,
181-
tpmBuckets: [{ key, dataPoints: [{ x: 0, y: 0 }] }],
184+
tpmBuckets: [{ key, avg: 0, dataPoints: [{ x: 0, y: 0 }] }],
182185
})[0].color
183186
).toEqual(theme.euiColorSecondary);
184187
});
@@ -190,7 +193,7 @@ describe('chartSelectors', () => {
190193
expect(
191194
getTpmSeries({
192195
...apmTimeseries,
193-
tpmBuckets: [{ key, dataPoints: [{ x: 0, y: 0 }] }],
196+
tpmBuckets: [{ key, avg: 0, dataPoints: [{ x: 0, y: 0 }] }],
194197
})[0].color
195198
).toEqual(theme.euiColorSecondary);
196199
});
@@ -202,7 +205,7 @@ describe('chartSelectors', () => {
202205
expect(
203206
getTpmSeries({
204207
...apmTimeseries,
205-
tpmBuckets: [{ key, dataPoints: [{ x: 0, y: 0 }] }],
208+
tpmBuckets: [{ key, avg: 0, dataPoints: [{ x: 0, y: 0 }] }],
206209
})[0].color
207210
).toEqual(theme.euiColorDanger);
208211
});
@@ -214,7 +217,7 @@ describe('chartSelectors', () => {
214217
expect(
215218
getTpmSeries({
216219
...apmTimeseries,
217-
tpmBuckets: [{ key, dataPoints: [{ x: 0, y: 0 }] }],
220+
tpmBuckets: [{ key, avg: 0, dataPoints: [{ x: 0, y: 0 }] }],
218221
})[0].color
219222
).toEqual(theme.euiColorDanger);
220223
});
@@ -226,7 +229,7 @@ describe('chartSelectors', () => {
226229
expect(
227230
getTpmSeries({
228231
...apmTimeseries,
229-
tpmBuckets: [{ key, dataPoints: [{ x: 0, y: 0 }] }],
232+
tpmBuckets: [{ key, avg: 0, dataPoints: [{ x: 0, y: 0 }] }],
230233
})[0].color
231234
).toEqual(theme.euiColorDanger);
232235
});
@@ -238,7 +241,7 @@ describe('chartSelectors', () => {
238241
expect(
239242
getTpmSeries({
240243
...apmTimeseries,
241-
tpmBuckets: [{ key, dataPoints: [{ x: 0, y: 0 }] }],
244+
tpmBuckets: [{ key, avg: 0, dataPoints: [{ x: 0, y: 0 }] }],
242245
})[0].color
243246
).toEqual(theme.euiColorDanger);
244247
});

x-pack/plugins/apm/public/selectors/chartSelectors.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import theme from '@elastic/eui/dist/eui_theme_light.json';
88
import { i18n } from '@kbn/i18n';
99
import { difference, zipObject } from 'lodash';
10-
import mean from 'lodash.mean';
1110
import { rgba } from 'polished';
1211
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1312
import { TimeSeriesAPIResponse } from '../../server/lib/transactions/charts';
@@ -72,15 +71,14 @@ export function getResponseTimeSeries({
7271
}: TimeSeriesAPIResponse) {
7372
const { overallAvgDuration } = apmTimeseries;
7473
const { avg, p95, p99 } = apmTimeseries.responseTimes;
75-
const formattedDuration = asDuration(overallAvgDuration);
7674

7775
const series: TimeSeries[] = [
7876
{
7977
title: i18n.translate('xpack.apm.transactions.chart.averageLabel', {
8078
defaultMessage: 'Avg.',
8179
}),
8280
data: avg,
83-
legendValue: formattedDuration,
81+
legendValue: asDuration(overallAvgDuration),
8482
type: 'linemark',
8583
color: theme.euiColorVis1,
8684
},
@@ -171,11 +169,10 @@ export function getTpmSeries(
171169
}
172170

173171
return tpmBuckets.map((bucket) => {
174-
const average = mean(bucket.dataPoints.map((p) => p.y));
175172
return {
176173
title: bucket.key,
177174
data: bucket.dataPoints,
178-
legendValue: `${asDecimal(average)} ${tpmUnit(transactionType || '')}`,
175+
legendValue: `${asDecimal(bucket.avg)} ${tpmUnit(transactionType || '')}`,
179176
type: 'linemark',
180177
color: getColor(bucket.key),
181178
};

0 commit comments

Comments
 (0)