From 515b5dc66c224fb566ae8b0ba7e11b4c69a7e408 Mon Sep 17 00:00:00 2001 From: Zacqary Adam Xeper Date: Wed, 1 Jul 2020 18:07:54 -0500 Subject: [PATCH] [Metrics UI] Fix asynchronicity and error handling in Snapshot API (#70503) Co-authored-by: Elastic Machine --- .../infra/server/lib/snapshot/snapshot.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts b/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts index 2868c63745eb1..9ca10d5e39da7 100644 --- a/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts +++ b/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts @@ -41,12 +41,13 @@ export class InfraSnapshot { // when they have both been completed. const timeRangeWithIntervalApplied = await createTimeRangeWithInterval(client, options); const optionsWithTimerange = { ...options, timerange: timeRangeWithIntervalApplied }; + const groupedNodesPromise = requestGroupedNodes(client, optionsWithTimerange); const nodeMetricsPromise = requestNodeMetrics(client, optionsWithTimerange); - - const groupedNodeBuckets = await groupedNodesPromise; - const nodeMetricBuckets = await nodeMetricsPromise; - + const [groupedNodeBuckets, nodeMetricBuckets] = await Promise.all([ + groupedNodesPromise, + nodeMetricsPromise, + ]); return { nodes: mergeNodeBuckets(groupedNodeBuckets, nodeMetricBuckets, options), interval: timeRangeWithIntervalApplied.interval, @@ -103,11 +104,12 @@ const requestGroupedNodes = async ( }, }, }; - - return await getAllCompositeData< - InfraSnapshotAggregationResponse, - InfraSnapshotNodeGroupByBucket - >(callClusterFactory(client), query, bucketSelector, handleAfterKey); + return getAllCompositeData( + callClusterFactory(client), + query, + bucketSelector, + handleAfterKey + ); }; const calculateIndexPatterBasedOnMetrics = (options: InfraSnapshotRequestOptions) => { @@ -161,10 +163,12 @@ const requestNodeMetrics = async ( }, }, }; - return await getAllCompositeData< - InfraSnapshotAggregationResponse, - InfraSnapshotNodeMetricsBucket - >(callClusterFactory(client), query, bucketSelector, handleAfterKey); + return getAllCompositeData( + callClusterFactory(client), + query, + bucketSelector, + handleAfterKey + ); }; // buckets can be InfraSnapshotNodeGroupByBucket[] or InfraSnapshotNodeMetricsBucket[]