Skip to content

Commit

Permalink
remove tabify performance issue (#124931) (#125047)
Browse files Browse the repository at this point in the history
(cherry picked from commit ecff412)

Co-authored-by: Joe Reuter <[email protected]>
  • Loading branch information
kibanamachine and flash1293 authored Feb 9, 2022
1 parent 6dcc5f9 commit 45be560
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
38 changes: 37 additions & 1 deletion src/plugins/data/common/search/tabify/tabify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<any>);
});
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;
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/data/common/search/tabify/tabify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 45be560

Please sign in to comment.