Skip to content

Commit

Permalink
Use abstract AzureStorageHealthCheck to test for CMK health (#3155)
Browse files Browse the repository at this point in the history
* upgrade shared components

* revert bad change from merge
  • Loading branch information
jnlycklama authored Oct 30, 2023
1 parent 3a808cc commit b8caefd
Showing 1 changed file with 3 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using EnsureThat;
Expand All @@ -15,39 +14,23 @@

namespace Microsoft.Health.Dicom.Functions.Client.HealthChecks;

internal sealed class DurableTaskHealthCheck : IHealthCheck
internal sealed class DurableTaskHealthCheck : AzureStorageHealthCheck
{
private const string DegradedDescription = "The health of the task hub has degraded.";

private readonly ITaskHubClient _client;
private readonly ValueCache<CustomerKeyHealth> _customerKeyHealthCache;
private readonly ILogger<DurableTaskHealthCheck> _logger;

public DurableTaskHealthCheck(
ITaskHubClient client,
ValueCache<CustomerKeyHealth> customerKeyHealthCache,
ILogger<DurableTaskHealthCheck> logger)
: base(customerKeyHealthCache, logger)
{
_client = EnsureArg.IsNotNull(client, nameof(client));
_customerKeyHealthCache = EnsureArg.IsNotNull(customerKeyHealthCache, nameof(customerKeyHealthCache));
_logger = EnsureArg.IsNotNull(logger, nameof(logger));
}

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
public override async Task<HealthCheckResult> CheckAzureStorageHealthAsync(CancellationToken cancellationToken)
{
EnsureArg.IsNotNull(context, nameof(context));

CustomerKeyHealth cmkStatus = await _customerKeyHealthCache.GetAsync(cancellationToken).ConfigureAwait(false);
if (!cmkStatus.IsHealthy)
{
// if the customer-managed key is inaccessible, the task hub will also be inaccessible
return new HealthCheckResult(
HealthStatus.Degraded,
DegradedDescription,
cmkStatus.Exception,
new Dictionary<string, object> { { "Reason", cmkStatus.Reason } });
}

ITaskHub taskHub = await _client.GetTaskHubAsync(cancellationToken).ConfigureAwait(false);
if (taskHub == null)
return HealthCheckResult.Unhealthy("Task hub not found.");
Expand Down

0 comments on commit b8caefd

Please sign in to comment.