Skip to content

Commit

Permalink
🐛 Fix single percentile case when ES is returning no buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Oct 15, 2021
1 parent a0c5c11 commit 7c83fe0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ describe('AggTypeMetricSinglePercentileProvider class', () => {
).toEqual(123);
});

it('should not throw error for empty buckets', () => {
const agg = aggConfigs.getResponseAggs()[0];
expect(agg.getValue({})).toEqual(NaN);
});

it('produces the expected expression ast', () => {
const agg = aggConfigs.getResponseAggs()[0];
expect(agg.toExpressionAst()).toMatchInlineSnapshot(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export const getSinglePercentileMetricAgg = () => {
if (Number.isInteger(agg.params.percentile)) {
valueKey += '.0';
}
return bucket[agg.id].values[valueKey];
const { values } = bucket[agg.id] ?? {};

return values ? values[valueKey] : NaN;
},
});
};

0 comments on commit 7c83fe0

Please sign in to comment.