Skip to content
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

Deprecate IResourceUtilizationPublisher #5360

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Extensions.DependencyInjection;

Expand All @@ -21,6 +22,7 @@ public interface IResourceMonitorBuilder
/// </summary>
/// <typeparam name="T">The publisher's implementation type.</typeparam>
/// <returns>The value of the object instance.</returns>
[Obsolete("This method is obsolete. Instead of IResourceUtilizationPublisher use observable instruments from Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceUtilizationInstruments.")]
evgenyfedorov2 marked this conversation as resolved.
Show resolved Hide resolved
IResourceMonitorBuilder AddPublisher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>()
where T : class, IResourceUtilizationPublisher;
}
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.Threading;
using System.Threading.Tasks;

Expand All @@ -9,6 +10,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// <summary>
/// Defines the contract for a resource utilization publisher that gets invoked whenever resource utilization is computed.
/// </summary>
[Obsolete("This interface is obsolete. Instead, use observable instruments from Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceUtilizationInstruments.")]
public interface IResourceUtilizationPublisher
{
/// <summary>
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.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -21,6 +22,7 @@ public ResourceMonitorBuilder(IServiceCollection services)
Services = services;
}

[Obsolete("This method is obsolete. Instead, use observable instruments from Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceUtilizationInstruments.")]
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 @@ -29,10 +29,12 @@ internal sealed class ResourceMonitorService : BackgroundService, IResourceMonit
/// </summary>
private readonly ISnapshotProvider _provider;

#pragma warning disable CS0618 // Type or member is obsolete
/// <summary>
/// The publishers to use with the data we are tracking.
/// </summary>
private readonly IResourceUtilizationPublisher[] _publishers;
#pragma warning restore CS0618 // Type or member is obsolete

/// <summary>
/// Logger to be used in this class.
Expand All @@ -55,7 +57,9 @@ public ResourceMonitorService(
ISnapshotProvider provider,
ILogger<ResourceMonitorService> logger,
IOptions<ResourceMonitoringOptions> options,
#pragma warning disable CS0618 // Type or member is obsolete
IEnumerable<IResourceUtilizationPublisher> publishers)
#pragma warning restore CS0618 // Type or member is obsolete
: this(provider, logger, options, publishers, TimeProvider.System)
{
}
Expand All @@ -64,7 +68,9 @@ internal ResourceMonitorService(
ISnapshotProvider provider,
ILogger<ResourceMonitorService> logger,
IOptions<ResourceMonitoringOptions> options,
#pragma warning disable CS0618 // Type or member is obsolete
IEnumerable<IResourceUtilizationPublisher> publishers,
#pragma warning restore CS0618 // Type or member is obsolete
TimeProvider timeProvider)
{
_provider = provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// <summary>
/// Represents the names of instruments published by this package.
/// </summary>
/// <remarks>
/// These metrics are currently only published on Linux.
/// </remarks>
/// <seealso cref="System.Diagnostics.Metrics.Instrument"/>
internal static class ResourceUtilizationInstruments
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows;

#pragma warning disable S109
#pragma warning disable IDE0060 // Remove unused parameters - Reason: used by source generator.

internal static partial class Log
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou
.AddSingleton<TimeProvider>(clock)
.AddSingleton<IUserHz>(new FakeUserHz(100))
.AddSingleton<IFileSystem>(fileSystem)
#pragma warning disable CS0618 // Type or member is obsolete
.AddSingleton<IResourceUtilizationPublisher>(new GenericPublisher(_ => e.Set()))
#pragma warning restore CS0618 // Type or member is obsolete
.AddResourceMonitoring())
.Build();

