Skip to content

Commit

Permalink
Merge pull request #599 from microsoft/mdacunzo/feature/solve-health-…
Browse files Browse the repository at this point in the history
…checks-obsolete

Reduced the number of obsoletion in the Diagnostics project
  • Loading branch information
K-Cully authored Aug 17, 2023
2 parents d30366a + 2b92114 commit 0cb32c7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Copyright (C) Microsoft Corporation. All rights reserved.

namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks.Composables;
namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks;

/// <summary>
/// A series of constants used by health checks.
/// </summary>
public static class HealthCheckConstants
internal static class HealthCheckConstants
{
/// <summary>
/// The local service default host.
/// </summary>
public const string LocalServiceDefaultHost = "localhost";

/// <summary>
/// The HTTP client logical name.
/// </summary>
public const string HttpClientLogicalName = "HttpEndpointHealthCheckHttpClient";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +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<HttpHealthCheckParameters>
{
public static string HttpClientLogicalName { get; } = "HttpEndpointHealthCheckHttpClient";

private readonly IHttpClientFactory m_httpClientFactory;

public HttpEndpointHealthCheck(
Expand All @@ -34,7 +32,7 @@ protected override async Task<HealthCheckResult> 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;
Expand Down
7 changes: 1 addition & 6 deletions src/Diagnostics.HealthChecks/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ public static class ServiceCollectionExtensions
/// <summary>
/// Add dependencies for a publisher
/// </summary>
[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,
Expand All @@ -43,14 +42,12 @@ private static IServiceCollection AddPublisherDependencies(this IServiceCollecti
/// <summary>
/// Register publisher for processing health check results directly to replicas
/// </summary>
[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<ServiceContextHealthStatusSender>();

/// <summary>
/// Register publisher for processing health check results directly to nodes using REST api
/// </summary>
[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()
Expand All @@ -59,8 +56,6 @@ public static IHealthChecksBuilder AddRestHealthChecksPublisher(this IServiceCol
/// <summary>
/// Register publisher for processing health check results
/// </summary>

[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<TStatusSender>(this IServiceCollection serviceCollection)
where TStatusSender : class, IHealthStatusSender
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public async Task CheckHealthAsync_WithAdditionalCheck_ReturnsOverridenResult()
Mock<IHttpClientFactory> 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(
Expand Down

0 comments on commit 0cb32c7

Please sign in to comment.