Skip to content

Commit

Permalink
Add Obsolete attribute on IResourceMonitor and its friends (#5774)
Browse files Browse the repository at this point in the history
Co-authored-by: Evgenii Fedorov <evgenii.fedorov@microsoft.com>
  • Loading branch information
evgenyfedorov2 and Evgenii Fedorov authored Jan 16, 2025
1 parent b9510dd commit 8f15b0f
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;

/// <summary>
/// Provides the ability to sample the system for current resource utilization.
/// </summary>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public interface IResourceMonitor
{
/// <summary>
Expand All @@ -16,7 +20,7 @@ public interface IResourceMonitor
/// <param name="window">A <see cref="TimeSpan"/> representing the time window for which utilization is requested.</param>
/// <returns>The utilization during the time window specified by <paramref name="window"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is greater than the maximum window size
/// configured while adding the service to the services collection.
/// configured while adding the service to the service collection.
/// </exception>
ResourceUtilization GetUtilization(TimeSpan window);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;

/// <summary>
/// Helps building the resource monitoring infrastructure.
/// Helps build the resource monitoring infrastructure.
/// </summary>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public interface IResourceMonitorBuilder
{
/// <summary>
Expand All @@ -23,12 +26,6 @@ public interface IResourceMonitorBuilder
/// </summary>
/// <typeparam name="T">The publisher's implementation type.</typeparam>
/// <returns>The value of the object instance.</returns>
#if !NET5_0_OR_GREATER
#pragma warning disable CS0436 // Type conflicts with imported type
#endif
[Obsolete(DiagnosticIds.Obsoletions.IResourceUtilizationPublisherMessage,
DiagnosticId = DiagnosticIds.Obsoletions.IResourceUtilizationPublisherDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
IResourceMonitorBuilder AddPublisher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>()
where T : class, IResourceUtilizationPublisher;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// <summary>
/// Defines the contract for a resource utilization publisher that gets invoked whenever resource utilization is computed.
/// </summary>
#if !NET5_0_OR_GREATER
#pragma warning disable CS0436 // Type conflicts with imported type
#endif
[Obsolete(DiagnosticIds.Obsoletions.IResourceUtilizationPublisherMessage,
DiagnosticId = DiagnosticIds.Obsoletions.IResourceUtilizationPublisherDiagId,
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public interface IResourceUtilizationPublisher
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Shared.DiagnosticIds;

Expand All @@ -10,6 +11,9 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// An interface to be implemented by a provider that represents an underlying system and gets resources data about it.
/// </summary>
[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public interface ISnapshotProvider
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<RootNamespace>Microsoft.Extensions.Diagnostics.ResourceMonitoring</RootNamespace>
<Description>Measures processor and memory usage.</Description>
<Workstream>ResourceMonitoring</Workstream>
<NoWarn Condition="'$(TargetFramework)' == 'net462'">$(NoWarn);CS0436</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ public ResourceMonitorBuilder(IServiceCollection services)
Services = services;
}

#if !NET5_0_OR_GREATER
#pragma warning disable CS0436 // Type conflicts with imported type
#endif
[Obsolete(DiagnosticIds.Obsoletions.IResourceUtilizationPublisherMessage,
DiagnosticId = DiagnosticIds.Obsoletions.IResourceUtilizationPublisherDiagId,
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public IResourceMonitorBuilder AddPublisher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>()
where T : class, IResourceUtilizationPublisher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;

/// <summary>
/// Lets you configure and register resource monitoring components.
/// </summary>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public static class ResourceMonitoringBuilderExtensions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using Microsoft.Shared.Data.Validation;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;

Expand Down Expand Up @@ -31,6 +32,9 @@ public partial class ResourceMonitoringOptions
/// This value represents the total amount of time for which the resource monitor tracks utilization
/// information for the system.
/// </remarks>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
[TimeSpan(MinimumSamplingWindow, MaximumSamplingWindow)]
public TimeSpan CollectionWindow { get; set; } = DefaultCollectionWindow;

Expand All @@ -43,6 +47,9 @@ public partial class ResourceMonitoringOptions
/// <remarks>
/// This value must be less than or equal to <see cref="CollectionWindow"/>.
/// </remarks>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
[TimeSpan(MinimumSamplingPeriod, MaximumSamplingPeriod)]
public TimeSpan SamplingInterval { get; set; } = DefaultSamplingInterval;

Expand All @@ -55,6 +62,9 @@ public partial class ResourceMonitoringOptions
/// <remarks>
/// The value needs to be less than or equal to <see cref="CollectionWindow"/>.
/// </remarks>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
[TimeSpan(MinimumSamplingWindow, MaximumSamplingWindow)]
public TimeSpan PublishingWindow { get; set; } = DefaultCollectionWindow;

Expand All @@ -67,6 +77,9 @@ public partial class ResourceMonitoringOptions
/// <remarks>
/// This is the time interval for a metric value to fetch resource utilization data from the operating system.
/// </remarks>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
[TimeSpan(MinimumCachingInterval, MaximumCachingInterval)]
public TimeSpan CpuConsumptionRefreshInterval { get; set; } = DefaultRefreshInterval;

Expand All @@ -79,6 +92,9 @@ public partial class ResourceMonitoringOptions
/// <remarks>
/// This is the time interval for a metric value to fetch resource utilization data from the operating system.
/// </remarks>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
[TimeSpan(MinimumCachingInterval, MaximumCachingInterval)]
public TimeSpan MemoryConsumptionRefreshInterval { get; set; } = DefaultRefreshInterval;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows;
using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop;
using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Network;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -43,6 +44,9 @@ public static IServiceCollection AddResourceMonitoring(
/// <param name="configure">Delegate to configure <see cref="IResourceMonitorBuilder"/>.</param>
/// <returns>The value of <paramref name="services" />.</returns>
/// <exception cref="ArgumentNullException">Either <paramref name="services"/> or <paramref name="configure"/> is <see langword="null"/>.</exception>
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public static IServiceCollection AddResourceMonitoring(
this IServiceCollection services,
Action<IResourceMonitorBuilder> configure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// Captures resource usage at a given point in time.
/// </summary>
[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Comparing instances is not an expected scenario")]
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public readonly struct ResourceUtilization
{
private const double Hundred = 100.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// </summary>
[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Comparing instances is not an expected scenario")]
[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public readonly struct Snapshot
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
Expand All @@ -9,6 +11,9 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// Provides information about the CPU and memory limits defined by the underlying system.
/// </summary>
#pragma warning disable CA1815 // Override equals and operator equals on value types
[Obsolete(DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiMessage,
DiagnosticId = DiagnosticIds.Obsoletions.NonObservableResourceMonitoringApiDiagId,
UrlFormat = DiagnosticIds.UrlFormat)]
public readonly struct SystemResources
#pragma warning restore CA1815 // Override equals and operator equals on value types
{
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/DiagnosticIds/DiagnosticIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ internal static class AuditReports

internal static class Obsoletions
{
internal const string IResourceUtilizationPublisherDiagId = "EXTOBS0001";
internal const string IResourceUtilizationPublisherMessage = "This API is obsolete and will be removed in a future version. Consider using Resource Monitoring observable instruments.";
internal const string NonObservableResourceMonitoringApiDiagId = "EXTOBS0001";
internal const string NonObservableResourceMonitoringApiMessage = "This API is obsolete and will be removed in a future version. Consider using Resource Monitoring observable instruments.";
}
}

Expand Down

0 comments on commit 8f15b0f

Please sign in to comment.