-
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
Add server OS information to telemetry stats #23793
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
802a740
Add server OS data to monitoring collector and telemetry
joshdover 06e9fa7
Merge remote-tracking branch 'upstream/master' into os-telemetry
joshdover dafc2de
Merge remote-tracking branch 'upstream/master' into os-telemetry
joshdover d325ee4
Fixup naming
joshdover d9cafda
Fix functional tests
joshdover 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
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/get_os_info.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,35 @@ | ||
/* | ||
* 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 os from 'os'; | ||
import getos from 'getos'; | ||
import { promisify } from 'util'; | ||
|
||
/** | ||
* Returns an object of OS information/ | ||
*/ | ||
export async function getOSInfo() { | ||
const osInfo = { | ||
platform: os.platform(), | ||
// Include the platform name in the release to avoid grouping unrelated platforms together. | ||
// release 1.0 across windows, linux, and darwin don't mean anything useful. | ||
platformRelease: `${os.platform()}-${os.release()}` | ||
}; | ||
|
||
// Get distribution information for linux | ||
if (os.platform() === 'linux') { | ||
try { | ||
const distro = await promisify(getos)(); | ||
osInfo.distro = distro.dist; | ||
// Include distro name in release for same reason as above. | ||
osInfo.distroRelease = `${distro.dist}-${distro.release}`; | ||
} catch (e) { | ||
// ignore errors | ||
} | ||
} | ||
|
||
return osInfo; | ||
} |
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/monitoring/server/kibana_monitoring/collectors/ops_buffer/get_os_info.test.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,53 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
jest.mock('os', () => ({ | ||
platform: jest.fn(), | ||
release: jest.fn(), | ||
})); | ||
jest.mock('getos'); | ||
|
||
import os from 'os'; | ||
import getos from 'getos'; | ||
|
||
import { getOSInfo } from './get_os_info'; | ||
|
||
describe('getOSInfo', () => { | ||
it('returns basic OS info on non-linux', async () => { | ||
os.platform.mockImplementation(() => 'darwin'); | ||
os.release.mockImplementation(() => '1.0.0'); | ||
|
||
const osInfo = await getOSInfo(); | ||
|
||
expect(osInfo).toEqual({ | ||
platform: 'darwin', | ||
platformRelease: 'darwin-1.0.0', | ||
}); | ||
}); | ||
|
||
it('returns basic OS info and distro info on linux', async () => { | ||
os.platform.mockImplementation(() => 'linux'); | ||
os.release.mockImplementation(() => '4.9.93-linuxkit-aufs'); | ||
|
||
// Mock getos response | ||
getos.mockImplementation((cb) => cb(null, { | ||
os: 'linux', | ||
dist: 'Ubuntu Linux', | ||
codename: 'precise', | ||
release: '12.04' | ||
})); | ||
|
||
const osInfo = await getOSInfo(); | ||
|
||
expect(osInfo).toEqual({ | ||
platform: 'linux', | ||
platformRelease: 'linux-4.9.93-linuxkit-aufs', | ||
// linux distro info | ||
distro: 'Ubuntu Linux', | ||
distroRelease: 'Ubuntu Linux-12.04', | ||
}); | ||
}); | ||
}); |
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
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
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.
If
buffer.flush()
returns a promise, then isn't this fundamentally the same as the previous code? A returned promise will have to be awaited by the caller either way, right?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.
Spencer got me in this habit of awaiting to make it more clear what was going on and to prevent bugs when you want to catch any exceptions that an async function might throw. If you were to add try/catch around this without awaiting you would never catch anything.