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

Add CassandraDb HealthCheck support #2174

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
37c579e
Add CassandraDb HealthCheck support
djesusnet Mar 9, 2024
9565dc4
Update healthchecks_cassandradb_ci.yaml
djesusnet Mar 9, 2024
5661506
Update ymal
djesusnet Mar 9, 2024
0dc5f14
Update CassandraDbHealthCheckTests
djesusnet Mar 9, 2024
17ae1a8
update CassandraDbHealthCheckTests
djesusnet Mar 9, 2024
2d161ff
updates yml and CassandraDbHealthCheckTests
djesusnet Mar 9, 2024
02797c9
Update unit tests
djesusnet Mar 9, 2024
9a2abdc
Update yml
djesusnet Mar 9, 2024
1e7b60a
Update HealthChecks CassandraDb CIi.yml
djesusnet Mar 9, 2024
50a4995
Update Ci.yml
djesusnet Mar 9, 2024
d92a380
Updates unit tests
djesusnet Mar 9, 2024
2dcd466
update dockercompose
djesusnet Mar 9, 2024
49261bb
Update DockerCompose
djesusnet Mar 9, 2024
4ee4e47
update docker-compose
djesusnet Mar 9, 2024
5f23cb0
Update CI
djesusnet Mar 9, 2024
96d5f4a
Update CI
djesusnet Mar 9, 2024
68a11d9
update CI
djesusnet Mar 9, 2024
cefe913
update ci
djesusnet Mar 9, 2024
9c627ce
update CI
djesusnet Mar 9, 2024
88be2d8
Update ci
djesusnet Mar 9, 2024
eba5c54
Ajuste CI
djesusnet Mar 9, 2024
db136c5
update Ci
djesusnet Mar 9, 2024
1917355
Ajuste no CI
djesusnet Mar 9, 2024
5f595a3
Ajuste Ci
djesusnet Mar 9, 2024
67fac24
update CI - CassandraDb
djesusnet Mar 9, 2024
6f776ef
Update unit test
djesusnet Mar 9, 2024
488cf5e
update CI
djesusnet Mar 9, 2024
281575a
update Ci
djesusnet Mar 9, 2024
025ad27
Ajuste no CI
djesusnet Mar 9, 2024
3a665da
Update CassandraDbHealthCheck
djesusnet Mar 9, 2024
338713e
Update tests
djesusnet Mar 9, 2024
2365d8a
Insert txt
djesusnet Mar 9, 2024
b7cdd1d
Insert txt
djesusnet Mar 9, 2024
57a8bec
update HealthChecks SQL Server DB CI
djesusnet Mar 9, 2024
cd8d8b2
Update and rollback
djesusnet Mar 9, 2024
e7bff20
Update Readme.md
djesusnet Mar 12, 2024
1be70b8
Merge branch 'master' into master
djesusnet Jun 7, 2024
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
2 changes: 2 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ flags:
carryforward: true
CosmosDb:
carryforward: true
CassandraDb:
carryforward: true
DocumentDb:
carryforward: true
DynamoDb:
Expand Down
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ consul:
cosmosdb:
- src/HealthChecks.CosmosDb/**/*

cassandradb:
- src/HealthChecks.CassandraDb/**/*

dapr:
- src/HealthChecks.Dapr/**/*

Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/healthchecks_cassandradb_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: HealthChecks CassandraDb CD

on:
push:
tags:
- release-cassandradb-*
- release-all-*

jobs:
build:
uses: ./.github/workflows/reusable_cd_workflow.yml
secrets: inherit
with:
BUILD_CONFIG: Release
PROJECT_PATH: ./src/HealthChecks.CassandraDb/HealthChecks.CassandraDb.csproj
PACKAGE_NAME: AspNetCore.HealthChecks.CassandraDb
17 changes: 17 additions & 0 deletions .github/workflows/healthchecks_cassandradb_cd_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: HealthChecks CassandraDb Preview CD

on:
push:
tags:
- preview-cassandradb-*
- preview-all-*

jobs:
build:
uses: ./.github/workflows/reusable_cd_preview_workflow.yml
secrets: inherit
with:
BUILD_CONFIG: Release
VERSION_SUFFIX_PREFIX: rc1
PROJECT_PATH: ./src/HealthChecks.CassandraDb/HealthChecks.CassandraDb.csproj
PACKAGE_NAME: AspNetCore.HealthChecks.CassandraDb
93 changes: 93 additions & 0 deletions .github/workflows/healthchecks_cassandradb_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: HealthChecks CassandraDb CI

