Skip to content

Commit

Permalink
review comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed Jun 29, 2020
1 parent 4b7e9a1 commit 73bb233
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ describe('get_nodes_usage', () => {
it('calls fetchNodesUsage', async () => {
const callCluster = jest.fn();
callCluster.mockResolvedValueOnce(mockedNodesFetchResponse);
jest.fn(async () => ({
cluster_name: 'test',
nodes: mockedNodesResponse,
}));
await getNodesUsage(callCluster);
expect(callCluster).toHaveBeenCalledWith('transport.request', {
path: '/_nodes/usage',
Expand All @@ -84,10 +80,6 @@ describe('get_nodes_usage', () => {
it('returns a modified array of node usage data', async () => {
const callCluster = jest.fn();
callCluster.mockResolvedValueOnce(mockedNodesFetchResponse);
jest.fn(async () => ({
cluster_name: 'test',
nodes: mockedNodesResponse,
}));
const result = await getNodesUsage(callCluster);
expect(result.nodes).toEqual([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,14 @@ export interface NodeObj {
[key: string]: NodeAggregation;
};
}
export interface NodesStats {
total: number;
successful: number;
failed: number;
}

export interface NodesFeatureUsageResponse {
cluster_name: string;
nodes: {
[key: string]: NodeObj;
};
}

export type NodesUsageFetcher = (callCluster: APICaller) => Promise<NodesFeatureUsageResponse>;

export type NodesUsageGetter = (
callCluster: APICaller
) => Promise<{ nodes: NodeObj[] | Array<{}> }>;
Expand All @@ -59,7 +53,7 @@ export type NodesUsageGetter = (
*
* The Nodes usage API was introduced in v6.0.0
*/
export async function fetchNodesUsage<NodesUsageFetcher>(callCluster: APICaller) {
export async function fetchNodesUsage(callCluster: APICaller): Promise<NodesFeatureUsageResponse> {
const response = await callCluster('transport.request', {
method: 'GET',
path: '/_nodes/usage',
Expand All @@ -76,13 +70,10 @@ export async function fetchNodesUsage<NodesUsageFetcher>(callCluster: APICaller)
* @returns Object containing array of modified usage information with the node_id nested within the data for that node.
*/
export const getNodesUsage: NodesUsageGetter = async (callCluster) => {
const result = await fetchNodesUsage<NodesUsageFetcher>(callCluster);
let transformedNodes = [{}];
if (result && result.nodes) {
transformedNodes = Object.entries(result.nodes).map(([key, value]) => ({
...(value as NodeObj),
node_id: key,
}));
}
const result = await fetchNodesUsage(callCluster);
const transformedNodes = Object.entries(result?.nodes || {}).map(([key, value]) => ({
...(value as NodeObj),
node_id: key,
}));
return { nodes: transformedNodes };
};

0 comments on commit 73bb233

Please sign in to comment.