-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Fetches control group resource information #10402
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bebddda
Adds control group data to status API and kbnServer.metrics
tylersmalley 1a66767
Fixes control group issue
tylersmalley ea394a2
Await call to getMetrics()
tylersmalley 378386e
Prevent IO if cgroups is not available
tylersmalley bfcde14
Adds hack for docker cgroup path
tylersmalley 3d1caca
Adds radix to parseInt
tylersmalley 71a60b1
Override should be a string and we should log errors
tylersmalley 8bb236b
Use stub to remove duplication
tylersmalley 3ba904d
Adds documentation for cgroup override
tylersmalley cccef8a
Updates description for cgroup override
tylersmalley 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,170 @@ | ||
| import expect from 'expect.js'; | ||
| import mockFs from 'mock-fs'; | ||
| import { cGroups as cGroupsFsStub } from './fs_stubs'; | ||
| import { getAllStats, readControlGroups, readCPUStat } from '../cgroup'; | ||
|
|
||
| describe('Control Group', function () { | ||
| const fsStub = cGroupsFsStub(); | ||
|
|
||
| afterEach(() => { | ||
| mockFs.restore(); | ||
| }); | ||
|
|
||
| describe('readControlGroups', () => { | ||
| it('parses the file', async () => { | ||
| mockFs({ '/proc/self/cgroup': fsStub.cGroupContents }); | ||
| const cGroup = await readControlGroups(); | ||
|
|
||
| expect(cGroup).to.eql({ | ||
| freezer: '/', | ||
| net_cls: '/', | ||
| net_prio: '/', | ||
| pids: '/', | ||
| blkio: '/', | ||
| memory: '/', | ||
| devices: '/user.slice', | ||
| hugetlb: '/', | ||
| perf_event: '/', | ||
| cpu: `/${fsStub.hierarchy}`, | ||
| cpuacct: `/${fsStub.hierarchy}`, | ||
| cpuset: `/${fsStub.hierarchy}`, | ||
| 'name=systemd': '/user.slice/user-1000.slice/session-2359.scope' | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('readCPUStat', () => { | ||
| it('parses the file', async () => { | ||
| mockFs({ '/sys/fs/cgroup/cpu/fakeGroup/cpu.stat': fsStub.cpuStatContents }); | ||
| const cpuStat = await readCPUStat('fakeGroup'); | ||
|
|
||
| expect(cpuStat).to.eql({ | ||
| number_of_elapsed_periods: 0, | ||
| number_of_times_throttled: 10, | ||
| time_throttled_nanos: 20 | ||
| }); | ||
| }); | ||
|
|
||
| it('returns default stats for missing file', async () => { | ||
| mockFs(); | ||
| const cpuStat = await readCPUStat('fakeGroup'); | ||
|
|
||
| expect(cpuStat).to.eql({ | ||
| number_of_elapsed_periods: -1, | ||
| number_of_times_throttled: -1, | ||
| time_throttled_nanos: -1 | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getAllStats', () => { | ||
| it('can override the cpu group path', async () => { | ||
| mockFs({ | ||
| '/proc/self/cgroup': fsStub.cGroupContents, | ||
| [`${fsStub.cpuAcctDir}/cpuacct.usage`]: '357753491408', | ||
| '/sys/fs/cgroup/cpu/docker/cpu.cfs_period_us': '100000', | ||
| '/sys/fs/cgroup/cpu/docker/cpu.cfs_quota_us': '5000', | ||
| '/sys/fs/cgroup/cpu/docker/cpu.stat': fsStub.cpuStatContents, | ||
| }); | ||
|
|
||
| console.log('fsStub.cpuAcctDir', fsStub.cpuAcctDir); | ||
| const stats = await getAllStats({ cpuPath: '/docker' }); | ||
|
|
||
| expect(stats).to.eql({ | ||
| cpuacct: { | ||
| control_group: `/${fsStub.hierarchy}`, | ||
| usage_nanos: 357753491408, | ||
| }, | ||
| cpu: { | ||
| control_group: '/docker', | ||
| cfs_period_micros: 100000, | ||
| cfs_quota_micros: 5000, | ||
| stat: { | ||
| number_of_elapsed_periods: 0, | ||
| number_of_times_throttled: 10, | ||
| time_throttled_nanos: 20 | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('can override the cpuacct group path', async () => { | ||
| mockFs({ | ||
| '/proc/self/cgroup': fsStub.cGroupContents, | ||
| '/sys/fs/cgroup/cpuacct/docker/cpuacct.usage': '357753491408', | ||
| [`${fsStub.cpuDir}/cpu.cfs_period_us`]: '100000', | ||
| [`${fsStub.cpuDir}/cpu.cfs_quota_us`]: '5000', | ||
| [`${fsStub.cpuDir}/cpu.stat`]: fsStub.cpuStatContents, | ||
| }); | ||
|
|
||
| const stats = await getAllStats({ cpuAcctPath: '/docker' }); | ||
|
|
||
| expect(stats).to.eql({ | ||
| cpuacct: { | ||
| control_group: '/docker', | ||
| usage_nanos: 357753491408, | ||
| }, | ||
| cpu: { | ||
| control_group: `/${fsStub.hierarchy}`, | ||
| cfs_period_micros: 100000, | ||
| cfs_quota_micros: 5000, | ||
| stat: { | ||
| number_of_elapsed_periods: 0, | ||
| number_of_times_throttled: 10, | ||
| time_throttled_nanos: 20 | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('extracts control group stats', async () => { | ||
| mockFs(fsStub.files); | ||
| const stats = await getAllStats(); | ||
|
|
||
| expect(stats).to.eql({ | ||
| cpuacct: { | ||
| control_group: `/${fsStub.hierarchy}`, | ||
| usage_nanos: 357753491408, | ||
| }, | ||
| cpu: { | ||
| control_group: `/${fsStub.hierarchy}`, | ||
| cfs_period_micros: 100000, | ||
| cfs_quota_micros: 5000, | ||
| stat: { | ||
| number_of_elapsed_periods: 0, | ||
| number_of_times_throttled: 10, | ||
| time_throttled_nanos: 20 | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('returns null when all files are missing', async () => { | ||
| mockFs({}); | ||
| const stats = await getAllStats(); | ||
| expect(stats).to.be.null; | ||
| }); | ||
|
|
||
| it('returns null if CPU accounting files are missing', async () => { | ||
| mockFs({ | ||
| '/proc/self/cgroup': fsStub.cGroupContents, | ||
| [`${fsStub.cpuDir}/cpu.stat`]: fsStub.cpuStatContents | ||
| }); | ||
| const stats = await getAllStats(); | ||
|
|
||
| expect(stats).to.be.null; | ||
| }); | ||
|
|
||
| it('returns null if cpuStat file is missing', async () => { | ||
| mockFs({ | ||
| '/proc/self/cgroup': fsStub.cGroupContents, | ||
| [`${fsStub.cpuAcctDir}/cpuacct.usage`]: '357753491408', | ||
| [`${fsStub.cpuDir}/cpu.cfs_period_us`]: '100000', | ||
| [`${fsStub.cpuDir}/cpu.cfs_quota_us`]: '5000' | ||
| }); | ||
| const stats = await getAllStats(); | ||
|
|
||
| expect(stats).to.be.null; | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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,42 @@ | ||
| export function cGroups(hierarchy) { | ||
| if (!hierarchy) { | ||
| hierarchy = Math.random().toString(36).substring(7); | ||
| } | ||
|
|
||
| const cpuAcctDir = `/sys/fs/cgroup/cpuacct/${hierarchy}`; | ||
| const cpuDir = `/sys/fs/cgroup/cpu/${hierarchy}`; | ||
|
|
||
| const cGroupContents = [ | ||
| '10:freezer:/', | ||
| '9:net_cls,net_prio:/', | ||
| '8:pids:/', | ||
| '7:blkio:/', | ||
| '6:memory:/', | ||
| '5:devices:/user.slice', | ||
| '4:hugetlb:/', | ||
| '3:perf_event:/', | ||
| '2:cpu,cpuacct,cpuset:/' + hierarchy, | ||
| '1:name=systemd:/user.slice/user-1000.slice/session-2359.scope' | ||
| ].join('\n'); | ||
|
|
||
| const cpuStatContents = [ | ||
| 'nr_periods 0', | ||
| 'nr_throttled 10', | ||
| 'throttled_time 20' | ||
| ].join('\n'); | ||
|
|
||
| return { | ||
| hierarchy, | ||
| cGroupContents, | ||
| cpuStatContents, | ||
| cpuAcctDir, | ||
| cpuDir, | ||
| files: { | ||
| '/proc/self/cgroup': cGroupContents, | ||
| [`${cpuAcctDir}/cpuacct.usage`]: '357753491408', | ||
| [`${cpuDir}/cpu.cfs_period_us`]: '100000', | ||
| [`${cpuDir}/cpu.cfs_quota_us`]: '5000', | ||
| [`${cpuDir}/cpu.stat`]: cpuStatContents, | ||
| } | ||
| }; | ||
| } |
This file contains hidden or 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 don't feel like we normally specific "
override" as the field to override, rather justcpu.cgroup.pathwould be set or unset (default). Specifically I'm looking at examples likeserver.basePath,plugins.paths, andpath.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 name was discussed here for Logstash/ES. While I agree we could omit "override" it maintains consistency with the other projects.
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.
Ah that's unfortunate, but I guess it's intentional to really show that you're going against defaults.