diff --git a/src/plugins/data/common/search/tabify/tabify.test.ts b/src/plugins/data/common/search/tabify/tabify.test.ts index 6cdf9a3547d48..3e1b856de4100 100644 --- a/src/plugins/data/common/search/tabify/tabify.test.ts +++ b/src/plugins/data/common/search/tabify/tabify.test.ts @@ -8,7 +8,7 @@ import { tabifyAggResponse } from './tabify'; import { IndexPattern } from '../..'; -import { AggConfigs, IAggConfig, IAggConfigs } from '../aggs'; +import { AggConfigs, BucketAggParam, IAggConfig, IAggConfigs } from '../aggs'; import { mockAggTypesRegistry } from '../aggs/test_helpers'; import { metricOnly, threeTermBuckets } from './fixtures/fake_hierarchical_data'; @@ -54,6 +54,42 @@ describe('tabifyAggResponse Integration', () => { expect(resp.columns[0]).toHaveProperty('name', aggConfigs.aggs[0].makeLabel()); }); + describe('scaleMetricValues performance check', () => { + beforeAll(() => { + typesRegistry.get('count').params.push({ + name: 'scaleMetricValues', + default: false, + write: () => {}, + advanced: true, + } as any as BucketAggParam); + }); + test('does not call write if scaleMetricValues is not set', () => { + const aggConfigs = createAggConfigs([{ type: 'count' } as any]); + + const writeMock = jest.fn(); + aggConfigs.getRequestAggs()[0].write = writeMock; + + tabifyAggResponse(aggConfigs, metricOnly, { + metricsAtAllLevels: true, + }); + expect(writeMock).not.toHaveBeenCalled(); + }); + + test('does call write if scaleMetricValues is set', () => { + const aggConfigs = createAggConfigs([ + { type: 'count', params: { scaleMetricValues: true } } as any, + ]); + + const writeMock = jest.fn(() => ({})); + aggConfigs.getRequestAggs()[0].write = writeMock; + + tabifyAggResponse(aggConfigs, metricOnly, { + metricsAtAllLevels: true, + }); + expect(writeMock).toHaveBeenCalled(); + }); + }); + describe('transforms a complex response', () => { let esResp: typeof threeTermBuckets; let aggConfigs: IAggConfigs; diff --git a/src/plugins/data/common/search/tabify/tabify.ts b/src/plugins/data/common/search/tabify/tabify.ts index a4d9551da75d5..9d1d6aadcb769 100644 --- a/src/plugins/data/common/search/tabify/tabify.ts +++ b/src/plugins/data/common/search/tabify/tabify.ts @@ -37,8 +37,10 @@ export function tabifyAggResponse( if (column) { const agg = column.aggConfig; - const aggInfo = agg.write(aggs); - aggScale *= aggInfo.metricScale || 1; + if (agg.getParam('scaleMetricValues')) { + const aggInfo = agg.write(aggs); + aggScale *= aggInfo.metricScale || 1; + } switch (agg.type.type) { case AggGroupNames.Buckets: