diff --git a/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts b/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts index f4cba6bd9c193..018b20ae2e650 100644 --- a/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts +++ b/x-pack/plugins/infra/server/lib/snapshot/snapshot.ts @@ -162,13 +162,26 @@ const requestNodeMetrics = async ( ); }; +// buckets can be InfraSnapshotNodeGroupByBucket[] or InfraSnapshotNodeMetricsBucket[] +// but typing this in a way that makes TypeScript happy is unreadable (if possible at all) +interface InfraSnapshotAggregationResponse { + nodes: { + buckets: any[]; + after_key: { [id: string]: string }; + }; +} + const getAllCompositeAggregationData = async ( framework: InfraBackendFrameworkAdapter, request: InfraFrameworkRequest, query: any, previousBuckets: BucketType[] = [] ): Promise => { - const response = await framework.callWithRequest(request, 'search', query); + const response = await framework.callWithRequest<{}, InfraSnapshotAggregationResponse>( + request, + 'search', + query + ); // Nothing available, return the previous buckets. if (response.hits.total.value === 0) { @@ -203,18 +216,14 @@ const mergeNodeBuckets = ( nodeMetricsBuckets: InfraSnapshotNodeMetricsBucket[], options: InfraSnapshotRequestOptions ): InfraSnapshotNode[] => { - const result: any[] = []; const nodeMetricsForLookup = getNodeMetricsForLookup(nodeMetricsBuckets); - nodeGroupByBuckets.forEach(node => { - const returnNode = { + return nodeGroupByBuckets.map(node => { + return { path: getNodePath(node, options), metric: getNodeMetrics(nodeMetricsForLookup[node.key.node], options), }; - result.push(returnNode); }); - - return result; }; const createQueryFilterClauses = (filterQuery: JsonObject | undefined) =>