Skip to content

gRPC health checks in kubernetes scenario - unable to execute on demand only subset of healthchecks #2141

Closed
@banatm-abb

Description

@banatm-abb

What version of gRPC and what language are you using?

2.53.0

What operating system (Linux, Windows,...) and version?

macos

What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)

6.0.16

What did you do?

Trying to configure kubernetes grpc healthchecks for my service.
I want to have different healthchecks executed on demand for startup and liveness probe.

I've tried to use the following configuration:

        services
            .AddGrpcHealthChecks(o =>
            {
                // startup probe checks dependencies
                o.Services.MapService("startup", r => r.Tags.Contains("startup"));
                // startup probe checks dependencies
                o.Services.MapService( "liveness", r => r.Tags.Contains("liveness"));
                o.Services.MapService("", r => r.Tags.Contains("liveness");
                o.UseHealthChecksCache = false;
            })
            ... //definitions here

           //auto update just liveness ones
           services.Configure<HealthCheckPublisherOptions>(options =>
           {
             options.Predicate = (r) => r.Tags.Contains("liveness");
           });

What did you expect to see?

grpc_cli call IP:PORT grpc.health.v1.Health/Check "service: 'startup'" will run only checks tagged with startup
grpc_cli call IP:PORT grpc.health.v1.Health/Check "service: 'liveness'" will run only checks tagged with liveness

What did you see instead?

grpc_cli call IP:PORT grpc.health.v1.Health/Check "service: 'startup'" doesnt not run startup tagged checks at all!

Code hint

In the newest code I've found that the CheckHealthAsync is executed with different predicate than GetStatus. Is it by design?

        HealthCheckResponse.Types.ServingStatus status;
        if (_grpcHealthCheckOptions.Services.TryGetServiceMapping(service, out var serviceMapping))
        {
            var result = await _healthCheckService.CheckHealthAsync(_healthCheckOptions.Predicate, cancellationToken);
            status = HealthChecksStatusHelpers.GetStatus(result, serviceMapping.Predicate);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions