From 8fc81f48b95255ea9a1c99aece5b670c5c57a13d Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Mon, 28 Feb 2022 11:49:00 -0700 Subject: [PATCH] [Infrastructure UI] Remove reduces from Log Threshold Rule (#126402) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../log_threshold/log_threshold_executor.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts index 674ba977e09c0..2ca97c6b8a35f 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts @@ -333,22 +333,22 @@ const getReducedGroupByResults = ( key: GroupedSearchQueryResponse['aggregations']['groups']['buckets'][0]['key'] ) => Object.values(key).join(', '); + const reducedGroupByResults: ReducedGroupByResults = []; if (isOptimizedGroupedSearchQueryResponse(results)) { - return results.reduce((acc, groupBucket) => { + for (const groupBucket of results) { const groupName = getGroupName(groupBucket.key); - const groupResult = { name: groupName, documentCount: groupBucket.doc_count }; - return [...acc, groupResult]; - }, []); + reducedGroupByResults.push({ name: groupName, documentCount: groupBucket.doc_count }); + } } else { - return results.reduce((acc, groupBucket) => { + for (const groupBucket of results) { const groupName = getGroupName(groupBucket.key); - const groupResult = { + reducedGroupByResults.push({ name: groupName, documentCount: groupBucket.filtered_results.doc_count, - }; - return [...acc, groupResult]; - }, []); + }); + } } + return reducedGroupByResults; }; export const processGroupByResults = (