-
Notifications
You must be signed in to change notification settings - Fork 763
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 support for Linux cgrpoup v2, issue-4885 #5068
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
87261f3
Add support for Linux cgrpoup v2, issue-4885
f32c9ad
Removed unnecessary using, ordered using, removed blank lines
da44f5f
Changed path for /sys/fs/cgroup/cpu/cpu.shares
3f75b40
Experimental attribute for GuaranteedPodCpuUnits added, removed blank…
87e64b8
Exprerimental attributes added
cda49b5
Removed the experimental parameter, agreed to reuse cpuGuaranteedRequest
a09bfc8
Acceptance test to support cgroupv2
0bc23ba
Removed unnessecary using
e80f7fb
Update src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitor…
danmoseley de0ca6b
Added Exists method for HardcodedValueFileSystem
0a4d70e
Merge branch 'issue-4885' of https://github.com/nezdali/extensions in…
89ee8fe
Adjusted the Preprocessor symbol
c124d5a
Moved cgroup version detection to a separate class
cca3d60
Summary added for ResourceMonitoringLinuxCgroupVersion class
1f9c963
Made cgroup detection class internal
742d0a4
Additional tests to cover cgroupv2 parser
c188df2
New method to get directory names with pattern and multiple test fixes
af86bc6
GetDirectoryNames method regex implementation
9ac1be5
refactored GetDirectoryNames for OSFIleSystem
5baf6ba
Added test to OSFileSystemTests.cs for GetDirectoryNames
d950ad3
Fix in OSFileSystemTests.cs
91b0a4b
Excluded from code coverage logic that identifies version of Cgroups
d24f868
Removed unnecessary 'using', fix for GetCgroupRequestCpu to return cp…
881f54b
Merge branch 'issue-4885' of https://github.com/nezdali/extensions in…
e4c69ae
Analyzer error fix
46cc5bf
Test fix
507f2ed
Removed one test
4f6eb8b
updated config path to fixtures to make osfilesystem test pass
05a0994
Added ExcludeFromCodeCoverage for GetCgroupType based on nested setting
5484960
Additional test for GetMemoryUsageInBytesFromSlices
00f46f5
Tests for GetCgroupCpuUsageInNanoseconds and for GetAvailableMemoryIn…
d099770
Update src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitor…
nezdali 031caa7
Renamed LinuxUtilizationParser to LinuxUtilizationParserCgroupV1 and …
d191d28
Merge branch 'issue-4885' of https://github.com/nezdali/extensions in…
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
69 changes: 69 additions & 0 deletions
69
...ries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/ILinuxUtilizationParser.cs
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,69 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux; | ||
|
||
/// <summary> | ||
/// An interface to be implemented by a parser that reads files and extracts resource utilization data from them. | ||
/// For both versions of cgroup controllers, the parser reads files from the /sys/fs/cgroup directory. | ||
/// </summary> | ||
internal interface ILinuxUtilizationParser | ||
{ | ||
/// <summary> | ||
/// Reads file /sys/fs/cgroup/memory.max, which is used to check the maximum amount of memory that can be used by a cgroup. | ||
/// It is part of the cgroup v2 memory controller. | ||
/// </summary> | ||
/// <returns>maybeMemory.</returns> | ||
ulong GetAvailableMemoryInBytes(); | ||
|
||
/// <summary> | ||
/// Reads the file /sys/fs/cgroup/cpu.stat, which is part of the cgroup v2 CPU controller. | ||
/// It provides statistics about the CPU usage of a cgroup. | ||
/// </summary> | ||
/// <returns>nanoseconds.</returns> | ||
long GetCgroupCpuUsageInNanoseconds(); | ||
xakep139 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// Reads the file /sys/fs/cgroup/cpu.max, which is part of the cgroup v2 CPU controller. | ||
/// It is used to set the maximum amount of CPU time that can be used by a cgroup. | ||
/// The file contains two fields, separated by a space. | ||
/// The first field is the quota, which specifies the maximum amount of CPU time (in microseconds) that can be used by the cgroup during one period. | ||
/// The second value is the period, which specifies the length of a period in microseconds. | ||
/// </summary> | ||
/// <returns>cpuUnits.</returns> | ||
float GetCgroupLimitedCpus(); | ||
|
||
/// <summary> | ||
/// Reads the file /proc/stat, which provides information about the system’s memory usage. | ||
/// It contains information about the total amount of installed memory, the amount of free and used memory, and the amount of memory used by the kernel and buffers/cache. | ||
/// </summary> | ||
/// <returns>memory.</returns> | ||
ulong GetHostAvailableMemory(); | ||
|
||
/// <summary> | ||
/// Reads the file /sys/fs/cgroup/cpuset.cpus.effective, which is part of the cgroup v2 cpuset controller. | ||
/// It shows the effective cpus that the cgroup can use. | ||
/// </summary> | ||
/// <returns>cpuCount.</returns> | ||
float GetHostCpuCount(); | ||
|
||
/// <summary> | ||
/// Reads the file /sys/fs/cgroup/cpu.stat, which is part of the cgroup v2 CPU controller. | ||
/// It provides statistics about the CPU usage of a cgroup. | ||
/// The file contains several fields, including usage_usec, which shows the total CPU time (in microseconds). | ||
/// </summary> | ||
/// <returns>total / (double)_userHz * NanosecondsInSecond.</returns> | ||
long GetHostCpuUsageInNanoseconds(); | ||
|
||
/// <summary> | ||
/// Reads the file /sys/fs/cgroup/memory.current, which is a file that contains the current memory usage of a cgroup in bytes. | ||
/// </summary> | ||
/// <returns>memoryUsage.</returns> | ||
ulong GetMemoryUsageInBytes(); | ||
|
||
/// <summary> | ||
/// Reads the file /sys/fs/cgroup/cpu.weight. And calculates the Pod CPU Request in millicores. | ||
/// </summary> | ||
/// <returns>cpuPodRequest.</returns> | ||
float GetCgroupRequestCpu(); | ||
} |
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.
Even though this is an internal class I'd caution against using mutable arrays as return values. This could lead to some gnarly hard to track bugs.
Could this be changed to something like
IList<string>
orIEnumerable<string>
?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.
Makes sense, will do the changes in another PR since this one is merged already.