Skip to content

Commit 8e6c228

Browse files
authored
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
1 parent 1059e84 commit 8e6c228

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

examples/features/health/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ Clients have two ways to monitor a servers health.
2525
They can use `Check()` to probe a servers health or they can use `Watch()` to observe changes.
2626

2727
In most cases, clients do not need to directly check backend servers.
28-
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).
29-
This configuration indicates which backend `serviceName` should be inspected when connections are established.
28+
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.
29+
The `serviceName` in `healthCheckConfig` will be used in the health check when connections are established.
3030
An empty string (`""`) typically indicates the overall health of a server should be reported.
3131

3232
```go
3333
// import grpc/health to enable transparent client side checking
3434
import _ "google.golang.org/grpc/health"
3535

36-
// set up appropriate service config
3736
serviceConfig := grpc.WithDefaultServiceConfig(`{
3837
"loadBalancingPolicy": "round_robin",
3938
"healthCheckConfig": {

examples/features/health/client/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import (
3030
"google.golang.org/grpc"
3131
"google.golang.org/grpc/credentials/insecure"
3232
pb "google.golang.org/grpc/examples/features/proto/echo"
33-
_ "google.golang.org/grpc/health"
33+
_ "google.golang.org/grpc/health" // REQUIRED to enable health checks
3434
"google.golang.org/grpc/resolver"
3535
"google.golang.org/grpc/resolver/manual"
3636
)
3737

38-
var serviceConfig = `{
38+
const serviceConfig = `{
3939
"loadBalancingPolicy": "round_robin",
4040
"healthCheckConfig": {
4141
"serviceName": ""
@@ -68,8 +68,8 @@ func main() {
6868

6969
options := []grpc.DialOption{
7070
grpc.WithTransportCredentials(insecure.NewCredentials()),
71-
grpc.WithBlock(),
7271
grpc.WithResolvers(r),
72+
// google.golang.org/grpc/health must also be imported
7373
grpc.WithDefaultServiceConfig(serviceConfig),
7474
}
7575

0 commit comments

Comments
 (0)