Skip to content

Commit

Permalink
[7.x] [APM] Show transaction rate per minute on Observability Overvie…
Browse files Browse the repository at this point in the history
…w page (#70336) (#70566)

* [APM] Show transaction rate per minute on Observability Overview page (#70336)

* changing transaction count to transaction rate per second

* sanity check coordinates before calculate the mean

* sanity check coordinates before calculate the mean

* removing extend_bounds to return empty when no data is available

* Fix lodash

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Søren Louv-Jansen <[email protected]>
  • Loading branch information
3 people authored Jul 7, 2020
1 parent ef0a749 commit f56a6c3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
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';
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))
) || 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,
})) || []
);
}

0 comments on commit f56a6c3

Please sign in to comment.