Skip to content

Commit ffedc7f

Browse files
committed
sanity check coordinates before calculate the mean
1 parent d7cb371 commit ffedc7f

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,45 @@ describe('Observability dashboard data', () => {
117117
},
118118
});
119119
});
120+
it('returns transaction stat as 0 when y is undefined', async () => {
121+
callApmApiMock.mockImplementation(() =>
122+
Promise.resolve({
123+
serviceCount: 0,
124+
transactionCoordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
125+
})
126+
);
127+
const response = await fetchLandingPageData(
128+
{
129+
startTime: '1',
130+
endTime: '2',
131+
bucketSize: '3',
132+
},
133+
{ theme }
134+
);
135+
expect(response).toEqual({
136+
title: 'APM',
137+
appLink: '/app/apm',
138+
stats: {
139+
services: {
140+
type: 'number',
141+
label: 'Services',
142+
value: 0,
143+
},
144+
transactions: {
145+
type: 'number',
146+
label: 'Transactions',
147+
value: 0,
148+
color: '#6092c0',
149+
},
150+
},
151+
series: {
152+
transactions: {
153+
label: 'Transactions',
154+
coordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
155+
color: '#6092c0',
156+
},
157+
},
158+
});
159+
});
120160
});
121161
});

x-pack/plugins/apm/public/services/rest/observability_dashboard.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ export const fetchLandingPageData = async (
4747
'xpack.apm.observabilityDashboard.stats.transactions',
4848
{ defaultMessage: 'Transactions' }
4949
),
50-
value:
51-
mean(transactionCoordinates.map((coordinates) => coordinates.y)) || 0,
50+
value: !!transactionCoordinates.length
51+
? mean(
52+
transactionCoordinates.map((coordinates) => coordinates.y || 0)
53+
)
54+
: 0,
5255
color: theme.euiColorVis1,
5356
},
5457
},

0 commit comments

Comments
 (0)