Voyager.HealthEndpoint 1.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Voyager.HealthEndpoint --version 1.2.1                
NuGet\Install-Package Voyager.HealthEndpoint -Version 1.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Voyager.HealthEndpoint" Version="1.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Voyager.HealthEndpoint --version 1.2.1                
#r "nuget: Voyager.HealthEndpoint, 1.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Voyager.HealthEndpoint as a Cake Addin
#addin nuget:?package=Voyager.HealthEndpoint&version=1.2.1

// Install Voyager.HealthEndpoint as a Cake Tool
#tool nuget:?package=Voyager.HealthEndpoint&version=1.2.1                

Voyager.HealthEndpoint


The extension for AspNetCore provides endpoints for sampling the health of the hosted application.

About

Just after registering services and mapping the endpoint the service for a health check is ready. After simply adding support specific to the application, it allows testing the readiness of the application for the needs of traffic management services. The interface can be used by Kubernetes, Supervisor, or any solution that probes over HTTP. It could be used in any kind of .Net Core application that provides an HTTP interface.

The library is very light. It doesn't include any new dependencies except those abstract declarations that already have been included in projects supporting HTTP interfaces. Registration is carried out based on framework receipt so the new interface will have been seen by other standard tools like Swagger.

The library doesn't require developers any specific for probing knowledge. It's just an extension that can be used by any kind of health check policy. Depending on an override of one method it can check the connection to any database, could test access to a filesystem, or an external connection, and check any kind of rules validating that the application is ready to work.

🏁 Getting Started

Prerequisites

The library coperate with the WebApplicationBuilder or HostApplicationBuilder. By the default, the hosts contain the required Dependency Injection.

🔧 How to configure test health check

Adding the NuGet to a project:

dotnet add package Voyager.HealthEndpoint

The default services are installed to the serivce catalog:

// use the namespace
using Microsoft.Extensions.DependencyInjection;
...
    // in the configuration method
    public void ConfigureServices(IServiceCollection services)
    {
      ...
      // Add the line
      services.AddHealthServices();
    }
    ...

Is requered adding the endpoint mapping to the pipline:

// use the namespace
using  Microsoft.AspNetCore.Builder
...
  // in the method
  public void Configure(IApplicationBuilder app)
  {
    ...
    app.UseEndpoints(endpoints =>
    {
      // add this 
      endpoints.MapHealth("/health");
      ...
    });
  }

After running the application it is possible to start probing:

curl http://localhost:5200/health

🔧 How to test readiness

For testing, readiness is required to implement the Voyager.HealthEndpoint.Interface.AppStatus interface. The class has to call a procedure that processes normal routine or in case of any problems it has to throw an exception.

public class HealthProbe : Voyager.HealthEndpoint.Interface.AppStatus
{
	// It's a class with the logic used to check if is an available connection to this data store
  private readonly ServerNameStory serverNameStory;

  public HealthProbe(ServerNameStory serverNameStory)
  {
    this.serverNameStory = serverNameStory;
  }

  public async Task ReadAsync()
  {
    await serverNameStory.Name().ConfigureAwait(false);
  }

  public Task<string> StoreNameAsync()
  {
    return serverNameStory.Name();
  }
}

The new class have to be registred in DI:

using Microsoft.Extensions.DependencyInjection;
...
    public void ConfigureServices(IServiceCollection services)
    {
      ...
      services.AddHealthServices().AddAppStatus<HealthProbe>();
    }
    ...

Is required to add the new mapping:

using  Microsoft.AspNetCore.Builder
...
  // in the method
  public void Configure(IApplicationBuilder app)
  {
    ...
    app.UseEndpoints(endpoints =>
    {
      // add this 
      endpoints.MapReadiness("/health/readiness");
      ...
    });
  }

In case the class return an exception the service will return the HTTP code = 503.

🔧 How to check the configuration

There is another method that from practice is very useful. This is the method that returns the name of the data store. In an environment, the connection to the storage depends on a configuration, for example, a config map in Kubernatess, and sometimes environment variables, it's good to have the possibility to check that everything is ok and that the application uses the desired data storage.

The implementation is in the class like above. It is only required to add the map for the new method.

using  Microsoft.AspNetCore.Builder
...
  // in the method
  public void Configure(IApplicationBuilder app)
  {
    ...
    app.UseEndpoints(endpoints =>
    {
      // add this 
      endpoints.MapSourceName("/sqlname");
      ...
    });
  }

✍️ Authors

  • @andrzejswistowski - Idea & work. Please let me know if you find out an error or suggestions.

contributors.

🎉 Acknowledgements

  • Przemysław Wróbel - for the icon.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.2 737 11/21/2023
1.2.1 213 4/14/2023
1.2.0 185 3/31/2023
1.1.7 208 3/15/2023
1.1.6 217 3/15/2023
1.0.0 111 11/21/2023