-
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
[Telemetry] Pull local Kibana usage stats #26496
Merged
tsullivan
merged 17 commits into
elastic:master
from
tsullivan:telemetry/pull-live-kibana-stats
Dec 10, 2018
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6ec60d7
add kibana stats
tsullivan 8df2e01
fix tests
tsullivan 1a7d435
format the stats for telemetry
tsullivan 30e12f3
fix the os/platform stats
tsullivan b7ed480
add version to locally-source kibana telemetry stats
tsullivan ea35c43
use callWithInternalUser
tsullivan 23dec6a
better get_kibana module unit test verification
tsullivan 97aa994
separate handleKibanaStats
tsullivan 3ed42b8
variable rename
tsullivan b36bbab
fix comment
tsullivan d655589
fix functional test
tsullivan e05e068
Merge branch 'master' into telemetry/pull-live-kibana-stats
tsullivan b90815d
keep the return object literal from handleLocalStats
tsullivan 1972606
Merge branch 'master' into telemetry/pull-live-kibana-stats
tsullivan 6e0cb9f
validate the payload fields
tsullivan 5c7036a
add warning log if no kibana stats returned
tsullivan 71be9bc
Merge branch 'master' into telemetry/pull-live-kibana-stats
tsullivan 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
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/xpack_main/server/lib/telemetry/local/get_kibana.js
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,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { get, omit } from 'lodash'; | ||
|
||
export function handleKibanaStats(server, response) { | ||
if (!response) { | ||
server.log(['warning', 'telemetry', 'local-stats'], 'No Kibana stats returned from usage collectors'); | ||
return; | ||
} | ||
|
||
const { kibana, kibana_stats: stats, ...plugins } = response; | ||
|
||
const platform = get(stats, 'os.platform', 'unknown'); | ||
const platformRelease = get(stats, 'os.platformRelease', 'unknown'); | ||
|
||
let version; | ||
const { kbnServer } = get(server, 'plugins.xpack_main.status.plugin'); | ||
if (kbnServer) { | ||
version = kbnServer.version.replace(/-snapshot/i, ''); | ||
} | ||
|
||
// combine core stats (os types, saved objects) with plugin usage stats | ||
// organize the object into the same format as monitoring-enabled telemetry | ||
return { | ||
...omit(kibana, 'index'), // discard index | ||
count: 1, | ||
indices: 1, | ||
os: { | ||
platforms: [{ platform, count: 1 }], | ||
platformReleases: [{ platformRelease, count: 1 }], | ||
}, | ||
versions: [{ version, count: 1 }], | ||
plugins, | ||
}; | ||
} | ||
|
||
/* | ||
* Check user privileges for read access to monitoring | ||
* Pass callWithInternalUser to bulkFetchUsage | ||
*/ | ||
export async function getKibana(server, callWithInternalUser) { | ||
const { collectorSet } = server.usage; | ||
const usage = await collectorSet.bulkFetch(callWithInternalUser); | ||
return collectorSet.toObject(usage); | ||
} |
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
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.
I'm kind of curious how we'd get in a state where
response
is validlynull
orundefined
. I could reasonably see it missing certain usage stats (e.g., from disabled or unused plugins), but not missing core data.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.
The reason for this early return is to avoid throwing exceptions for unit tests that don't pass in mock response for the
handleLocalStats
tests: https://github.com/elastic/kibana/pull/26496/files#diff-46ad76ce05cd14b05bdc60fc08f0001dR104There 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.
I'm not sure if that's a good thing though. We're allowing for a broken state of Kibana to simplify a few tests, which means we'll have to get luckier to catch it.
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.
How about add logging with a warning here?
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.
5c7036a