Skip to content

Commit

Permalink
More idiomatic JavaScript, more types.
Browse files Browse the repository at this point in the history
  • Loading branch information
skh committed Apr 18, 2019
1 parent 0bc4adc commit c475797
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions x-pack/plugins/infra/server/lib/snapshot/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <BucketType>(
framework: InfraBackendFrameworkAdapter,
request: InfraFrameworkRequest,
query: any,
previousBuckets: BucketType[] = []
): Promise<BucketType[]> => {
const response = await framework.callWithRequest<any, any>(request, 'search', query);
const response = await framework.callWithRequest<{}, InfraSnapshotAggregationResponse>(
request,
'search',
query
);

// Nothing available, return the previous buckets.
if (response.hits.total.value === 0) {
Expand Down Expand Up @@ -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) =>
Expand Down

0 comments on commit c475797

Please sign in to comment.