From e9645dd091179be5943cb7470849716c3f790d19 Mon Sep 17 00:00:00 2001
From: evgenyfedorov2 <25526458+evgenyfedorov2@users.noreply.github.com>
Date: Thu, 29 Aug 2024 10:26:18 +0200
Subject: [PATCH 1/3] Expose Snapshot API
---
.../ISnapshotProvider.cs | 8 +++++---
.../ResourceUtilization.cs | 7 ++++++-
.../Snapshot.cs | 4 +++-
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ISnapshotProvider.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ISnapshotProvider.cs
index 4646fafb61c..adc5c0b2618 100644
--- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ISnapshotProvider.cs
+++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ISnapshotProvider.cs
@@ -1,12 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
+using Microsoft.Shared.DiagnosticIds;
+
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
///
/// An interface to be implemented by a provider that represents an underlying system and gets resources data about it.
///
-internal interface ISnapshotProvider
+[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
+public interface ISnapshotProvider
{
///
/// Gets the static values of CPU and memory limitations defined by the system.
@@ -17,7 +21,5 @@ internal interface ISnapshotProvider
/// Get a snapshot of the resource utilization of the system.
///
/// An appropriate sample.
-#pragma warning disable S4049 // Properties should be preferred
Snapshot GetSnapshot();
-#pragma warning restore S4049 // Properties should be preferred
}
diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilization.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilization.cs
index 0645f2270bb..ff62aea2218 100644
--- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilization.cs
+++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilization.cs
@@ -3,6 +3,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
@@ -41,7 +42,11 @@ public readonly struct ResourceUtilization
///
public SystemResources SystemResources { get; }
- internal Snapshot Snapshot { get; } = default;
+ ///
+ /// Gets the latest snapshot of the resource utilization of the system.
+ ///
+ [Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
+ public Snapshot Snapshot { get; } = default;
///
/// Initializes a new instance of the struct.
diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Snapshot.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Snapshot.cs
index 8b6fd850cdd..a5955893143 100644
--- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Snapshot.cs
+++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Snapshot.cs
@@ -3,6 +3,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
+using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
@@ -11,7 +12,8 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// A snapshot of CPU and memory usage taken periodically over time.
///
[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Comparing instances is not an expected scenario")]
-internal readonly struct Snapshot
+[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
+public readonly struct Snapshot
{
///
/// Gets the total CPU time that has elapsed since startup.
From f08f115a0f436235d0fd634acfa185868447890f Mon Sep 17 00:00:00 2001
From: evgenyfedorov2 <25526458+evgenyfedorov2@users.noreply.github.com>
Date: Thu, 29 Aug 2024 10:59:11 +0200
Subject: [PATCH 2/3] Remove more uncessary suppressions of S4049
---
.../Provider/NullConfigureContextualOptions.cs | 1 -
.../ApiLifecycle/ApiLifecycleAnalyzerTest.cs | 1 -
2 files changed, 2 deletions(-)
diff --git a/src/Libraries/Microsoft.Extensions.Options.Contextual/Provider/NullConfigureContextualOptions.cs b/src/Libraries/Microsoft.Extensions.Options.Contextual/Provider/NullConfigureContextualOptions.cs
index 3721b4eba7a..dee6602057a 100644
--- a/src/Libraries/Microsoft.Extensions.Options.Contextual/Provider/NullConfigureContextualOptions.cs
+++ b/src/Libraries/Microsoft.Extensions.Options.Contextual/Provider/NullConfigureContextualOptions.cs
@@ -13,7 +13,6 @@ public static class NullConfigureContextualOptions
///
/// The options type to configure.
/// A do-nothing instance of .
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S4049:Properties should be preferred", Justification = "Not possible for generic methods.")]
public static IConfigureContextualOptions GetInstance()
where TOptions : class
=> NullConfigureContextualOptions.Instance;
diff --git a/test/Analyzers/Microsoft.Analyzers.Local.Tests/ApiLifecycle/ApiLifecycleAnalyzerTest.cs b/test/Analyzers/Microsoft.Analyzers.Local.Tests/ApiLifecycle/ApiLifecycleAnalyzerTest.cs
index 87afb05f182..3e69badedce 100644
--- a/test/Analyzers/Microsoft.Analyzers.Local.Tests/ApiLifecycle/ApiLifecycleAnalyzerTest.cs
+++ b/test/Analyzers/Microsoft.Analyzers.Local.Tests/ApiLifecycle/ApiLifecycleAnalyzerTest.cs
@@ -442,7 +442,6 @@ namespace Microsoft.Extensions.AsyncState;
[Obsolete(""Deprecated since 1.17.0 and will be removed in 1.20.0. Use IAsyncContext instead."")]
public interface IAsyncContext
{
- [SuppressMessage(""Minor Code Smell"", ""S4049:Properties should be preferred"", Justification = ""Not suitable"")]
T? GetAsyncState()
where T : notnull;
From b7b585abaa481d0021e89ee892c5892c1e6b6f99 Mon Sep 17 00:00:00 2001
From: evgenyfedorov2 <25526458+evgenyfedorov2@users.noreply.github.com>
Date: Thu, 29 Aug 2024 11:42:00 +0200
Subject: [PATCH 3/3] .
---
.../ApiLifecycle/ApiLifecycleAnalyzerTest.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/test/Analyzers/Microsoft.Analyzers.Local.Tests/ApiLifecycle/ApiLifecycleAnalyzerTest.cs b/test/Analyzers/Microsoft.Analyzers.Local.Tests/ApiLifecycle/ApiLifecycleAnalyzerTest.cs
index 3e69badedce..87afb05f182 100644
--- a/test/Analyzers/Microsoft.Analyzers.Local.Tests/ApiLifecycle/ApiLifecycleAnalyzerTest.cs
+++ b/test/Analyzers/Microsoft.Analyzers.Local.Tests/ApiLifecycle/ApiLifecycleAnalyzerTest.cs
@@ -442,6 +442,7 @@ namespace Microsoft.Extensions.AsyncState;
[Obsolete(""Deprecated since 1.17.0 and will be removed in 1.20.0. Use IAsyncContext instead."")]
public interface IAsyncContext
{
+ [SuppressMessage(""Minor Code Smell"", ""S4049:Properties should be preferred"", Justification = ""Not suitable"")]
T? GetAsyncState()
where T : notnull;