]> git.feebdaed.xyz Git - 0xmirror/grpc-go.git/commitdiff
examples/features/health: Clarify docs for health import (#8597)
authorEvan Jones <evan.jones@datadoghq.com>
Thu, 25 Sep 2025 17:53:20 +0000 (13:53 -0400)
committerGitHub <noreply@github.com>
Thu, 25 Sep 2025 17:53:20 +0000 (10:53 -0700)
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

examples/features/health/README.md
examples/features/health/client/main.go

index 69ee38135c5bc07ff195afdd0b1ab71847522c4d..1b8f0e89d8560ae6a8a097b712fdae233a864223 100644 (file)
@@ -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": {
index dc5382a40a9eb834f210cae3165c9e9f73f39ac9..f7c97aaacf1d278d5608ca19d1b4ef807aa9c23c 100644 (file)
@@ -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),
        }