on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- src/HealthChecks.CassandraDb/**
- test/HealthChecks.CassandraDb.Tests/**
- test/_SHARED/**
- .github/workflows/healthchecks_cassandradb_ci.yml
- Directory.Build.props
- Directory.Build.targets
tags-ignore:
- release-*
- preview-*

pull_request:
branches: [ master ]
paths:
- src/HealthChecks.CassandraDb/**
- test/HealthChecks.CassandraDb.Tests/**
- test/_SHARED/**
- .github/workflows/healthchecks_cassandradb_ci.yml
- Directory.Build.props
- Directory.Build.targets

jobs:
build:
runs-on: ubuntu-latest
services:
CassandraDb:
image: cassandra:latest
ports:
- 9042:9042
options: --health-cmd="cqlsh -e 'DESCRIBE KEYSPACES'" --health-interval=10s --health-timeout=5s --health-retries=6

steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x

- name: Cache NuGet Packages
uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/.*csproj') }}
restore-keys: ${{ runner.os }}-nuget-

- name: Restore
run: |
dotnet restore ./src/HealthChecks.CassandraDb/HealthChecks.CassandraDb.csproj &&
dotnet restore ./test/HealthChecks.CassandraDb.Tests/HealthChecks.CassandraDb.Tests.csproj

- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.CassandraDb/HealthChecks.CassandraDb.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.CassandraDb.Tests/HealthChecks.CassandraDb.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)

- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.CassandraDb/HealthChecks.CassandraDb.csproj &&
dotnet build --no-restore ./test/HealthChecks.CassandraDb.Tests/HealthChecks.CassandraDb.Tests.csproj

- name: Wait for Cassandra to be ready
run: |
until docker run --network host -e CQLSH_HOST=localhost -e CQLSH_PORT=9042 cassandra:latest cqlsh -e "SELECT now() FROM system.local;"; do
echo "Waiting for Cassandra..."
sleep 10
done

- name: Test
run: >
dotnet test
./test/HealthChecks.CassandraDb.Tests/HealthChecks.CassandraDb.Tests.csproj
--no-restore
--no-build
--collect "XPlat Code Coverage"
--results-directory .coverage
--
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover

- name: Upload Coverage
uses: codecov/codecov-action@v3
with:
flags: CassandraDb
directory: .coverage
14 changes: 14 additions & 0 deletions AspNetCore.Diagnostics.HealthChecks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Azure.Messagin
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.AzureServiceBus.Tests", "test\HealthChecks.AzureServiceBus.Tests\HealthChecks.AzureServiceBus.Tests.csproj", "{3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks.CassandraDb", "src\HealthChecks.CassandraDb\HealthChecks.CassandraDb.csproj", "{BCBC3C44-A140-452C-9C18-C670C2F7FCEF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks.CassandraDb.Tests", "test\HealthChecks.CassandraDb.Tests\HealthChecks.CassandraDb.Tests.csproj", "{3FDC5E82-4AFB-4C79-A253-2C704DCAC400}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -856,6 +860,14 @@ Global
{3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}.Release|Any CPU.Build.0 = Release|Any CPU
{BCBC3C44-A140-452C-9C18-C670C2F7FCEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCBC3C44-A140-452C-9C18-C670C2F7FCEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCBC3C44-A140-452C-9C18-C670C2F7FCEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCBC3C44-A140-452C-9C18-C670C2F7FCEF}.Release|Any CPU.Build.0 = Release|Any CPU
{3FDC5E82-4AFB-4C79-A253-2C704DCAC400}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FDC5E82-4AFB-4C79-A253-2C704DCAC400}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FDC5E82-4AFB-4C79-A253-2C704DCAC400}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FDC5E82-4AFB-4C79-A253-2C704DCAC400}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -997,6 +1009,8 @@ Global
{2C02BEDF-FFFA-4747-920A-A1ED6CFFC21A} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE}
{09160C0F-BB5E-4DF2-AF44-E859E8EDE6BD} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE}
{3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE}
{BCBC3C44-A140-452C-9C18-C670C2F7FCEF} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4}
{3FDC5E82-4AFB-4C79-A253-2C704DCAC400} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2B8C62A1-11B6-469F-874C-A02443256568}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ HealthChecks packages include health checks for:
| Azure Service Bus | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.AzureServiceBus)](https://www.nuget.org/packages/AspNetCore.HealthChecks.AzureServiceBus) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.AzureServiceBus)](https://www.nuget.org/packages/AspNetCore.HealthChecks.AzureServiceBus) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/azure)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/azure) | Queue and Topics |
| Consul | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Consul)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Consul) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.Consul)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Consul) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/consul)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/consul)
| CosmosDb | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.CosmosDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.CosmosDb) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.CosmosDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.CosmosDb) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/cosmosdb)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/cosmosdb) | CosmosDb and Azure Table
| CassandraDb | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.CassandraDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.CassandraDb) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.CassandraDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.CassandraDb) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/cassandradb)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/cassandradb)
| Dapr | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Dapr)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Dapr) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.Dapr)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Dapr) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/dapr)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/dapr)
| Azure DocumentDb | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.DocumentDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.DocumentDb) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.DocumentDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.DocumentDb) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/documentdb)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/documentdb)
| Amazon DynamoDb | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.DynamoDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.DynamoDb) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.DynamoDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.DynamoDb) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/dynamodb)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/dynamodb)
Expand Down Expand Up @@ -143,6 +144,7 @@ Install-Package AspNetCore.HealthChecks.AzureServiceBus
Install-Package AspNetCore.HealthChecks.AzureStorage
Install-Package AspNetCore.HealthChecks.Consul
Install-Package AspNetCore.HealthChecks.CosmosDb
Install-Package AspNetCore.HealthChecks.CassandraDb
Install-Package AspNetCore.HealthChecks.Dapr
Install-Package AspNetCore.HealthChecks.DocumentDb
Install-Package AspNetCore.HealthChecks.DynamoDB
Expand Down
3 changes: 2 additions & 1 deletion build/versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<HealthCheckCloudFirestore>8.0.1</HealthCheckCloudFirestore>
<HealthCheckConsul>8.0.1</HealthCheckConsul>
<HealthCheckCosmosDb>8.0.1</HealthCheckCosmosDb>
<HealthCheckCassandraDb>8.0.1</HealthCheckCassandraDb>
<HealthCheckDapr>8.0.1</HealthCheckDapr>
<HealthCheckDocumentDb>8.0.1</HealthCheckDocumentDb>
<HealthCheckDynamoDb>8.0.1</HealthCheckDynamoDb>
Expand Down Expand Up @@ -71,4 +72,4 @@
<HealthCheckKeyVaultSecrets>8.0.1</HealthCheckKeyVaultSecrets>
</PropertyGroup>

</Project>
</Project>
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ services:
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=Password12!
cassandra:
image: cassandra:latest
ports:
- "9042:9042"
volumes:
- ./build/docker-services/cassandra:/var/lib/cassandra
environment:
- CASSANDRA_CLUSTER_NAME=cloudinfra
redis:
image: redis:alpine
ports:
Expand Down
43 changes: 43 additions & 0 deletions src/HealthChecks.CassandraDb/CassandraDbHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Cassandra;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthChecks.CassandraDb;

public class CassandraDbHealthCheck : IHealthCheck
{
private readonly CassandraDbOptions _options;

public CassandraDbHealthCheck(CassandraDbOptions options)
{
_options = Guard.ThrowIfNull(options);

if (_options.ContactPoint is null && _options.Keyspace is null)
{
throw new ArgumentException("A connection or connection string must be set!", nameof(options));
}
}

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
var builder = Cluster.Builder().AddContactPoint(_options.ContactPoint);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current approach, we would build a new instance every time the health check would be invoked. Which I expect would be bad for performance and could even lead to some resource leaks (nothing is getting disposed here).

We have changed many of our health checks similar to what I described in #2040: for all the client instances that are thread-safe and should be used as singleton, we don't create our own instances, but expect it to be resolved from the DI (so the user registers a singleton and we just resolve).

I've done some quick web search, but have failed to find dependency injection best practices for working with the C# client of CassandarDb.

Should we just expect the users to inject the cluster into the DI and solve it?

For example this is what we do for MongoDB:

We allow the users to specify a Func<IServiceProvider, IMongoClient> factory:

when it's not specified, we just try to resolve it from the DI container:

IMongoClient client = clientFactory?.Invoke(sp) ?? sp.GetService<MongoClient>() ?? sp.GetRequiredService<IMongoClient>();

_options.ConfigureClusterBuilder?.Invoke(builder);

var cluster = builder.Build();

ISession session = await cluster.ConnectAsync(_options.Keyspace).ConfigureAwait(false);


RowSet rows = await session.ExecuteAsync(new SimpleStatement(_options.Query)).ConfigureAwait(false);
var result = rows.FirstOrDefault();

return HealthCheckResult.Healthy();
}
catch (Exception ex)
{

return HealthCheckResult.Unhealthy(ex.Message);
}
}
}
14 changes: 14 additions & 0 deletions src/HealthChecks.CassandraDb/CassandraDbOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Cassandra;

namespace HealthChecks.CassandraDb;

/// <summary>
/// Options for CassandraHealthCheck.
/// </summary>
public class CassandraDbOptions
{
public string ContactPoint { get; set; } = null!;
public string Keyspace { get; set; } = null!;
public string Query { get; set; } = "SELECT now() FROM system.local;";
public Action<Builder> ConfigureClusterBuilder { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Cassandra;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthChecks.CassandraDb.DependencyInjection;

/// <summary>
/// Extension methods to configure <see cref="CassandraDbHealthCheck"/>.
/// </summary>
public static class CassandraDbHealthCheckBuilderExtensions
{
private const string NAME = "cassandra";

/// <summary>
/// Add a health check for Cassandra databases.
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="contactPoint">The Cassandra contact point to be used.</param>
/// <param name="keyspace">The Cassandra keyspace to be used.</param>
/// <param name="query">The query to be executed. Default is 'SELECT now() FROM system.local;'.</param>
/// <param name="configureClusterBuilder">An action to allow additional Cassandra specific configuration. It cannot be null.</param>
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'cassandra' will be used for the name.</param>
/// <param name="failureStatus">
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
/// </param>
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>
/// <returns>The specified <paramref name="builder"/>.</returns>
public static IHealthChecksBuilder AddCassandra(
this IHealthChecksBuilder builder,
string contactPoint,
string keyspace,
string query = "SELECT now() FROM system.local;",
Action<Builder>? configureClusterBuilder = null, // Note: The caller must ensure this is not null
string? name = default,
HealthStatus? failureStatus = default,
IEnumerable<string>? tags = default,
TimeSpan? timeout = default)
{
// Define a default configuration action if none is provided
var defaultConfigurationAction = new Action<Builder>(b =>
// Default minimal configuration
b.AddContactPoint(contactPoint).Build());

var options = new CassandraDbOptions
{
ContactPoint = contactPoint,
Keyspace = keyspace,
Query = query,
ConfigureClusterBuilder = configureClusterBuilder ?? defaultConfigurationAction // Use provided configuration or default
};

return builder.AddCassandra(options, name, failureStatus, tags, timeout);
}

/// <summary>
/// Add a health check for Cassandra databases using <see cref="CassandraDbOptions"/>.
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="options">Options for the Cassandra health check.</param>
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'cassandra' will be used for the name.</param>
/// <param name="failureStatus">
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
/// </param>
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>
/// <returns>The specified <paramref name="builder"/>.</returns>
public static IHealthChecksBuilder AddCassandra(
this IHealthChecksBuilder builder,
CassandraDbOptions options,
string? name = default,
HealthStatus? failureStatus = default,
IEnumerable<string>? tags = default,
TimeSpan? timeout = default)
{
// Ensure options.ConfigureClusterBuilder is never null
if (options.ConfigureClusterBuilder == null)
{
throw new ArgumentNullException(nameof(options.ConfigureClusterBuilder), "ConfigureClusterBuilder action cannot be null.");
}

return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => new CassandraDbHealthCheck(options),
failureStatus,
tags,
timeout));
}
}
12 changes: 12 additions & 0 deletions src/HealthChecks.CassandraDb/HealthChecks.CassandraDb.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CassandraCSharpDriver" Version="3.20.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/HealthChecks.UI/assets/1ae4e3706fe3f478fcc1.woff2

Large diffs are not rendered by default.

Loading