gRPC HealthChecks returning '''Unknown''' Rather than Serving
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 836
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 7
Description
### What version of gRPC and what language are you using?
2.55.0 / 2.56.0-pre2 --> C#
### What operating system (Linux, Windows,...) and version?
Windows 11
### What runtime / compiler are you using (e.g. .NET Core SDK version `dotnet --info`)
net7.0 (7.0.307)
### What did you do?
I was able to replicate this issue with the default grpc template from VS.
Basically dialing into the grpc.health.v1.services --> Check/Watch will return Unkwnown as a status.
This is my ```Program.cs```
```
using GrpcService1.HealthCheck;
using GrpcService1.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGrpc();
builder.Services.AddGrpcHealthChecks(o =>
{
o.Services.Map("", r => r.Tags.Contains("public"));
}).AddCheck("ping");
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapGrpcService();
app.MapGrpcHealthChecksService();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.Run();
```
And this is my healthCheck:
```
public class PingHealthCheck : IHealthCheck
{
public async Task CheckHealthAsync(HealthCheckContext context,
CancellationToken cancellationToken = new())
{
using var channel = GrpcChannel.ForAddress("http://localhost:5127/", new GrpcChannelOptions
{
});
var client = new Health.HealthClient(channel);
var response = await client.CheckAsync(new HealthCheckRequest());
var status = response.Status;
return status == HealthCheckResponse.Types.ServingStatus.Serving
? HealthCheckResult.Healthy()
: HealthCheckResult.Unhealthy();
}
}
```
I've been following this doc: https://learn.microsoft.com/en-us/aspnet/core/grpc/health-checks?view=aspnetcore-7.0
```
Health results determine what the gRPC service reports:
1. Unknown is reported when there are no health results.
2. NotServing is reported when there are any health results of [HealthStatus.Unhealthy](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.diagnostics.healthchecks.healthstatus#microsoft-extensions-diagnostics-healthchecks-healthstatus-unhealthy).
3. Otherwise, Serving is reported.
```
This is a bit weird, because I don't get why there aren't any health results, do I need to kickstart anything? Like if I comment out the
MapGrpcHealthChecksService the service will rightfully fail, telling me that it's not implemented.
I have attached my sample.
### What did you expect to see?
```
{
"status": "SERVING"
}
```
### What did you see instead?
```
{
"status": "UNKNOWN"
}
```
[GrpcService1.zip](https://github.com/grpc/grpc-dotnet/files/12406326/GrpcService1.zip)
Contributor guide
Assessment
This issue has not been assessed yet.