From a094d15f7936201b09b68b67db282cfe8cf622e6 Mon Sep 17 00:00:00 2001 From: Massimiliano D'Acunzo Date: Thu, 17 Aug 2023 11:01:47 +0100 Subject: [PATCH 1/2] Refactored constants to reduce the number of obsoletions --- .../{Composables => }/HealthCheckConstants.cs | 9 +++++++-- .../Internal/HttpEndpointHealthCheck.cs | 3 ++- .../ServiceCollectionExtensions.cs | 7 +------ .../HttpEndpointHealthCheckTests.cs | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) rename src/Diagnostics.HealthChecks/{Composables => }/HealthCheckConstants.cs (52%) diff --git a/src/Diagnostics.HealthChecks/Composables/HealthCheckConstants.cs b/src/Diagnostics.HealthChecks/HealthCheckConstants.cs similarity index 52% rename from src/Diagnostics.HealthChecks/Composables/HealthCheckConstants.cs rename to src/Diagnostics.HealthChecks/HealthCheckConstants.cs index 1bf1f265..1eb2637b 100644 --- a/src/Diagnostics.HealthChecks/Composables/HealthCheckConstants.cs +++ b/src/Diagnostics.HealthChecks/HealthCheckConstants.cs @@ -1,14 +1,19 @@ // Copyright (C) Microsoft Corporation. All rights reserved. -namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks.Composables; +namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks; /// /// A series of constants used by health checks. /// -public static class HealthCheckConstants +internal static class HealthCheckConstants { /// /// The local service default host. /// public const string LocalServiceDefaultHost = "localhost"; + + /// + /// The HTTP client logical name. + /// + public const string HttpClientLogicalName = "HttpEndpointHealthCheckHttpClient"; } diff --git a/src/Diagnostics.HealthChecks/Internal/HttpEndpointHealthCheck.cs b/src/Diagnostics.HealthChecks/Internal/HttpEndpointHealthCheck.cs index 22f78e56..ddbb9782 100644 --- a/src/Diagnostics.HealthChecks/Internal/HttpEndpointHealthCheck.cs +++ b/src/Diagnostics.HealthChecks/Internal/HttpEndpointHealthCheck.cs @@ -16,6 +16,7 @@ namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks [Obsolete("The usage of this class is deprecated and will be removed in a later release, please use composable classes in Microsoft.Omex.Extensions.Diagnostics.HealthChecks.Composables namespace to build health checks.")] internal class HttpEndpointHealthCheck : AbstractHealthCheck { + [Obsolete("This property is deprecated and will be removed in a later release.")] public static string HttpClientLogicalName { get; } = "HttpEndpointHealthCheckHttpClient"; private readonly IHttpClientFactory m_httpClientFactory; @@ -34,7 +35,7 @@ protected override async Task CheckHealthInternalAsync(Health { string checkName = context.Registration.Name; - HttpClient httpClient = m_httpClientFactory.CreateClient(HttpClientLogicalName); + HttpClient httpClient = m_httpClientFactory.CreateClient(HealthCheckConstants.HttpClientLogicalName); HttpResponseMessage? response = await httpClient.SendAsync(CloneRequestMessage(Parameters.RequestMessage), token).ConfigureAwait(false); HealthStatus healthStatus = HealthStatus.Unhealthy; diff --git a/src/Diagnostics.HealthChecks/ServiceCollectionExtensions.cs b/src/Diagnostics.HealthChecks/ServiceCollectionExtensions.cs index f8431cdf..002d7be9 100644 --- a/src/Diagnostics.HealthChecks/ServiceCollectionExtensions.cs +++ b/src/Diagnostics.HealthChecks/ServiceCollectionExtensions.cs @@ -21,14 +21,13 @@ public static class ServiceCollectionExtensions /// /// Add dependencies for a publisher /// - [Obsolete("This method is deprecated and will be removed in a later release, please use HealthCheckComposablesExtensions class extension methods to compose health checks.")] private static IServiceCollection AddPublisherDependencies(this IServiceCollection serviceCollection) { // HttpClient registration only needed for HttpEndpointHealthCheck. // It add added here instead of AddHttpEndpointCheck method to avoid creating new configuration each time new health check added. // It would be nice to register this HttpClient configuration once and only if HttpEndpointCheck used. serviceCollection - .AddHttpClient(HttpEndpointHealthCheck.HttpClientLogicalName) + .AddHttpClient(HealthCheckConstants.HttpClientLogicalName) .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { AllowAutoRedirect = false, @@ -43,14 +42,12 @@ private static IServiceCollection AddPublisherDependencies(this IServiceCollecti /// /// Register publisher for processing health check results directly to replicas /// - [Obsolete("This method is deprecated and will be removed in a later release, please use HealthCheckComposablesExtensions class extension methods to compose health checks.")] public static IHealthChecksBuilder AddServiceFabricHealthChecks(this IServiceCollection serviceCollection) => serviceCollection.AddOmexHealthCheckDependencies(); /// /// Register publisher for processing health check results directly to nodes using REST api /// - [Obsolete("This method is deprecated and will be removed in a later release, please use HealthCheckComposablesExtensions class extension methods to compose health checks.")] public static IHealthChecksBuilder AddRestHealthChecksPublisher(this IServiceCollection serviceCollection) => serviceCollection .AddServiceFabricClient() @@ -59,8 +56,6 @@ public static IHealthChecksBuilder AddRestHealthChecksPublisher(this IServiceCol /// /// Register publisher for processing health check results /// - - [Obsolete("This method is deprecated and will be removed in a later release, please use HealthCheckComposablesExtensions class extension methods to compose health checks.")] private static IHealthChecksBuilder AddOmexHealthCheckDependencies(this IServiceCollection serviceCollection) where TStatusSender : class, IHealthStatusSender { diff --git a/tests/Diagnostics.HealthChecks.UnitTests/HttpEndpointHealthCheckTests.cs b/tests/Diagnostics.HealthChecks.UnitTests/HttpEndpointHealthCheckTests.cs index 91de7c0c..54bf04d3 100644 --- a/tests/Diagnostics.HealthChecks.UnitTests/HttpEndpointHealthCheckTests.cs +++ b/tests/Diagnostics.HealthChecks.UnitTests/HttpEndpointHealthCheckTests.cs @@ -137,7 +137,7 @@ public async Task CheckHealthAsync_WithAdditionalCheck_ReturnsOverridenResult() Mock factoryMock = new(); MockClient clientMock = new(response); - factoryMock.Setup(f => f.CreateClient(HttpEndpointHealthCheck.HttpClientLogicalName)) + factoryMock.Setup(f => f.CreateClient(HealthCheckConstants.HttpClientLogicalName)) .Returns(clientMock); HttpEndpointHealthCheck healthCheck = new( From 2b92114c1e2f4c8801b46e504628deadb27bd77d Mon Sep 17 00:00:00 2001 From: Massimiliano D'Acunzo Date: Thu, 17 Aug 2023 11:10:35 +0100 Subject: [PATCH 2/2] Removed property as it was contained in an internal class --- .../Internal/HttpEndpointHealthCheck.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Diagnostics.HealthChecks/Internal/HttpEndpointHealthCheck.cs b/src/Diagnostics.HealthChecks/Internal/HttpEndpointHealthCheck.cs index ddbb9782..f8298aba 100644 --- a/src/Diagnostics.HealthChecks/Internal/HttpEndpointHealthCheck.cs +++ b/src/Diagnostics.HealthChecks/Internal/HttpEndpointHealthCheck.cs @@ -16,9 +16,6 @@ namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks [Obsolete("The usage of this class is deprecated and will be removed in a later release, please use composable classes in Microsoft.Omex.Extensions.Diagnostics.HealthChecks.Composables namespace to build health checks.")] internal class HttpEndpointHealthCheck : AbstractHealthCheck { - [Obsolete("This property is deprecated and will be removed in a later release.")] - public static string HttpClientLogicalName { get; } = "HttpEndpointHealthCheckHttpClient"; - private readonly IHttpClientFactory m_httpClientFactory; public HttpEndpointHealthCheck(