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

Remove health checks #317

Merged
merged 6 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -39,14 +39,6 @@ public AmazonKinesisTransport(IServiceScopeFactory serviceScopeFactory,
clientConfig: TransportOptions.KinesisConfig);
}

/// <inheritdoc/>
public override async Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
_ = await kinesisClient.ListStreamsAsync(cancellationToken);
return true;
}

/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancellationToken)
{
Expand Down
10 changes: 0 additions & 10 deletions src/Tingle.EventBus.Transports.Amazon.Sqs/AmazonSqsTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ public AmazonSqsTransport(IServiceScopeFactory serviceScopeFactory,
clientConfig: TransportOptions.SqsConfig);
}

/// <inheritdoc/>
public override async Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
_ = await snsClient.ListTopicsAsync(cancellationToken);
var prefix = BusOptions.Naming.Scope ?? "";
_ = await sqsClient.ListQueuesAsync(prefix, cancellationToken);
return true;
}

/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ public AzureEventHubsTransport(IServiceScopeFactory serviceScopeFactory,
{
}

/// <inheritdoc/>
public override async Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
// get properties for the producers
var producers = producersCache.Values;
foreach (var proc in producers)
{
cancellationToken.ThrowIfCancellationRequested();

await proc.GetEventHubPropertiesAsync(cancellationToken);
}

return true;
}

/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ public AzureQueueStorageTransport(IServiceScopeFactory serviceScopeFactory,
: new QueueServiceClient(connectionString: (string)cred);
}

/// <inheritdoc/>
public override async Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
/* GetStatisticsAsync fails to work as expected, instead we use GetPropertiesAsync */
await serviceClient.GetPropertiesAsync(cancellationToken);
return true;
}

/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,6 @@ public AzureServiceBusTransport(IServiceScopeFactory serviceScopeFactory,
}
}

/// <inheritdoc/>
public override async Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
Logger.LogDebug("Listing Queues ...");
var queues = managementClient.GetQueuesRuntimePropertiesAsync(cancellationToken).AsPages();
await foreach (var _ in queues) ; // there's nothing to do
var registrations = GetRegistrations();
if (registrations.Any(r => r.EntityKind == EntityKind.Broadcast))
{
Logger.LogDebug("Listing Topics ...");
var topics = managementClient.GetTopicsRuntimePropertiesAsync(cancellationToken);
await foreach (var t in topics)
{
cancellationToken.ThrowIfCancellationRequested();

Logger.LogDebug("Listing Subscriptions for '{TopicName}' topic ...", t.Name);
var subscriptions = managementClient.GetSubscriptionsRuntimePropertiesAsync(t.Name, cancellationToken);
await foreach (var _ in subscriptions) ; // there's nothing to do
}
}
return true;
}

/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancellationToken)
{
Expand Down
8 changes: 0 additions & 8 deletions src/Tingle.EventBus.Transports.InMemory/InMemoryTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ public InMemoryTransport(IServiceScopeFactory serviceScopeFactory,
/// </summary>
internal ConcurrentBag<EventContext> Failed => failed;

/// <inheritdoc/>
public override Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
// InMemory is always healthy
return Task.FromResult(true);
}

/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancellationToken)
{
Expand Down
8 changes: 0 additions & 8 deletions src/Tingle.EventBus.Transports.Kafka/KafkaTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ public KafkaTransport(IHostEnvironment environment,
.Build();
}

/// <inheritdoc/>
public override Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
adminClient.GetMetadata(StandardTimeout);
return Task.FromResult(true);
}

/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancellationToken)
{
Expand Down
13 changes: 0 additions & 13 deletions src/Tingle.EventBus.Transports.RabbitMQ/RabbitMqTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ public RabbitMqTransport(IServiceScopeFactory serviceScopeFactory,
});
}

/// <inheritdoc/>
public override async Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
if (!IsConnected)
{
await TryConnectAsync(cancellationToken);
}

using var channel = connection!.CreateModel();
return channel.IsOpen;
}

/// <inheritdoc/>
public override async Task StartAsync(CancellationToken cancellationToken)
{
Expand Down
11 changes: 0 additions & 11 deletions src/Tingle.EventBus/ConstStrings.cs

This file was deleted.

7 changes: 6 additions & 1 deletion src/Tingle.EventBus/DependencyInjection/EventBusBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -36,7 +37,11 @@ public EventBusBuilder(IServiceCollection services)
Services.AddSingleton<EventBus>();
Services.AddHostedService(p => p.GetRequiredService<EventBus>());
UseDefaultSerializer<DefaultJsonEventSerializer>();
UseDefaultReadinessProvider<DefaultReadinessProvider>();

// Register health/readiness services needed
Services.AddSingleton<DefaultReadinessProvider>();
Services.AddSingleton<IHealthCheckPublisher>(p => p.GetRequiredService<DefaultReadinessProvider>());
Services.AddSingleton<IReadinessProvider>(p => p.GetRequiredService<DefaultReadinessProvider>());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,5 @@ public class EventBusReadinessOptions
/// The default value is 5 minutes. Max value is 15 minutes and minimum is 5 seconds.
/// </summary>
public TimeSpan Timeout { get; set; } = TimeSpan.FromMinutes(5);

/// <summary>
/// Whether to exclude the EventBus health checks when checking for readiness
/// in the default implementation of <see cref="IReadinessProvider"/>.
/// Defaults to <see langword="false"/>.
/// Setting <see langword="false"/> is useful when using multiple transports.
/// </summary>
public bool ExcludeSelf { get; set; } = false;
}
}
29 changes: 0 additions & 29 deletions src/Tingle.EventBus/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,6 @@ public EventBus(IReadinessProvider readinessProvider,
logger = loggerFactory?.CreateLogger(LogCategoryNames.EventBus) ?? throw new ArgumentNullException(nameof(logger));
}

/// <summary>
/// Checks for health of the bus.
/// This function can be used by the Health Checks framework and may throw and exception during execution.
/// </summary>
/// <param name="data">Additional key-value pairs describing the health of the bus.</param>
/// <param name="cancellationToken"></param>
/// <returns>A value indicating if the bus is healthy.</returns>
[Obsolete(ConstStrings.HealthChecksObsolete)]
public async Task<bool> CheckHealthAsync(Dictionary<string, object> data,
CancellationToken cancellationToken = default)
{
var healthy = true;

// Ensure each transport is healthy
foreach (var t in transports)
{
cancellationToken.ThrowIfCancellationRequested();

// Check the health on the transport
var tData = new Dictionary<string, object>();
healthy &= await t.CheckHealthAsync(tData, cancellationToken);

// Combine the data dictionaries into one, keyed by the transport name
data[t.Name] = tData;
}

return healthy;
}

/// <summary>
/// Publish an event.
/// </summary>
Expand Down
42 changes: 0 additions & 42 deletions src/Tingle.EventBus/Health/EventBusHealthCheck.cs

This file was deleted.

24 changes: 0 additions & 24 deletions src/Tingle.EventBus/Health/IHealthChecksBuilderExtensions.cs

This file was deleted.

Loading