Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

evgenyfedorov2
Copy link
Member

@evgenyfedorov2 evgenyfedorov2 commented Jul 8, 2025

Fixes #6587

Microsoft Reviewers: Open in CodeFlow

Adding container.memory.usage metric with ObservableUpDownCounter instrument type, measured in bytes.

@evgenyfedorov2 evgenyfedorov2 force-pushed the users/evgenyfedorov2/add_memory_usage_metric branch from 6989b03 to d671e88 Compare July 9, 2025 06:06
@evgenyfedorov2 evgenyfedorov2 marked this pull request as ready for review July 9, 2025 07:04
@Copilot Copilot AI review requested due to automatic review settings July 9, 2025 07:04
@evgenyfedorov2 evgenyfedorov2 requested review from a team as code owners July 9, 2025 07:04
Copilot

This comment was marked as outdated.

@evgenyfedorov2 evgenyfedorov2 force-pushed the users/evgenyfedorov2/add_memory_usage_metric branch from 9779fd3 to dd6b70f Compare July 9, 2025 07:12
@evgenyfedorov2 evgenyfedorov2 requested a review from Copilot July 9, 2025 07:12
Copilot

This comment was marked as outdated.

@evgenyfedorov2 evgenyfedorov2 force-pushed the users/evgenyfedorov2/add_memory_usage_metric branch 2 times, most recently from ac948f7 to 120a012 Compare July 9, 2025 08:03
@evgenyfedorov2 evgenyfedorov2 requested a review from Copilot July 9, 2025 08:05
Copilot

This comment was marked as outdated.

@evgenyfedorov2 evgenyfedorov2 requested a review from Copilot July 9, 2025 08:12
Copilot

This comment was marked as outdated.

@evgenyfedorov2 evgenyfedorov2 force-pushed the users/evgenyfedorov2/add_memory_usage_metric branch from 2b4b3ed to 66a792d Compare July 9, 2025 08:16
@evgenyfedorov2 evgenyfedorov2 requested a review from amadeuszl July 9, 2025 08:24
@evgenyfedorov2 evgenyfedorov2 force-pushed the users/evgenyfedorov2/add_memory_usage_metric branch from 66a792d to e06592f Compare July 9, 2025 08:38
@evgenyfedorov2 evgenyfedorov2 requested a review from Copilot July 9, 2025 08:38
Copilot

This comment was marked as outdated.

@evgenyfedorov2 evgenyfedorov2 force-pushed the users/evgenyfedorov2/add_memory_usage_metric branch from e06592f to 244d332 Compare July 9, 2025 09:50
@evgenyfedorov2 evgenyfedorov2 force-pushed the users/evgenyfedorov2/add_memory_usage_metric branch from 244d332 to 412064a Compare July 9, 2025 11:26
@evgenyfedorov2 evgenyfedorov2 requested a review from Copilot July 9, 2025 11:27
Copilot

This comment was marked as outdated.

@dotnet-policy-service dotnet-policy-service bot added the waiting-author-feedback 📭 The author of this issue needs to respond in order for us to continue investigating this issue. label Jul 11, 2025
@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback 📭 The author of this issue needs to respond in order for us to continue investigating this issue. label Jul 11, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new container.memory.usage metric (bytes) as an ObservableUpDownCounter across Windows and Linux, updates logging, and extends tests to validate the new instrument.

  • Introduce ContainerMemoryUsage constant and register it in both Windows and Linux providers.
  • Refactor snapshot providers to expose container memory usage and separate percentage calculations, updating log messages.
  • Extend unit and acceptance tests to subscribe to and assert on the new memory‐usage metric.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/.../Windows/WindowsContainerSnapshotProviderTests.cs Added tests for combined container/process memory metrics and standalone usage test
test/.../Linux/LinuxUtilizationProviderTests.cs Captured ContainerMemoryUsage in measurements, updated expected sample/retry counts
test/.../Linux/AcceptanceTest.cs Subscribed to and asserted on new container memory usage gauge
test/.../ResourceUtilizationHealthChecks/ResourceHealthCheckExtensionsTests.cs Added GetCurrentProcessMemoryUsage setup for health‐check tests
src/Shared/Instruments/ResourceUtilizationInstruments.cs Added public const string ContainerMemoryUsage constant with XML docs
src/Libraries/.../Windows/WindowsSnapshotProvider.cs Refactored memory methods, added _processMemoryLocker, new up/down counter, log rename
src/Libraries/.../Windows/Log.cs Added ContainerMemoryUsageData and ProcessMemoryPercentageData messages
src/Libraries/.../Linux/Log.cs Renamed MemoryUsageData to MemoryPercentageData, added new MemoryUsageData
src/Libraries/.../Linux/LinuxUtilizationProvider.cs Refactored memory methods, added up/down counter for usage, updated retry helper
Comments suppressed due to low confidence (2)

src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsContainerSnapshotProvider.cs:234

  • Logging while holding the _memoryLocker can lead to lock contention or unexpected delays. It’s safer to capture the values inside the lock and invoke the logger after releasing the lock to minimize the duration of the critical section.
                _logger.ProcessMemoryPercentageData(processMemoryUsage, _memoryLimit, _processMemoryPercentage);

src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/Log.cs:69

  • The totalMemory parameter represents a byte count but is typed as double. For consistency with processMemoryUsage and to avoid implicit conversions, consider changing totalMemory to ulong.
        double memoryPercentage);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a metric for memory usage to Resource Monitoring
3 participants