gRPC - Health Checks

In this article we will show how to use gRPC health checks with the ABP Framework.

Health Checks

ASP.NET Core 7 supports gRPC health checks. Health Checks allow us to determine the overall health and availability of our application infrastructure. They are exposed as HTTP endpoints and can be configured to provide information for various monitoring scenarios, such as the response time and memory usage of our application, or whether our application can communicate with our database provider.

gRPC Health Checks

The gRPC health checking protocol is a standard for reporting the health of gRPC server apps. An app exposes health checks as a gRPC service. They are typically used with an external monitoring service to check the status of an app.

Grpc.AspNetCore.HealthChecks

ASP.NET Core supports the gRPC health checking protocol with the Grpc.AspNetCore.HealthChecks package. Results from .NET health checks are reported to callers.

Using gRPC Health Checks with the ABP Framework

In this article, I'm assuming you've used gRPC with ABP before. If you are still having problems with this, it may be good for you to review this article.
https://community.abp.io/posts/using-grpc-with-the-abp-framework-2dgaxzw3

Set up gRPC Health Checks

In this solution, *.HttpApi.Host is the project that configures and runs the server-side application. So, we will make changes in that project.

  • Add the Grpc.AspNetCore.HealthChecks package to your project.
dotnet add package Grpc.AspNetCore.HealthChecks
  • AddGrpcHealthChecks to register services that enable health checks.
public override void ConfigureServices(ServiceConfigurationContext context)
{
    // Other configurations...

    context.Services.AddGrpcHealthChecks()
        .AddCheck("SampleHealthCheck", () => HealthCheckResult.Healthy());
}
  • MapGrpcHealthChecksService to add a health check service endpoint.
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
    // Other middlewares...

    app.UseConfiguredEndpoints(builder =>
    {
        builder.MapGrpcHealthChecksService();
    });
}

Calling Health Checks From a Client

Now that our server is configured for gRPC health checks, we can test it by creating a basic console client.

var channel = GrpcChannel.ForAddress("https://localhost:44357");
var client = new Health.HealthClient(channel);

var response = await client.CheckAsync(new HealthCheckRequest());
var status = response.Status;

Console.WriteLine($"Health Status: {status}");

References

Salih Özkara 69 weeks ago

Great post!

Enis Necipoğlu 69 weeks ago

Great article!

annacrawd@gmail.com 46 weeks ago

Proper nutrition and the use of fresh products allows you to maintain and maintain good physical health for many years. mental health is also important for every person and I advise you to go here to learn more about the use of quality natural products based on the well-known weed. This is a great solution for maintaining good mental health.