-
Notifications
You must be signed in to change notification settings - Fork 841
Add Kubernetes based Resource Monitoring #6748
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
base: main
Are you sure you want to change the base?
Add Kubernetes based Resource Monitoring #6748
Conversation
# Conflicts: # src/Shared/Instruments/ResourceUtilizationInstruments.cs
...aries/Microsoft.Extensions.ClusterMetadata.Kubernetes/KubernetesClusterMetadataExtensions.cs
Outdated
Show resolved
Hide resolved
...Extensions.ClusterMetadata.Kubernetes/Microsoft.Extensions.ClusterMetadata.Kubernetes.csproj
Outdated
Show resolved
Hide resolved
...raries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs
Outdated
Show resolved
Hide resolved
...rosoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsContainerSnapshotProvider.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/IResourceQuotasProvider.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceQuotas.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/IResourceQuotasProvider.cs
Outdated
Show resolved
Hide resolved
...ostics.ResourceMonitoring.Kubernetes/KubernetesResourceQuotasServiceCollectionsExtensions.cs
Outdated
Show resolved
Hide resolved
….com/amadeuszl/extensions into users/alechniak/kuberenetes-metadata
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.
Pull Request Overview
This PR refactors resource monitoring to extract quota calculation logic into dedicated ResourceQuotaProvider implementations and adds Kubernetes support for resource monitoring. The changes separate concerns by moving resource limit/request determination out of snapshot providers into reusable quota providers.
Key changes:
- Introduces
ResourceQuotamodel andResourceQuotaProviderabstract base class for platform-agnostic quota retrieval - Creates
WindowsContainerResourceQuotaProviderandLinuxResourceQuotaProviderimplementations for existing platforms - Adds new
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kuberneteslibrary with Kubernetes-specific quota provider that reads from environment variables
Reviewed Changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| ResourceQuota.cs | New model class defining CPU and memory quota properties (max and baseline) |
| ResourceQuotaProvider.cs | New abstract base class for quota provider implementations |
| WindowsContainerResourceQuotaProvider.cs | Extracts Windows quota logic from WindowsContainerSnapshotProvider |
| WindowsContainerSnapshotProvider.cs | Refactored to use ResourceQuotaProvider dependency |
| LinuxResourceQuotaProvider.cs | Extracts Linux quota logic from LinuxUtilizationProvider |
| LinuxUtilizationProvider.cs | Refactored to use ResourceQuotaProvider dependency |
| ILinuxUtilizationParser.cs | Adds GetMinMemoryInBytes() method for reading memory requests |
| LinuxUtilizationParserCgroupV1.cs | Stub implementation returning 0 (no request support in v1) |
| LinuxUtilizationParserCgroupV2.cs | Implements GetMinMemoryInBytes() reading memory.min/memory.low files |
| KubernetesMetadata.cs | Reads Kubernetes resource limits/requests from environment variables |
| KubernetesResourceQuotaProvider.cs | Kubernetes-specific quota provider converting millicores to cores |
| KubernetesResourceQuotaServiceCollectionExtensions.cs | DI registration for Kubernetes resource monitoring |
| ResourceMonitoringServiceCollectionExtensions.cs | Registers appropriate ResourceQuotaProvider for each platform |
| Test files | Updates all tests to create ResourceQuotaProvider instances; adds comprehensive Kubernetes test coverage |
...gnostics.ResourceMonitoring.Kubernetes/KubernetesResourceQuotaServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
...braries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes/KubernetesMetadata.cs
Outdated
Show resolved
Hide resolved
...braries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes/KubernetesMetadata.cs
Outdated
Show resolved
Hide resolved
...braries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/ILinuxUtilizationParser.cs
Outdated
Show resolved
Hide resolved
...osoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs
Outdated
Show resolved
Hide resolved
...gnostics.ResourceMonitoring.Kubernetes/KubernetesResourceQuotaServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
...gnostics.ResourceMonitoring.Kubernetes/KubernetesResourceQuotaServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
| /// Maximum values define the upper limits of resource usage, while baseline values specify | ||
| /// the minimum assured resource allocations. |
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 does it translate into K8s request and limits?
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.
max are limits, and baselines are requests
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.
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.
do you think it makes sense to reflect that in XML documentation here?
...soft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes/KubernetesResourceQuotaProvider.cs
Show resolved
Hide resolved
...gnostics.ResourceMonitoring.Kubernetes/KubernetesResourceQuotaServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
...soft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes/KubernetesResourceQuotaProvider.cs
Show resolved
Hide resolved
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <Stage>normal</Stage> |
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 think it should be dev stage initially. After one release (= one month) we can change it to normal. And in this case we don't have to bother with EnablePackageValidation because it is not enabled for dev packages:
extensions/eng/MSBuild/Packaging.targets
Line 40 in 7ddf87e
| <PackageValidationBaselineVersion Condition="'$(Stage)' == 'normal' and '$(PackageValidationBaselineVersion)' == ''">9.10.0</PackageValidationBaselineVersion> |
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.
Let me verify that. I would prefer to release it already in December as normal.
Fix #6496
Microsoft Reviewers: Open in CodeFlow