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
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,8 @@ export const fetchLandingPageData = async (
'xpack.apm.observabilityDashboard.stats.transactions',
{ defaultMessage: 'Transactions' }
),
value: sum(transactionCoordinates.map((coordinates) => coordinates.y)),
value:
mean(transactionCoordinates.map((coordinates) => coordinates.y)) || 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Beware that mean can return NaN if any of the coordinates.y values here are non-numeric.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the heads up @smith , I added a condition to check if the array is not empty and to return 0 in case corrdinate.y is undefined. ffedc7f#diff-cf9933de7395c67ff230849c1c748111R50-R54

Copy link
Contributor

Choose a reason for hiding this comment

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

That will return 0 if any y value is non-numeric, which is fine if that's the behavior you want. When I ran into this I did values.map(value => value.y).filter(y => isFinite(y)).

(I can't remember if the data I was looking at had null or NaN or undefined, but let's say null for now) The first method makes it 0 if any null are found and the second gives you the mean of the the non-null values. I suppose you could also do values.map(value => value.y ?? 0), which would convert all the null values to zeroes and give you the mean of that.

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,
})) || []
);
}