Expand Down Expand Up @@ -312,7 +314,9 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou
.AddSingleton<TimeProvider>(clock)
.AddSingleton<IUserHz>(new FakeUserHz(100))
.AddSingleton<IFileSystem>(fileSystem)
#pragma warning disable CS0618 // Type or member is obsolete
.AddSingleton<IResourceUtilizationPublisher>(new GenericPublisher(_ => e.Set()))
#pragma warning restore CS0618 // Type or member is obsolete
.AddResourceMonitoring()
.Replace(ServiceDescriptor.Singleton<ILinuxUtilizationParser, LinuxUtilizationParserCgroupV2>()))
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test;
/// <summary>
/// A publisher that accept <see cref="Action{Utilization}"/> in its constructor.
/// </summary>
[Obsolete("Testing the obsolete IResourceUtilizationPublisher interface.")]
internal sealed class GenericPublisher : IResourceUtilizationPublisher
{
private readonly Action<ResourceUtilization> _publish;
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.Threading;
using System.Threading.Tasks;

Expand All @@ -9,6 +10,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Publishers;
/// <summary>
/// Another publisher that do nothing, added to test scenarios where multiple publishers are added to the services collections.
/// </summary>
[Obsolete("Testing the obsolete IResourceUtilizationPublisher interface.")]
internal sealed class AnotherPublisher : IResourceUtilizationPublisher
{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +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;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Publishers;

/// <summary>
/// A publisher that do nothing.
/// A publisher that does nothing.
/// </summary>
[Obsolete("Testing the obsolete IResourceUtilizationPublisher interface.")]
internal sealed class EmptyPublisher : IResourceUtilizationPublisher
{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Publishers;
/// <summary>
/// A publisher that throws an error.
/// </summary>
[Obsolete("Testing the obsolete IResourceUtilizationPublisher interface.")]
internal sealed class FaultPublisher : IResourceUtilizationPublisher
{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Publishers;
/// <summary>
/// A publisher that accept <see cref="Action{Utilization}"/> in its constructor.
/// </summary>
[Obsolete("Testing the obsolete IResourceUtilizationPublisher interface.")]
internal sealed class GenericPublisher : IResourceUtilizationPublisher
{
private readonly Action<ResourceUtilization> _publish;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test;

#pragma warning disable CS0618 // Type or member is obsolete - IResourceUtilizationPublisher is obsolete, but we still need code coverage.
public sealed class ResourceMonitoringBuilderTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test;

#pragma warning disable CS0618 // Type or member is obsolete - IResourceUtilizationPublisher is obsolete, but we still need code coverage.
public sealed class ResourceMonitoringExtensionsTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test;
/// <summary>
/// Tests for the DataTracker class.
/// </summary>
#pragma warning disable CS0618 // Type or member is obsolete - IResourceUtilizationPublisher is obsolete, but we still need code coverage.
public sealed class ResourceMonitoringServiceTests
{
private const string ProviderUnableToGatherData = "Unable to gather utilization statistics.";
Expand All @@ -32,7 +33,7 @@ public sealed class ResourceMonitoringServiceTests
/// <summary>
/// Simply construct the object.
/// </summary>
/// <remarks>Tests that look into internals like this are evil. Consider removing long term.</remarks>
/// <remarks>Tests that look into internals like this are evil. Consider removing long term.</remarks>
[Fact]
public void BasicConstructor()
{
Expand Down Expand Up @@ -75,7 +76,7 @@ public void BasicConstructor_NullOptions_Throws()
/// <summary>
/// Simply construct the object (publisher constructor).
/// </summary>
/// <remarks>Tests that look into internals like this are evil. Consider removing long term.</remarks>
/// <remarks>Tests that look into internals like this are evil. Consider removing long term.</remarks>
[Fact]
public void BasicConstructor_NullPublishers_Throws()
{
Expand Down Expand Up @@ -293,7 +294,7 @@ public async Task RunTrackerAsync_IfPublisherThrows_LogsError()
/// <summary>
/// Validate that the tracker invokes the publisher's Publish method.
/// </summary>
/// <remarks>Tests that look into internals like this are evil. Consider removing long term.</remarks>
/// <remarks>Tests that look into internals like this are evil. Consider removing long term.</remarks>
[Fact]
public async Task ResourceUtilizationTracker_InitializedProperly_InvokesPublishers()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Microsoft.Extensions.Http.Resilience.Test.Resilience;

#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete

public class RequestMessageSnapshotTests
Expand Down