Skip to content

Commit

Permalink
[7.x] [Metrics UI] Fix asynchronicity and error handling in Snapshot …
Browse files Browse the repository at this point in the history
…API (#70503) (#70534)

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Zacqary and elasticmachine authored Jul 2, 2020
1 parent b1c1516 commit c55b84b
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions x-pack/plugins/infra/server/lib/snapshot/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -103,11 +104,12 @@ const requestGroupedNodes = async (
},
},
};

return await getAllCompositeData<
InfraSnapshotAggregationResponse,
InfraSnapshotNodeGroupByBucket
>(callClusterFactory(client), query, bucketSelector, handleAfterKey);
return getAllCompositeData<InfraSnapshotAggregationResponse, InfraSnapshotNodeGroupByBucket>(
callClusterFactory(client),
query,
bucketSelector,
handleAfterKey
);
};

const calculateIndexPatterBasedOnMetrics = (options: InfraSnapshotRequestOptions) => {
Expand Down Expand Up @@ -161,10 +163,12 @@ const requestNodeMetrics = async (
},
},
};
return await getAllCompositeData<
InfraSnapshotAggregationResponse,
InfraSnapshotNodeMetricsBucket
>(callClusterFactory(client), query, bucketSelector, handleAfterKey);
return getAllCompositeData<InfraSnapshotAggregationResponse, InfraSnapshotNodeMetricsBucket>(
callClusterFactory(client),
query,
bucketSelector,
handleAfterKey
);
};

// buckets can be InfraSnapshotNodeGroupByBucket[] or InfraSnapshotNodeMetricsBucket[]
Expand Down

0 comments on commit c55b84b

Please sign in to comment.