Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Jun 25, 2020
1 parent fd21494 commit 2bc7fc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('transactionGroupsTransformer', () => {
const {
bucketSize,
isAggregationAccurate,
transactionGroups,
items,
} = transactionGroupsTransformer({
response: transactionGroupsResponse,
start: 100,
Expand All @@ -23,7 +23,7 @@ describe('transactionGroupsTransformer', () => {

expect(bucketSize).toBe(100);
expect(isAggregationAccurate).toBe(true);
expect(transactionGroups).toMatchSnapshot();
expect(items).toMatchSnapshot();
});

it('should transform response correctly', () => {
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('transactionGroupsTransformer', () => {
).toEqual({
bucketSize: 100,
isAggregationAccurate: true,
transactionGroups: [
items: [
{
averageResponseTime: 255966.30555555556,
impact: 0,
Expand Down Expand Up @@ -123,17 +123,13 @@ describe('transactionGroupsTransformer', () => {
},
} as unknown) as ESResponse;

const { transactionGroups } = transactionGroupsTransformer({
const { items } = transactionGroupsTransformer({
response,
start: 100,
end: 20000,
bucketSize: 100,
});

expect(transactionGroups.map((bucket) => bucket.impact)).toEqual([
100,
25,
0,
]);
expect(items.map((bucket) => bucket.impact)).toEqual([100, 25, 0]);
});
});
16 changes: 6 additions & 10 deletions x-pack/plugins/apm/server/lib/transaction_groups/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import moment from 'moment';
import { sortByOrder } from 'lodash';
import { ESResponse } from './fetcher';

function calculateRelativeImpacts(transactionGroups: ITransactionGroup[]) {
const values = transactionGroups
function calculateRelativeImpacts(items: ITransactionGroup[]) {
const values = items
.map(({ impact }) => impact)
.filter((value) => value !== null) as number[];

const max = Math.max(...values);
const min = Math.min(...values);

return transactionGroups.map((bucket) => ({
return items.map((bucket) => ({
...bucket,
impact:
bucket.impact !== null
Expand Down Expand Up @@ -74,16 +74,12 @@ export function transactionGroupsTransformer({
const buckets = getBuckets(response);
const duration = moment.duration(end - start);
const minutes = duration.asMinutes();
const transactionGroups = buckets.map((bucket) =>
getTransactionGroup(bucket, minutes)
);
const items = buckets.map((bucket) => getTransactionGroup(bucket, minutes));

const transactionGroupsWithRelativeImpact = calculateRelativeImpacts(
transactionGroups
);
const itemsWithRelativeImpact = calculateRelativeImpacts(items);

return {
items: transactionGroupsWithRelativeImpact,
items: itemsWithRelativeImpact,

// The aggregation is considered accurate if the configured bucket size is larger or equal to the number of buckets returned
// the actual number of buckets retrieved are `bucketsize + 1` to detect whether it's above the limit
Expand Down

0 comments on commit 2bc7fc0

Please sign in to comment.