From: Evan Jones Date: Thu, 25 Sep 2025 17:53:20 +0000 (-0400) Subject: examples/features/health: Clarify docs for health import (#8597) X-Git-Url: https://git.feebdaed.xyz/?a=commitdiff_plain;h=8e6c2287eba710bb7614cb8527abd2312795615a;p=0xmirror%2Fgrpc-go.git examples/features/health: Clarify docs for health import (#8597) The google.golang.org/grpc/health package must be imported for client health checking to work. I somehow missed this, even though it is in the README, the client example, and the health package docs. Attempt to make it clearer with a few extra mentions, since it is quite hard to debug this misconfiguration. * Remove deprecated grpc.WithBlock function * Make service config const since it isn't modified Attempts to clarify Issue #8590. RELEASE NOTES: N/A --- diff --git a/examples/features/health/README.md b/examples/features/health/README.md index 69ee3813..1b8f0e89 100644 --- a/examples/features/health/README.md +++ b/examples/features/health/README.md @@ -25,15 +25,14 @@ Clients have two ways to monitor a servers health. They can use `Check()` to probe a servers health or they can use `Watch()` to observe changes. In most cases, clients do not need to directly check backend servers. -Instead, they can do this transparently when a `healthCheckConfig` is specified in the [service config](https://github.com/grpc/proposal/blob/master/A17-client-side-health-checking.md#service-config-changes). -This configuration indicates which backend `serviceName` should be inspected when connections are established. +Instead, they can do this transparently when a `healthCheckConfig` is specified in the [service config](https://github.com/grpc/proposal/blob/master/A17-client-side-health-checking.md#service-config-changes) and the [health package](https://pkg.go.dev/google.golang.org/grpc/health) is imported. +The `serviceName` in `healthCheckConfig` will be used in the health check when connections are established. An empty string (`""`) typically indicates the overall health of a server should be reported. ```go // import grpc/health to enable transparent client side checking import _ "google.golang.org/grpc/health" -// set up appropriate service config serviceConfig := grpc.WithDefaultServiceConfig(`{ "loadBalancingPolicy": "round_robin", "healthCheckConfig": { diff --git a/examples/features/health/client/main.go b/examples/features/health/client/main.go index dc5382a4..f7c97aaa 100644 --- a/examples/features/health/client/main.go +++ b/examples/features/health/client/main.go @@ -30,12 +30,12 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" pb "google.golang.org/grpc/examples/features/proto/echo" - _ "google.golang.org/grpc/health" + _ "google.golang.org/grpc/health" // REQUIRED to enable health checks "google.golang.org/grpc/resolver" "google.golang.org/grpc/resolver/manual" ) -var serviceConfig = `{ +const serviceConfig = `{ "loadBalancingPolicy": "round_robin", "healthCheckConfig": { "serviceName": "" @@ -68,8 +68,8 @@ func main() { options := []grpc.DialOption{ grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), grpc.WithResolvers(r), + // google.golang.org/grpc/health must also be imported grpc.WithDefaultServiceConfig(serviceConfig), }