-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds nodes feature usage stats merged into cluster_stats.nodes
- Loading branch information
1 parent
4845bef
commit de25409
Showing
2 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { APICaller } from 'kibana/server'; | ||
import { TIMEOUT } from './constants'; | ||
|
||
export interface NodeAggregation { | ||
[key: string]: number; | ||
} | ||
|
||
// we set aggregations as an optional type because it was only added in v7.8.0 | ||
export interface NodeObj { | ||
node_id?: string; | ||
timestamp: number; | ||
since: number; | ||
rest_actions: { | ||
[key: string]: number; | ||
}; | ||
aggregations?: { | ||
[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[] }>; | ||
/** | ||
* Get the nodes usage data from the connected cluster. | ||
* | ||
* This is the equivalent to GET /_nodes/usage?timeout=30s. | ||
* | ||
* The Nodes usage API was introduced in v6.0.0 | ||
*/ | ||
export async function fetchNodesUsage<NodesUsageFetcher>(callCluster: APICaller) { | ||
const response = await callCluster('transport.request', { | ||
method: 'GET', | ||
path: '/_nodes/usage', | ||
query: { | ||
timeout: TIMEOUT, | ||
}, | ||
}); | ||
return response; | ||
} | ||
|
||
/** | ||
* Get the nodes usage from the connected cluster | ||
* @param 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); | ||
const transformedNodes = Object.entries(result.nodes).map(([key, value]) => ({ | ||
...(value as NodeObj), | ||
node_id: key, | ||
})); | ||
return { nodes: transformedNodes }; | ||
}; |