Skip to content
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 @@ -58,7 +58,7 @@ describe('Observability dashboard data', () => {
transactions: {
type: 'number',
label: 'Transactions',
value: 6,
value: 2,
color: '#6092c0',
},
},
Expand Down Expand Up @@ -115,5 +115,45 @@ describe('Observability dashboard data', () => {
},
});
});
it('returns transaction stat as 0 when y is undefined', async () => {
callApmApiMock.mockImplementation(() =>
Promise.resolve({
serviceCount: 0,
transactionCoordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
})
);
const response = await fetchLandingPageData(
{
startTime: '1',
endTime: '2',
bucketSize: '3',
},
{ theme }
);
expect(response).toEqual({
title: 'APM',
appLink: '/app/apm',
stats: {
services: {
type: 'number',
label: 'Services',
value: 0,
},
transactions: {
type: 'number',
label: 'Transactions',
value: 0,
color: '#6092c0',
},
},
series: {
transactions: {
label: 'Transactions',
coordinates: [{ x: 1 }, { x: 2 }, { x: 3 }],
color: '#6092c0',
},
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { i18n } from '@kbn/i18n';
import { sum } from 'lodash';
import mean from 'lodash.mean';
import { Theme } from '@kbn/ui-shared-deps/theme';
import {
ApmFetchDataResponse,
Expand Down Expand Up @@ -48,7 +48,12 @@ export const fetchLandingPageData = async (
'xpack.apm.observabilityDashboard.stats.transactions',
{ defaultMessage: 'Transactions' }
),
value: sum(transactionCoordinates.map((coordinates) => coordinates.y)),
value:
mean(
transactionCoordinates
.map(({ y }) => y)
.filter((y) => y && isFinite(y))
Copy link
Copy Markdown
Contributor

@sorenlouv sorenlouv Jul 1, 2020

Choose a reason for hiding this comment

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

nit: I think you can do:

Suggested change
.filter((y) => y && isFinite(y))
.filter(isFinite)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

isFinite requires a number, and y can be number | undefined. That's why I didn't do what you've suggested.

) || 0,
color: theme.euiColorVis1,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ export async function getTransactionCoordinates({
field: '@timestamp',
fixed_interval: bucketSize,
min_doc_count: 0,
extended_bounds: { min: start, max: end },
},
},
},
},
});

const deltaAsMinutes = (end - start) / 1000 / 60;

return (
aggregations?.distribution.buckets.map((bucket) => ({
x: bucket.key,
y: bucket.doc_count,
y: bucket.doc_count / deltaAsMinutes,
})) || []
);
}