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] Show transaction rate per minute on Observability Overview page #70336

Merged
merged 6 commits into from
Jul 2, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Observability dashboard data', () => {
transactions: {
type: 'number',
label: 'Transactions',
value: 6,
value: 2,
color: '#6092c0',
},
},
Expand Down Expand Up @@ -117,5 +117,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';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FetchDataParams } from '../../../../observability/public/data_handler';
import { ApmFetchDataResponse } from '../../../../observability/public/typings/fetch_data_response';
Expand Down Expand Up @@ -47,7 +47,11 @@ export const fetchLandingPageData = async (
'xpack.apm.observabilityDashboard.stats.transactions',
{ defaultMessage: 'Transactions' }
),
value: sum(transactionCoordinates.map((coordinates) => coordinates.y)),
value: !!transactionCoordinates.length
? mean(
transactionCoordinates.map((coordinates) => coordinates.y || 0)
)
: 0,
color: theme.euiColorVis1,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ export async function getTransactionCoordinates({
},
});

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

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