1 // Copyright 2016 gRPC authors.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
20 // Signed seconds of the span of time. Must be from -315,576,000,000
21 // to +315,576,000,000 inclusive.
24 // Signed fractions of a second at nanosecond resolution of the span
25 // of time. Durations less than one second are represented with a 0
26 // `seconds` field and a positive or negative `nanos` field. For durations
27 // of one second or more, a non-zero value for the `nanos` field must be
28 // of the same sign as the `seconds` field. Must be from -999,999,999
29 // to +999,999,999 inclusive.
35 // Represents seconds of UTC time since Unix epoch
36 // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
37 // 9999-12-31T23:59:59Z inclusive.
40 // Non-negative fractions of a second at nanosecond resolution. Negative
41 // second values with fractions must still have non-negative nanos values
42 // that count forward in time. Must be from 0 to 999,999,999
47 service LoadBalancer {
48 // Bidirectional rpc to get a list of servers.
49 rpc BalanceLoad(stream LoadBalanceRequest)
50 returns (stream LoadBalanceResponse);
53 message LoadBalanceRequest {
54 oneof load_balance_request_type {
55 // This message should be sent on the first request to the load balancer.
56 InitialLoadBalanceRequest initial_request = 1;
58 // The client stats should be periodically reported to the load balancer
59 // based on the duration defined in the InitialLoadBalanceResponse.
60 ClientStats client_stats = 2;
64 message InitialLoadBalanceRequest {
65 // Name of load balanced service (IE, balancer.service.com)
66 // length should be less than 256 bytes.
70 // Contains client level statistics that are useful to load balancing. Each
71 // count except the timestamp should be reset to zero after reporting the stats.
73 // The timestamp of generating the report.
74 Timestamp timestamp = 1;
76 // The total number of RPCs that started.
77 int64 num_calls_started = 2;
79 // The total number of RPCs that finished.
80 int64 num_calls_finished = 3;
82 // The total number of RPCs that were dropped by the client because of rate
84 int64 num_calls_finished_with_drop_for_rate_limiting = 4;
86 // The total number of RPCs that were dropped by the client because of load
88 int64 num_calls_finished_with_drop_for_load_balancing = 5;
90 // The total number of RPCs that failed to reach a server except dropped RPCs.
91 int64 num_calls_finished_with_client_failed_to_send = 6;
93 // The total number of RPCs that finished and are known to have been received
95 int64 num_calls_finished_known_received = 7;
98 message LoadBalanceResponse {
99 oneof load_balance_response_type {
100 // This message should be sent on the first response to the client.
101 InitialLoadBalanceResponse initial_response = 1;
103 // Contains the list of servers selected by the load balancer. The client
104 // should send requests to these servers in the specified order.
105 ServerList server_list = 2;
109 message InitialLoadBalanceResponse {
110 // This is an application layer redirect that indicates the client should use
111 // the specified server for load balancing. When this field is non-empty in
112 // the response, the client should open a separate connection to the
113 // load_balancer_delegate and call the BalanceLoad method. Its length should
114 // be less than 64 bytes.
115 string load_balancer_delegate = 1;
117 // This interval defines how often the client should send the client stats
118 // to the load balancer. Stats should only be reported when the duration is
120 Duration client_stats_report_interval = 2;
124 // Contains a list of servers selected by the load balancer. The list will
125 // be updated when server resolutions change or as needed to balance load
126 // across more servers. The client should consume the server list in order
127 // unless instructed otherwise via the client_config.
128 repeated Server servers = 1;
130 // Indicates the amount of time that the client should consider this server
131 // list as valid. It may be considered stale after waiting this interval of
132 // time after receiving the list. If the interval is not positive, the
133 // client can assume the list is valid until the next list is received.
134 Duration expiration_interval = 3;
137 // Contains server information. When none of the [drop_for_*] fields are true,
138 // use the other fields. When drop_for_rate_limiting is true, ignore all other
139 // fields. Use drop_for_load_balancing only when it is true and
140 // drop_for_rate_limiting is false.
142 // A resolved address for the server, serialized in network-byte-order. It may
143 // either be an IPv4 or IPv6 address.
144 bytes ip_address = 1;
146 // A resolved port number for the server.
149 // An opaque but printable token given to the frontend for each pick. All
150 // frontend requests for that pick must include the token in its initial
151 // metadata. The token is used by the backend to verify the request and to
152 // allow the backend to report load to the gRPC LB system.
154 // Its length is variable but less than 50 bytes.
155 string load_balance_token = 3;
157 // Indicates whether this particular request should be dropped by the client
158 // for rate limiting.
159 bool drop_for_rate_limiting = 4;
161 // Indicates whether this particular request should be dropped by the client
162 // for load balancing.
163 bool drop_for_load_balancing = 5;