-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split AzureServiceBus into dedicated nuget packages
- Loading branch information
1 parent
67b8b48
commit 964ad22
Showing
23 changed files
with
309 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<PackageTags>$(PackageTags);Azure;EventHub</PackageTags> | ||
<Description>HealthChecks.Azure.Messaging.EventHubs is the health check package for Azure EventHub.</Description> | ||
<VersionPrefix>$(HealthCheckAzureServiceBus)</VersionPrefix> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="../ClientCache.cs" Link="ClientCache.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.9.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="7.0.9" /> | ||
</ItemGroup> | ||
|
||
</Project> |
File renamed without changes.
114 changes: 57 additions & 57 deletions
114
...iceBus/AzureServiceBusQueueHealthCheck.cs → ...iceBus/AzureServiceBusQueueHealthCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
using HealthChecks.AzureServiceBus.Configuration; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace HealthChecks.AzureServiceBus; | ||
|
||
public class AzureServiceBusQueueHealthCheck : AzureServiceBusHealthCheck<AzureServiceBusQueueHealthCheckOptions>, IHealthCheck | ||
{ | ||
private readonly string _queueKey; | ||
|
||
public AzureServiceBusQueueHealthCheck(AzureServiceBusQueueHealthCheckOptions options, ServiceBusClientProvider clientProvider) | ||
: base(options, clientProvider) | ||
{ | ||
Guard.ThrowIfNull(options.QueueName, true); | ||
|
||
_queueKey = $"{nameof(AzureServiceBusQueueHealthCheck)}_{ConnectionKey}_{Options.QueueName}"; | ||
} | ||
|
||
public AzureServiceBusQueueHealthCheck(AzureServiceBusQueueHealthCheckOptions options) | ||
: this(options, new ServiceBusClientProvider()) | ||
{ } | ||
|
||
/// <inheritdoc /> | ||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
if (Options.UsePeekMode) | ||
await CheckWithReceiver().ConfigureAwait(false); | ||
else | ||
await CheckWithManagement().ConfigureAwait(false); | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); | ||
} | ||
|
||
async Task CheckWithReceiver() | ||
{ | ||
var client = await ClientCache.GetOrAddAsyncDisposableAsync(ConnectionKey, _ => CreateClient()).ConfigureAwait(false); | ||
var receiver = await ClientCache.GetOrAddAsyncDisposableAsync( | ||
_queueKey, | ||
_ => client.CreateReceiver(Options.QueueName)) | ||
.ConfigureAwait(false); | ||
|
||
await receiver.PeekMessageAsync(cancellationToken: cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
Task CheckWithManagement() | ||
{ | ||
var managementClient = ClientCache.GetOrAdd(ConnectionKey, _ => CreateManagementClient()); | ||
|
||
return managementClient.GetQueueRuntimePropertiesAsync(Options.QueueName, cancellationToken); | ||
} | ||
} | ||
} | ||
using HealthChecks.AzureServiceBus.Configuration; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace HealthChecks.AzureServiceBus; | ||
|
||
public class AzureServiceBusQueueHealthCheck : AzureServiceBusHealthCheck<AzureServiceBusQueueHealthCheckOptions>, IHealthCheck | ||
{ | ||
private readonly string _queueKey; | ||
|
||
public AzureServiceBusQueueHealthCheck(AzureServiceBusQueueHealthCheckOptions options, ServiceBusClientProvider clientProvider) | ||
: base(options, clientProvider) | ||
{ | ||
Guard.ThrowIfNull(options.QueueName, true); | ||
|
||
_queueKey = $"{nameof(AzureServiceBusQueueHealthCheck)}_{ConnectionKey}_{Options.QueueName}"; | ||
} | ||
|
||
public AzureServiceBusQueueHealthCheck(AzureServiceBusQueueHealthCheckOptions options) | ||
: this(options, new ServiceBusClientProvider()) | ||
{ } | ||
|
||
/// <inheritdoc /> | ||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
if (Options.UsePeekMode) | ||
await CheckWithReceiver().ConfigureAwait(false); | ||
else | ||
await CheckWithManagement().ConfigureAwait(false); | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); | ||
} | ||
|
||
async Task CheckWithReceiver() | ||
{ | ||
var client = await ClientCache.GetOrAddAsyncDisposableAsync(ConnectionKey, _ => CreateClient()).ConfigureAwait(false); | ||
var receiver = await ClientCache.GetOrAddAsyncDisposableAsync( | ||
_queueKey, | ||
_ => client.CreateReceiver(Options.QueueName)) | ||
.ConfigureAwait(false); | ||
|
||
await receiver.PeekMessageAsync(cancellationToken: cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
Task CheckWithManagement() | ||
{ | ||
var managementClient = ClientCache.GetOrAdd(ConnectionKey, _ => CreateManagementClient()); | ||
|
||
return managementClient.GetQueueRuntimePropertiesAsync(Options.QueueName, cancellationToken); | ||
} | ||
} | ||
} |
166 changes: 83 additions & 83 deletions
166
...sQueueMessageCountThresholdHealthCheck.cs → ...sQueueMessageCountThresholdHealthCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,83 @@ | ||
using HealthChecks.AzureServiceBus.Configuration; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace HealthChecks.AzureServiceBus; | ||
|
||
public class AzureServiceBusQueueMessageCountThresholdHealthCheck : AzureServiceBusHealthCheck<AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions>, IHealthCheck | ||
{ | ||
private readonly string _queueName; | ||
private readonly AzureServiceBusQueueMessagesCountThreshold? _activeMessagesThreshold; | ||
private readonly AzureServiceBusQueueMessagesCountThreshold? _deadLetterMessagesThreshold; | ||
|
||
public AzureServiceBusQueueMessageCountThresholdHealthCheck(AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions options, ServiceBusClientProvider clientProvider) | ||
: base(options, clientProvider) | ||
{ | ||
_queueName = Guard.ThrowIfNull(options.QueueName); | ||
_activeMessagesThreshold = options.ActiveMessages; | ||
_deadLetterMessagesThreshold = options.DeadLetterMessages; | ||
} | ||
|
||
public AzureServiceBusQueueMessageCountThresholdHealthCheck(AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions options) | ||
: this(options, new ServiceBusClientProvider()) | ||
{ } | ||
|
||
/// <inheritdoc /> | ||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
var managementClient = ClientCache.GetOrAdd(ConnectionKey, _ => CreateManagementClient()); | ||
|
||
var properties = await managementClient.GetQueueRuntimePropertiesAsync(_queueName, cancellationToken).ConfigureAwait(false); | ||
|
||
var activeQueueHealthStatus = CheckHealthStatus( | ||
properties.Value.ActiveMessageCount, | ||
_activeMessagesThreshold, | ||
"queue"); | ||
|
||
if (activeQueueHealthStatus.Status != HealthStatus.Healthy) | ||
{ | ||
return activeQueueHealthStatus; | ||
} | ||
|
||
var deadLetterQueueHealthStatus = CheckHealthStatus( | ||
properties.Value.DeadLetterMessageCount, | ||
_deadLetterMessagesThreshold, | ||
"dead letter queue"); | ||
|
||
if (deadLetterQueueHealthStatus.Status != HealthStatus.Healthy) | ||
{ | ||
return deadLetterQueueHealthStatus; | ||
} | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); | ||
} | ||
} | ||
|
||
private HealthCheckResult CheckHealthStatus( | ||
long messagesCount, | ||
AzureServiceBusQueueMessagesCountThreshold? threshold, | ||
string queueType) | ||
{ | ||
if (threshold is null) | ||
{ | ||
return HealthCheckResult.Healthy(); | ||
} | ||
|
||
if (messagesCount >= threshold.Value.UnhealthyThreshold) | ||
{ | ||
return HealthCheckResult.Unhealthy($"Message in {queueType} {_queueName} exceeded the amount of messages allowed for the unhealthy threshold {threshold.Value.UnhealthyThreshold}/{messagesCount}"); | ||
} | ||
|
||
if (messagesCount >= threshold.Value.DegradedThreshold) | ||
{ | ||
return HealthCheckResult.Degraded($"Message in {queueType} {_queueName} exceeded the amount of messages allowed for the degraded threshold {threshold.Value.DegradedThreshold}/{messagesCount}"); | ||
} | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
} | ||
using HealthChecks.AzureServiceBus.Configuration; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace HealthChecks.AzureServiceBus; | ||
|
||
public class AzureServiceBusQueueMessageCountThresholdHealthCheck : AzureServiceBusHealthCheck<AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions>, IHealthCheck | ||
{ | ||
private readonly string _queueName; | ||
private readonly AzureServiceBusQueueMessagesCountThreshold? _activeMessagesThreshold; | ||
private readonly AzureServiceBusQueueMessagesCountThreshold? _deadLetterMessagesThreshold; | ||
|
||
public AzureServiceBusQueueMessageCountThresholdHealthCheck(AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions options, ServiceBusClientProvider clientProvider) | ||
: base(options, clientProvider) | ||
{ | ||
_queueName = Guard.ThrowIfNull(options.QueueName); | ||
_activeMessagesThreshold = options.ActiveMessages; | ||
_deadLetterMessagesThreshold = options.DeadLetterMessages; | ||
} | ||
|
||
public AzureServiceBusQueueMessageCountThresholdHealthCheck(AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions options) | ||
: this(options, new ServiceBusClientProvider()) | ||
{ } | ||
|
||
/// <inheritdoc /> | ||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
var managementClient = ClientCache.GetOrAdd(ConnectionKey, _ => CreateManagementClient()); | ||
|
||
var properties = await managementClient.GetQueueRuntimePropertiesAsync(_queueName, cancellationToken).ConfigureAwait(false); | ||
|
||
var activeQueueHealthStatus = CheckHealthStatus( | ||
properties.Value.ActiveMessageCount, | ||
_activeMessagesThreshold, | ||
"queue"); | ||
|
||
if (activeQueueHealthStatus.Status != HealthStatus.Healthy) | ||
{ | ||
return activeQueueHealthStatus; | ||
} | ||
|
||
var deadLetterQueueHealthStatus = CheckHealthStatus( | ||
properties.Value.DeadLetterMessageCount, | ||
_deadLetterMessagesThreshold, | ||
"dead letter queue"); | ||
|
||
if (deadLetterQueueHealthStatus.Status != HealthStatus.Healthy) | ||
{ | ||
return deadLetterQueueHealthStatus; | ||
} | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); | ||
} | ||
} | ||
|
||
private HealthCheckResult CheckHealthStatus( | ||
long messagesCount, | ||
AzureServiceBusQueueMessagesCountThreshold? threshold, | ||
string queueType) | ||
{ | ||
if (threshold is null) | ||
{ | ||
return HealthCheckResult.Healthy(); | ||
} | ||
|
||
if (messagesCount >= threshold.Value.UnhealthyThreshold) | ||
{ | ||
return HealthCheckResult.Unhealthy($"Message in {queueType} {_queueName} exceeded the amount of messages allowed for the unhealthy threshold {threshold.Value.UnhealthyThreshold}/{messagesCount}"); | ||
} | ||
|
||
if (messagesCount >= threshold.Value.DegradedThreshold) | ||
{ | ||
return HealthCheckResult.Degraded($"Message in {queueType} {_queueName} exceeded the amount of messages allowed for the degraded threshold {threshold.Value.DegradedThreshold}/{messagesCount}"); | ||
} | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.