mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Lens][Aggs] Gracefully handle the case of missing extended_stats for std_deviation operation (#141248)
* 🐛 Make getValue return undefined if no extended_object is present * ✅ Add unit test
This commit is contained in:
parent
585d51444e
commit
fa661a445b
2 changed files with 15 additions and 3 deletions
|
@ -13,7 +13,10 @@ import { METRIC_TYPES } from './metric_agg_types';
|
|||
|
||||
describe('AggTypeMetricStandardDeviationProvider class', () => {
|
||||
const typesRegistry = mockAggTypesRegistry();
|
||||
const getAggConfigs = (customLabel?: string) => {
|
||||
const getAggConfigs = ({
|
||||
customLabel,
|
||||
showBounds,
|
||||
}: { customLabel?: string; showBounds?: boolean } = {}) => {
|
||||
const field = {
|
||||
name: 'memory',
|
||||
};
|
||||
|
@ -38,6 +41,7 @@ describe('AggTypeMetricStandardDeviationProvider class', () => {
|
|||
displayName: 'memory',
|
||||
},
|
||||
customLabel,
|
||||
...(showBounds != null ? { showBounds } : {}),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -47,7 +51,7 @@ describe('AggTypeMetricStandardDeviationProvider class', () => {
|
|||
};
|
||||
|
||||
it('uses the custom label if it is set', () => {
|
||||
const aggConfigs = getAggConfigs('custom label');
|
||||
const aggConfigs = getAggConfigs({ customLabel: 'custom label' });
|
||||
const responseAggs: any = getStdDeviationMetricAgg().getResponseAggs(
|
||||
aggConfigs.aggs[0] as IStdDevAggConfig
|
||||
);
|
||||
|
@ -102,4 +106,12 @@ describe('AggTypeMetricStandardDeviationProvider class', () => {
|
|||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('returns null without throwing if no "extended_stats" is returned', () => {
|
||||
const aggConfigs = getAggConfigs({ showBounds: false });
|
||||
|
||||
expect(() =>
|
||||
getStdDeviationMetricAgg().getValue(aggConfigs.aggs[0] as IStdDevAggConfig, {})
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -117,7 +117,7 @@ export const getStdDeviationMetricAgg = () => {
|
|||
getValue(agg, bucket) {
|
||||
const showBounds = agg.getParam('showBounds');
|
||||
if (showBounds === false) {
|
||||
return bucket[agg.id].std_deviation;
|
||||
return bucket[agg.id]?.std_deviation;
|
||||
}
|
||||
return get(bucket[agg.parentId], agg.valProp());
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue