Skip to content

Commit

Permalink
Fixes error with percentiles on index with many docs (#113216)
Browse files Browse the repository at this point in the history
* Fixes error with metric viz and percentiles on index with many docs

* Unskip the metric viz suite

* Adds a unit test
  • Loading branch information
stratoula authored Sep 29, 2021
1 parent 25695b5 commit c63f4be
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
51 changes: 51 additions & 0 deletions src/plugins/data/common/search/aggs/metrics/percentiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IPercentileAggConfig, getPercentilesMetricAgg } from './percentiles';
import { AggConfigs, IAggConfigs } from '../agg_configs';
import { mockAggTypesRegistry } from '../test_helpers';
import { METRIC_TYPES } from './metric_agg_types';
import { IResponseAggConfig } from './lib/get_response_agg_config_class';

describe('AggTypesMetricsPercentilesProvider class', () => {
let aggConfigs: IAggConfigs;
Expand Down Expand Up @@ -92,4 +93,54 @@ describe('AggTypesMetricsPercentilesProvider class', () => {
}
`);
});

it('returns NaN if bucket has zero documents', () => {
const agg = {
id: '1.5',
key: 5,
parentId: '1',
} as IResponseAggConfig;
const percentileValue: any = getPercentilesMetricAgg().getValue(agg, {
doc_count: 0,
});

expect(percentileValue).toBe(NaN);
});

it('computes the value correctly', () => {
const agg = {
id: '1.5',
key: 5,
parentId: '1',
} as IResponseAggConfig;
const percentileValue: any = getPercentilesMetricAgg().getValue(agg, {
doc_count: 0,
1: {
values: [
{
key: 1,
value: 0,
},
{
key: 5,
value: 306.5442142237532,
},
{
key: 75,
value: 8014.248827201506,
},
{
key: 95,
value: 10118.560640759324,
},
{
key: 99,
value: 18028.720727798096,
},
],
},
});

expect(percentileValue).toBe(306.5442142237532);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getPercentileValue = <TAggConfig extends IResponseAggConfig>(
agg: TAggConfig,
bucket: any
) => {
const { values } = bucket[agg.parentId];
const { values } = bucket[agg.parentId] ?? {};

const percentile: any = find(values, ({ key }) => key === agg.key);

Expand Down
3 changes: 1 addition & 2 deletions test/functional/apps/visualize/_metric_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const inspector = getService('inspector');
const PageObjects = getPageObjects(['visualize', 'visEditor', 'visChart', 'timePicker']);

// FLAKY: https://github.com/elastic/kibana/issues/106121
describe.skip('metric chart', function () {
describe('metric chart', function () {
before(async function () {
await PageObjects.visualize.initTests();
log.debug('navigateToApp visualize');
Expand Down

0 comments on commit c63f4be

Please sign in to comment.