1GRPC Health Checking Protocol
2================================
3
4Health checks are used to probe whether the server is able to handle rpcs. The
5client-to-server health checking can happen from point to point or via some
6control system. A server may choose to reply “unhealthy” because it
7is not ready to take requests, it is shutting down or some other reason.
8The client can act accordingly if the response is not received within some time
9window or the response says unhealthy in it.
10
11
12A GRPC service is used as the health checking mechanism for both simple
13client-to-server scenario and other control systems such as load-balancing.
14Being a high
15level service provides some benefits. Firstly, since it is a GRPC service
16itself, doing a health check is in the same format as a normal rpc. Secondly,
17it has rich semantics such as per-service health status. Thirdly, as a GRPC
18service, it is able reuse all the existing billing, quota infrastructure, etc,
19and thus the server has full control over the access of the health checking
20service.
21
22## Service Definition
23
24The server should export a service defined in the following proto:
25
26```
27syntax = "proto3";
28
29package grpc.health.v1;
30
31message HealthCheckRequest {
32  string service = 1;
33}
34
35message HealthCheckResponse {
36  enum ServingStatus {
37    UNKNOWN = 0;
38    SERVING = 1;
39    NOT_SERVING = 2;
40  }
41  ServingStatus status = 1;
42}
43
44service Health {
45  rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
46
47  rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);
48}
49```
50
51A client can query the server’s health status by calling the `Check` method, and
52a deadline should be set on the rpc. The client can optionally set the service
53name it wants to query for health status. The suggested format of service name
54is `package_names.ServiceName`, such as `grpc.health.v1.Health`.
55
56The server should register all the services manually and set
57the individual status, including an empty service name and its status. For each
58request received, if the service name can be found in the registry,
59a response must be sent back with an `OK` status and the status field should be
60set to `SERVING` or `NOT_SERVING` accordingly. If the service name is not
61registered, the server returns a `NOT_FOUND` GRPC status.
62
63The server should use an empty string as the key for server's
64overall health status, so that a client not interested in a specific service can
65query the server's status with an empty request. The server can just do exact
66matching of the service name without support of any kind of wildcard matching.
67However, the service owner has the freedom to implement more complicated
68matching semantics that both the client and server agree upon.
69
70A client can declare the server as unhealthy if the rpc is not finished after
71some amount of time. The client should be able to handle the case where server
72does not have the Health service.
73
74A client can call the `Watch` method to perform a streaming health-check.
75The server will immediately send back a message indicating the current
76serving status.  It will then subsequently send a new message whenever
77the service's serving status changes.
78