dotnet-cqrs/Svrnty.CQRS.Events.Abstractions/Streaming/IStreamHealthCheck.cs

81 lines
3.2 KiB
C#

using System;
using Svrnty.CQRS.Events.Abstractions.Models;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Svrnty.CQRS.Events.Abstractions.Streaming;
/// <summary>
/// Performs health checks on event streams and subscriptions.
/// </summary>
public interface IStreamHealthCheck
{
/// <summary>
/// Checks the health of a specific stream.
/// </summary>
/// <param name="streamName">Name of the stream to check.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Health check result for the stream.</returns>
Task<HealthCheckResult> CheckStreamHealthAsync(string streamName, CancellationToken cancellationToken = default);
/// <summary>
/// Checks the health of a specific subscription.
/// </summary>
/// <param name="streamName">Name of the stream.</param>
/// <param name="subscriptionName">Name of the subscription to check.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Health check result for the subscription.</returns>
Task<HealthCheckResult> CheckSubscriptionHealthAsync(string streamName, string subscriptionName, CancellationToken cancellationToken = default);
/// <summary>
/// Checks the health of all configured streams.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Dictionary of stream names to health check results.</returns>
Task<IReadOnlyDictionary<string, HealthCheckResult>> CheckAllStreamsAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Checks the health of all subscriptions across all streams.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Dictionary of subscription keys (streamName:subscriptionName) to health check results.</returns>
Task<IReadOnlyDictionary<string, HealthCheckResult>> CheckAllSubscriptionsAsync(CancellationToken cancellationToken = default);
}
/// <summary>
/// Configuration for stream health checks.
/// </summary>
public sealed class StreamHealthCheckOptions
{
/// <summary>
/// Maximum consumer lag (in events) before marking as degraded.
/// Default: 1000 events.
/// </summary>
public long DegradedConsumerLagThreshold { get; set; } = 1000;
/// <summary>
/// Maximum consumer lag (in events) before marking as unhealthy.
/// Default: 10000 events.
/// </summary>
public long UnhealthyConsumerLagThreshold { get; set; } = 10000;
/// <summary>
/// Maximum time without progress before marking consumer as stalled (degraded).
/// Default: 5 minutes.
/// </summary>
public TimeSpan DegradedStalledThreshold { get; set; } = TimeSpan.FromMinutes(5);
/// <summary>
/// Maximum time without progress before marking consumer as stalled (unhealthy).
/// Default: 15 minutes.
/// </summary>
public TimeSpan UnhealthyStalledThreshold { get; set; } = TimeSpan.FromMinutes(15);
/// <summary>
/// Timeout for health check operations.
/// Default: 5 seconds.
/// </summary>
public TimeSpan HealthCheckTimeout { get; set; } = TimeSpan.FromSeconds(5);
}