Contains HealthChecks for CockroachDb, based on the nuget package `Npgsql`.
$ dotnet add package NetEvolve.HealthChecks.CockroachDbThis package provides a health check for CockroachDb databases, based on the Npgsql package. The main purpose is to check if the CockroachDb database is available and if the database is online.
:bulb: This package is available for .NET 8.0 and later.
To use this package, you need to add the package to your project. You can do this by using the NuGet package manager or by using the dotnet CLI.
dotnet add package NetEvolve.HealthChecks.CockroachDb
The health check is a liveness check. It checks if the CockroachDb database is available and if the database is online.
If the query needs longer than the configured timeout, the health check will return Degraded.
If the query fails, for whatever reason, the health check will return Unhealthy.
After adding the package, you need to import the namespace NetEvolve.HealthChecks.CockroachDb and add the health check to the service collection.
using NetEvolve.HealthChecks.CockroachDb;
Therefore, you can use two different approaches. In both approaches you have to provide a name for the health check.
name: The name of the health check. The name is used to identify the configuration object. It is required and must be unique within the application.options: The configuration options for the health check. If you don't provide any options, the health check will use the configuration based approach.tags: The tags for the health check. The tags cockroachdb and database are always used as default and combined with the user input. You can provide additional tags to group or filter the health checks.The first one is to use the configuration based approach. This approach is recommended if you have multiple CockroachDb instances to check.
var builder = services.AddHealthChecks();
builder.AddCockroachDb("<name>");The configuration looks like this:
{
..., // other configuration
"HealthChecks": {
"CockroachDb": {
"<name>": {
"ConnectionString": "<connection string>",
"Timeout": "<timeout>" // optional, default is 100 milliseconds
}
}
}
}The second approach is to use the builder based approach. This approach is recommended if you only have one CockroachDb instance to check or dynamic programmatic values.
var builder = services.AddHealthChecks();
builder.AddCockroachDb("<name>", options =>
{
options.ConnectionString = "<connection string>";
options.Timeout = "<timeout>"; // optional, default is 100 milliseconds
});var builder = services.AddHealthChecks();
builder.AddCockroachDb("<name>", options => ..., "cockroachdb", "database");This project is licensed under the MIT License - see the LICENSE file for details.