diff --git a/x-pack/plugins/apm/server/lib/transaction_groups/transform.test.ts b/x-pack/plugins/apm/server/lib/transaction_groups/transform.test.ts index 35420d223d22d..0bb29e27f0219 100644 --- a/x-pack/plugins/apm/server/lib/transaction_groups/transform.test.ts +++ b/x-pack/plugins/apm/server/lib/transaction_groups/transform.test.ts @@ -13,7 +13,7 @@ describe('transactionGroupsTransformer', () => { const { bucketSize, isAggregationAccurate, - transactionGroups, + items, } = transactionGroupsTransformer({ response: transactionGroupsResponse, start: 100, @@ -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', () => { @@ -59,7 +59,7 @@ describe('transactionGroupsTransformer', () => { ).toEqual({ bucketSize: 100, isAggregationAccurate: true, - transactionGroups: [ + items: [ { averageResponseTime: 255966.30555555556, impact: 0, @@ -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]); }); }); diff --git a/x-pack/plugins/apm/server/lib/transaction_groups/transform.ts b/x-pack/plugins/apm/server/lib/transaction_groups/transform.ts index 2128d3f37ab29..81dba39e9d712 100644 --- a/x-pack/plugins/apm/server/lib/transaction_groups/transform.ts +++ b/x-pack/plugins/apm/server/lib/transaction_groups/transform.ts @@ -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 @@ -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