From a097bee1ff8dfaed1d52109734cedbca5d12abd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Ali=20=C3=96ZKAYA?= Date: Sun, 27 Nov 2022 16:40:04 +0300 Subject: [PATCH 1/3] Community Article: gRPC - Health Checks --- .../2022-11-27-gRPC-Health-Checks/POST.md | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md diff --git a/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md b/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md new file mode 100644 index 0000000000..533be0c6f4 --- /dev/null +++ b/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md @@ -0,0 +1,69 @@ +# gRPC - Health Checks + +ASP.NET Core 7 supports gRPC health checks. In this article we will show how to use gRPC health checks with the ABP Framework. + +## 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](https://github.com/grpc/grpc/blob/master/doc/health-checking.md) 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](https://www.nuget.org/packages/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. + +```bash +dotnet add package Grpc.AspNetCore.HealthChecks +``` + +* `AddGrpcHealthChecks` to register services that enable health checks. + +```csharp +public override void ConfigureServices(ServiceConfigurationContext context) +{ + // Other configurations... + + context.Services.AddGrpcHealthChecks() + .AddCheck("SampleHealthCheck", () => HealthCheckResult.Healthy()); +} +``` +* `MapGrpcHealthChecksService` to add a health checks service endpoint. + +```csharp +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. + +```csharp +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}"); +``` \ No newline at end of file From 8c3069f13b532769571dc925a99554902f38c61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Ali=20=C3=96ZKAYA?= Date: Mon, 28 Nov 2022 10:50:45 +0300 Subject: [PATCH 2/3] Add references section --- .../2022-11-27-gRPC-Health-Checks/POST.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md b/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md index 533be0c6f4..ce2ed939ac 100644 --- a/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md +++ b/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md @@ -1,10 +1,10 @@ # gRPC - Health Checks -ASP.NET Core 7 supports gRPC health checks. In this article we will show how to use gRPC health checks with the ABP Framework. +In this article we will show how to use gRPC health checks with the ABP Framework. ## 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. +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 @@ -66,4 +66,8 @@ var response = await client.CheckAsync(new HealthCheckRequest()); var status = response.Status; Console.WriteLine($"Health Status: {status}"); -``` \ No newline at end of file +``` + +## References + +- https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-7.0?view=aspnetcore-7.0#grpc-health-checks-in-aspnet-core \ No newline at end of file From aff68835b048b7f7b02c09998d9dd69db71ab718 Mon Sep 17 00:00:00 2001 From: Hamza Albreem <94292623+braim23@users.noreply.github.com> Date: Mon, 28 Nov 2022 10:57:27 +0300 Subject: [PATCH 3/3] tiny fix --- .../Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md b/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md index ce2ed939ac..70bcb15e38 100644 --- a/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md +++ b/docs/en/Community-Articles/2022-11-27-gRPC-Health-Checks/POST.md @@ -40,7 +40,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) .AddCheck("SampleHealthCheck", () => HealthCheckResult.Healthy()); } ``` -* `MapGrpcHealthChecksService` to add a health checks service endpoint. +* `MapGrpcHealthChecksService` to add a health check service endpoint. ```csharp public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -70,4 +70,4 @@ Console.WriteLine($"Health Status: {status}"); ## References -- https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-7.0?view=aspnetcore-7.0#grpc-health-checks-in-aspnet-core \ No newline at end of file +- https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-7.0?view=aspnetcore-7.0#grpc-health-checks-in-aspnet-core