-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Usage Collection] Report nodes feature usage #70108
Merged
TinaHeiligers
merged 12 commits into
elastic:master
from
TinaHeiligers:nodes-feature-usage-local-collection
Jun 30, 2020
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
de25409
Adds nodes feature usage stats merged into cluster_stats.nodes
TinaHeiligers c75b23e
Adds jest unit test for get_nodes_usage, adds to mocha tests for get_…
TinaHeiligers 048bfe5
adds assertion for nodes usage in cluster stats api integration test
TinaHeiligers 3e62592
resolves linter problem
TinaHeiligers 345310c
Handles unit test failures
TinaHeiligers 4b7e9a1
Update src/plugins/telemetry/server/telemetry_collection/get_local_st…
TinaHeiligers 73bb233
review comments addressed
TinaHeiligers 853710b
removes unused merge import
TinaHeiligers 9a0962d
Updates test snapshots
TinaHeiligers a6bd9bd
removes unused var
TinaHeiligers 5acbcdb
Merge branch 'master' of github.com:elastic/kibana into nodes-feature…
TinaHeiligers e43b412
Updates type
TinaHeiligers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
80 changes: 80 additions & 0 deletions
80
src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.test.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,80 @@ | ||
/* | ||
* 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 { getNodesUsage } from './get_nodes_usage'; | ||
import { TIMEOUT } from './constants'; | ||
|
||
const mockedNodesFetchResponse = { | ||
cluster_name: 'test cluster', | ||
nodes: { | ||
some_node_id: { | ||
timestamp: 1588617023177, | ||
since: 1588616945163, | ||
rest_actions: { | ||
nodes_usage_action: 1, | ||
create_index_action: 1, | ||
document_get_action: 1, | ||
search_action: 19, | ||
nodes_info_action: 36, | ||
}, | ||
aggregations: { | ||
terms: { | ||
bytes: 2, | ||
}, | ||
scripted_metric: { | ||
other: 7, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
describe('get_nodes_usage', () => { | ||
it('calls fetchNodesUsage', async () => { | ||
const callCluster = jest.fn(); | ||
callCluster.mockResolvedValueOnce(mockedNodesFetchResponse); | ||
await getNodesUsage(callCluster); | ||
expect(callCluster).toHaveBeenCalledWith('transport.request', { | ||
path: '/_nodes/usage', | ||
method: 'GET', | ||
query: { | ||
timeout: TIMEOUT, | ||
}, | ||
}); | ||
}); | ||
it('returns a modified array of node usage data', async () => { | ||
const callCluster = jest.fn(); | ||
callCluster.mockResolvedValueOnce(mockedNodesFetchResponse); | ||
const result = await getNodesUsage(callCluster); | ||
expect(result.nodes).toEqual([ | ||
{ | ||
aggregations: { scripted_metric: { other: 7 }, terms: { bytes: 2 } }, | ||
node_id: 'some_node_id', | ||
rest_actions: { | ||
create_index_action: 1, | ||
document_get_action: 1, | ||
nodes_info_action: 36, | ||
nodes_usage_action: 1, | ||
search_action: 19, | ||
}, | ||
since: 1588616945163, | ||
timestamp: 1588617023177, | ||
}, | ||
]); | ||
}); | ||
}); |
81 changes: 81 additions & 0 deletions
81
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,81 @@ | ||
/* | ||
* 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 { LegacyAPICaller } 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 NodesFeatureUsageResponse { | ||
cluster_name: string; | ||
nodes: { | ||
[key: string]: NodeObj; | ||
}; | ||
} | ||
|
||
export type NodesUsageGetter = ( | ||
callCluster: LegacyAPICaller | ||
) => Promise<{ nodes: NodeObj[] | Array<{}> }>; | ||
/** | ||
* 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( | ||
callCluster: LegacyAPICaller | ||
): Promise<NodesFeatureUsageResponse> { | ||
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(callCluster); | ||
const transformedNodes = Object.entries(result?.nodes || {}).map(([key, value]) => ({ | ||
...(value as NodeObj), | ||
node_id: key, | ||
})); | ||
return { nodes: transformedNodes }; | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: I think there is no need for the cast now that
fetchNodesUsage
is properly typed :)