question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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);
        }

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, May 26, 2023

Ok, I understand.

Rather than have two predicates, what I’d like to do is:

  • Obsolete the current predicate on ServiceMapping that takes a HealthResult.
  • Add a new predicate that takes the health registration name, tags, and maybe description. Those values are common between HealthCheckRegistration and HealthResult.
  • The new predicate can be used in both places:
    • The health checks publisher to filter health results
    • CheckHealthAsync to determine what health checks should run for a service name.
0reactions
banatm-abbcommented, May 25, 2023

Potential solution could be to:

  • add new predicate in ServiceMapping Func<HealthCheckRegistration, bool> ExecutionPredicate { get; } with default value to return always true
  • use bothservice.ExecutionPredicate and _healthCheckOptions.Predicate in GetHealthCheckResponseAsync
        HealthCheckResponse.Types.ServingStatus status;
        if (_grpcHealthCheckOptions.Services.TryGetServiceMapping(service, out var serviceMapping))
        {
            var result = await _healthCheckService.CheckHealthAsync(
                (r) =>
                    (_healthCheckOptions.Predicate == null || _healthCheckOptions.Predicate(r))
                    && serviceMapping.ExecutionPredicate(r),
                cancellationToken
            );
            status = HealthChecksStatusHelpers.GetStatus(result, serviceMapping.Predicate);
        }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Health checking gRPC servers on Kubernetes
In this article, we will talk about grpc-health-probe, a Kubernetes-native way to health check gRPC apps. If you're unfamiliar, Kubernetes ...
Read more >
Configuring gRPC probes with the latest versions ... - YouTube
Kubernetes introduces the native support of gRPC probes for health and readiness checks. Many Kubernetes users who used to run gRPC services ...
Read more >
Container health checks (services) - Cloud Run
You can configure HTTP, TCP, and gRPC startup health check probes, along with HTTP and gRPC liveness probes for new and existing Cloud...
Read more >
gRPC health checks in ASP.NET Core
The health checks service is added to the server app. ·.NET health checks registered with the app are periodically executed for health results....
Read more >
Health checking your gRPC servers on GKE
Kubernetes natively supports some health check methods to assert readiness or liveness of a Pod: TCP socket open; HTTP GET request; executing a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found