grpc 1.23.0 → 1.24.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +765 -485
  3. data/include/grpc/grpc.h +3 -1
  4. data/include/grpc/grpc_security.h +20 -4
  5. data/include/grpc/impl/codegen/grpc_types.h +6 -5
  6. data/include/grpc/impl/codegen/port_platform.h +25 -0
  7. data/src/core/ext/filters/client_channel/backend_metric.cc +78 -0
  8. data/src/core/ext/filters/client_channel/backend_metric.h +36 -0
  9. data/src/core/ext/filters/client_channel/channel_connectivity.cc +16 -2
  10. data/src/core/ext/filters/client_channel/client_channel.cc +325 -267
  11. data/src/core/ext/filters/client_channel/client_channel_factory.h +0 -4
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +23 -32
  13. data/src/core/ext/filters/client_channel/http_proxy.cc +7 -3
  14. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy.h +58 -34
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +46 -50
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +9 -2
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +35 -17
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +130 -215
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +34 -21
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1120 -802
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +8 -2
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +33 -12
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc +151 -40
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h +184 -26
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +389 -245
  27. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +98 -60
  28. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +6 -1
  29. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +89 -0
  30. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +3 -8
  31. data/src/core/ext/filters/client_channel/server_address.cc +1 -3
  32. data/src/core/ext/filters/client_channel/server_address.h +1 -1
  33. data/src/core/ext/filters/client_channel/subchannel.h +2 -1
  34. data/src/core/ext/filters/client_idle/client_idle_filter.cc +207 -29
  35. data/src/core/ext/filters/http/client/http_client_filter.cc +10 -8
  36. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  37. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +10 -7
  38. data/src/core/ext/filters/http/server/http_server_filter.cc +52 -26
  39. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +23 -20
  40. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +24 -21
  41. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  42. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +37 -24
  43. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
  44. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +237 -191
  45. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +29 -27
  46. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +1 -1
  47. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +19 -4
  48. data/src/core/ext/transport/chttp2/transport/hpack_table.h +13 -4
  49. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -1
  50. data/src/core/ext/transport/chttp2/transport/internal.h +0 -2
  51. data/src/core/ext/transport/chttp2/transport/parsing.cc +99 -71
  52. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +222 -0
  53. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +818 -0
  54. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +314 -0
  55. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1142 -0
  56. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +53 -0
  57. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +158 -0
  58. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +34 -0
  59. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +69 -0
  60. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +49 -0
  61. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +240 -0
  62. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +110 -0
  63. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +324 -0
  64. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +235 -0
  65. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +661 -0
  66. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +84 -0
  67. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +274 -0
  68. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +175 -0
  69. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +572 -0
  70. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +150 -0
  71. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +596 -0
  72. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +35 -0
  73. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +80 -0
  74. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +95 -0
  75. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +308 -0
  76. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +128 -0
  77. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +392 -0
  78. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +91 -0
  79. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +236 -0
  80. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +88 -0
  81. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +258 -0
  82. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +111 -0
  83. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +324 -0
  84. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +23 -0
  85. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +50 -0
  86. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +52 -0
  87. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +130 -0
  88. data/src/core/ext/upb-generated/envoy/type/percent.upb.c +39 -0
  89. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +87 -0
  90. data/src/core/ext/upb-generated/envoy/type/range.upb.c +39 -0
  91. data/src/core/ext/upb-generated/envoy/type/range.upb.h +85 -0
  92. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +17 -0
  93. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +30 -0
  94. data/src/core/ext/upb-generated/google/api/annotations.upb.c +18 -0
  95. data/src/core/ext/upb-generated/google/api/annotations.upb.h +30 -0
  96. data/src/core/ext/upb-generated/google/api/http.upb.c +66 -0
  97. data/src/core/ext/upb-generated/google/api/http.upb.h +190 -0
  98. data/src/core/ext/upb-generated/google/protobuf/any.upb.c +27 -0
  99. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +58 -0
  100. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +485 -0
  101. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +1690 -0
  102. data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +27 -0
  103. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +58 -0
  104. data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +22 -0
  105. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +50 -0
  106. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +79 -0
  107. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +215 -0
  108. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +27 -0
  109. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +58 -0
  110. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +106 -0
  111. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +238 -0
  112. data/src/core/ext/upb-generated/google/rpc/status.upb.c +33 -0
  113. data/src/core/ext/upb-generated/google/rpc/status.upb.h +74 -0
  114. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +49 -0
  115. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +126 -0
  116. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +209 -0
  117. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +681 -0
  118. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +42 -0
  119. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +109 -0
  120. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +36 -0
  121. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +84 -0
  122. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +133 -0
  123. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +359 -0
  124. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +58 -0
  125. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +144 -0
  126. data/src/core/ext/upb-generated/validate/validate.upb.c +443 -0
  127. data/src/core/ext/upb-generated/validate/validate.upb.h +2037 -0
  128. data/src/core/lib/channel/channel_args.cc +21 -0
  129. data/src/core/lib/channel/channel_args.h +16 -2
  130. data/src/core/lib/channel/channel_stack.h +2 -1
  131. data/src/core/lib/channel/channelz.cc +54 -56
  132. data/src/core/lib/channel/channelz.h +29 -12
  133. data/src/core/lib/compression/compression.cc +2 -1
  134. data/src/core/lib/compression/compression_internal.h +8 -0
  135. data/src/core/lib/gpr/log_linux.cc +2 -2
  136. data/src/core/lib/gpr/log_posix.cc +2 -2
  137. data/src/core/lib/gpr/time_precise.cc +123 -36
  138. data/src/core/lib/gpr/time_precise.h +37 -0
  139. data/src/core/lib/gprpp/abstract.h +10 -0
  140. data/src/core/lib/gprpp/atomic.h +4 -0
  141. data/src/core/lib/gprpp/inlined_vector.h +20 -4
  142. data/src/core/lib/gprpp/map.h +109 -6
  143. data/src/core/lib/gprpp/memory.h +6 -0
  144. data/src/core/lib/gprpp/ref_counted_ptr.h +2 -0
  145. data/src/core/lib/iomgr/ev_epollex_linux.cc +29 -54
  146. data/src/core/lib/iomgr/exec_ctx.cc +27 -17
  147. data/src/core/lib/iomgr/exec_ctx.h +3 -0
  148. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -3
  149. data/src/core/lib/iomgr/tcp_posix.cc +16 -25
  150. data/src/core/lib/iomgr/tcp_server_custom.cc +1 -1
  151. data/src/core/lib/iomgr/timer_manager.cc +8 -1
  152. data/src/core/lib/iomgr/timer_manager.h +2 -0
  153. data/src/core/lib/security/credentials/credentials.h +8 -2
  154. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -0
  155. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +3 -0
  156. data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +3 -3
  157. data/src/core/lib/security/security_connector/ssl_utils.cc +1 -12
  158. data/src/core/lib/security/security_connector/ssl_utils.h +10 -6
  159. data/src/core/lib/security/security_connector/ssl_utils_config.cc +32 -0
  160. data/src/core/lib/security/security_connector/ssl_utils_config.h +30 -0
  161. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +161 -49
  162. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +34 -1
  163. data/src/core/lib/slice/slice_intern.cc +17 -9
  164. data/src/core/lib/slice/slice_internal.h +34 -7
  165. data/src/core/lib/slice/slice_utils.h +7 -3
  166. data/src/core/lib/surface/call.cc +97 -57
  167. data/src/core/lib/surface/channel.cc +2 -2
  168. data/src/core/lib/surface/completion_queue.cc +10 -16
  169. data/src/core/lib/surface/init.cc +3 -0
  170. data/src/core/lib/surface/server.cc +11 -14
  171. data/src/core/lib/surface/validate_metadata.cc +4 -0
  172. data/src/core/lib/surface/version.cc +2 -2
  173. data/src/core/lib/transport/metadata.cc +4 -4
  174. data/src/core/lib/transport/metadata_batch.cc +72 -16
  175. data/src/core/lib/transport/metadata_batch.h +38 -0
  176. data/src/core/lib/transport/static_metadata.cc +814 -1023
  177. data/src/core/lib/transport/static_metadata.h +271 -213
  178. data/src/core/lib/transport/transport.h +12 -0
  179. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  180. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +104 -76
  181. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +34 -16
  182. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +2 -2
  183. data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +10 -6
  184. data/src/core/tsi/alts/handshaker/alts_tsi_utils.h +4 -3
  185. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +74 -48
  186. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +34 -26
  187. data/src/core/tsi/ssl_transport_security.cc +14 -6
  188. data/src/core/tsi/ssl_transport_security.h +4 -0
  189. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  190. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  191. data/src/ruby/ext/grpc/extconf.rb +5 -0
  192. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  193. data/src/ruby/ext/grpc/rb_grpc.c +1 -42
  194. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
  195. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
  196. data/src/ruby/lib/grpc.rb +2 -0
  197. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  198. data/src/ruby/lib/grpc/errors.rb +4 -7
  199. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +9 -4
  200. data/src/ruby/lib/grpc/structs.rb +15 -0
  201. data/src/ruby/lib/grpc/version.rb +1 -1
  202. data/src/ruby/spec/errors_spec.rb +1 -0
  203. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  204. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +34 -0
  205. data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -29
  206. data/third_party/upb/upb/decode.c +604 -0
  207. data/third_party/upb/upb/decode.h +21 -0
  208. data/third_party/upb/upb/encode.c +378 -0
  209. data/third_party/upb/upb/encode.h +21 -0
  210. data/third_party/upb/upb/generated_util.h +105 -0
  211. data/third_party/upb/upb/msg.c +111 -0
  212. data/third_party/upb/upb/msg.h +69 -0
  213. data/third_party/upb/upb/port.c +27 -0
  214. data/third_party/upb/upb/port_def.inc +152 -0
  215. data/third_party/upb/upb/port_undef.inc +21 -0
  216. data/third_party/upb/upb/table.c +911 -0
  217. data/third_party/upb/upb/table.int.h +507 -0
  218. data/third_party/upb/upb/upb.c +261 -0
  219. data/third_party/upb/upb/upb.h +364 -0
  220. metadata +129 -50
  221. data/src/core/ext/filters/client_channel/health/health.pb.c +0 -23
  222. data/src/core/ext/filters/client_channel/health/health.pb.h +0 -73
  223. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c +0 -19
  224. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h +0 -54
  225. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c +0 -19
  226. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h +0 -54
  227. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +0 -89
  228. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -164
  229. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc +0 -520
  230. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h +0 -323
  231. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +0 -145
  232. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +0 -149
  233. data/src/core/tsi/alts/handshaker/altscontext.pb.c +0 -47
  234. data/src/core/tsi/alts/handshaker/altscontext.pb.h +0 -63
  235. data/src/core/tsi/alts/handshaker/handshaker.pb.c +0 -122
  236. data/src/core/tsi/alts/handshaker/handshaker.pb.h +0 -254
  237. data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +0 -49
  238. data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +0 -78
  239. data/third_party/nanopb/pb.h +0 -579
  240. data/third_party/nanopb/pb_common.c +0 -97
  241. data/third_party/nanopb/pb_common.h +0 -42
  242. data/third_party/nanopb/pb_decode.c +0 -1347
  243. data/third_party/nanopb/pb_decode.h +0 -149
  244. data/third_party/nanopb/pb_encode.c +0 -696
  245. data/third_party/nanopb/pb_encode.h +0 -154
@@ -36,10 +36,6 @@ class ClientChannelFactory {
36
36
  virtual Subchannel* CreateSubchannel(const grpc_channel_args* args)
37
37
  GRPC_ABSTRACT;
38
38
 
39
- // Creates a channel for the specified target with the specified args.
40
- virtual grpc_channel* CreateChannel(
41
- const char* target, const grpc_channel_args* args) GRPC_ABSTRACT;
42
-
43
39
  // Returns a channel arg containing the specified factory.
44
40
  static grpc_arg CreateChannelArg(ClientChannelFactory* factory);
45
41
 
@@ -23,14 +23,12 @@
23
23
 
24
24
  #include "src/core/ext/filters/client_channel/health/health_check_client.h"
25
25
 
26
- #include "pb_decode.h"
27
- #include "pb_encode.h"
28
- #include "src/core/ext/filters/client_channel/health/health.pb.h"
29
26
  #include "src/core/lib/debug/trace.h"
30
27
  #include "src/core/lib/gprpp/sync.h"
31
28
  #include "src/core/lib/slice/slice_internal.h"
32
29
  #include "src/core/lib/transport/error_utils.h"
33
30
  #include "src/core/lib/transport/status_metadata.h"
31
+ #include "src/proto/grpc/health/v1/health.upb.h"
34
32
 
35
33
  #define HEALTH_CHECK_INITIAL_CONNECT_BACKOFF_SECONDS 1
36
34
  #define HEALTH_CHECK_RECONNECT_BACKOFF_MULTIPLIER 1.6
@@ -202,19 +200,16 @@ namespace {
202
200
 
203
201
  void EncodeRequest(const char* service_name,
204
202
  ManualConstructor<SliceBufferByteStream>* send_message) {
205
- grpc_health_v1_HealthCheckRequest request_struct;
206
- request_struct.has_service = true;
207
- snprintf(request_struct.service, sizeof(request_struct.service), "%s",
208
- service_name);
209
- pb_ostream_t ostream;
210
- memset(&ostream, 0, sizeof(ostream));
211
- pb_encode(&ostream, grpc_health_v1_HealthCheckRequest_fields,
212
- &request_struct);
213
- grpc_slice request_slice = GRPC_SLICE_MALLOC(ostream.bytes_written);
214
- ostream = pb_ostream_from_buffer(GRPC_SLICE_START_PTR(request_slice),
215
- GRPC_SLICE_LENGTH(request_slice));
216
- GPR_ASSERT(pb_encode(&ostream, grpc_health_v1_HealthCheckRequest_fields,
217
- &request_struct) != 0);
203
+ upb::Arena arena;
204
+ grpc_health_v1_HealthCheckRequest* request_struct =
205
+ grpc_health_v1_HealthCheckRequest_new(arena.ptr());
206
+ grpc_health_v1_HealthCheckRequest_set_service(
207
+ request_struct, upb_strview_makez(service_name));
208
+ size_t buf_length;
209
+ char* buf = grpc_health_v1_HealthCheckRequest_serialize(
210
+ request_struct, arena.ptr(), &buf_length);
211
+ grpc_slice request_slice = GRPC_SLICE_MALLOC(buf_length);
212
+ memcpy(GRPC_SLICE_START_PTR(request_slice), buf, buf_length);
218
213
  grpc_slice_buffer slice_buffer;
219
214
  grpc_slice_buffer_init(&slice_buffer);
220
215
  grpc_slice_buffer_add(&slice_buffer, request_slice);
@@ -248,24 +243,19 @@ bool DecodeResponse(grpc_slice_buffer* slice_buffer, grpc_error** error) {
248
243
  }
249
244
  }
250
245
  // Deserialize message.
251
- grpc_health_v1_HealthCheckResponse response_struct;
252
- pb_istream_t istream =
253
- pb_istream_from_buffer(recv_message, slice_buffer->length);
254
- if (!pb_decode(&istream, grpc_health_v1_HealthCheckResponse_fields,
255
- &response_struct)) {
246
+ upb::Arena arena;
247
+ grpc_health_v1_HealthCheckResponse* response_struct =
248
+ grpc_health_v1_HealthCheckResponse_parse(
249
+ reinterpret_cast<char*>(recv_message), slice_buffer->length,
250
+ arena.ptr());
251
+ if (response_struct == nullptr) {
256
252
  // Can't parse message; assume unhealthy.
257
253
  *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
258
254
  "cannot parse health check response");
259
255
  return false;
260
256
  }
261
- if (!response_struct.has_status) {
262
- // Field not present; assume unhealthy.
263
- *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
264
- "status field not present in health check response");
265
- return false;
266
- }
267
- return response_struct.status ==
268
- grpc_health_v1_HealthCheckResponse_ServingStatus_SERVING;
257
+ int32_t status = grpc_health_v1_HealthCheckResponse_status(response_struct);
258
+ return status == grpc_health_v1_HealthCheckResponse_SERVING;
269
259
  }
270
260
 
271
261
  } // namespace
@@ -314,8 +304,8 @@ void HealthCheckClient::CallState::StartCall() {
314
304
  health_check_client_->connected_subchannel_,
315
305
  &pollent_,
316
306
  GRPC_MDSTR_SLASH_GRPC_DOT_HEALTH_DOT_V1_DOT_HEALTH_SLASH_WATCH,
317
- gpr_now(GPR_CLOCK_MONOTONIC), // start_time
318
- GRPC_MILLIS_INF_FUTURE, // deadline
307
+ gpr_get_cycle_counter(), // start_time
308
+ GRPC_MILLIS_INF_FUTURE, // deadline
319
309
  arena_,
320
310
  context_,
321
311
  &call_combiner_,
@@ -356,7 +346,8 @@ void HealthCheckClient::CallState::StartCall() {
356
346
  &send_initial_metadata_, &path_metadata_storage_,
357
347
  grpc_mdelem_from_slices(
358
348
  GRPC_MDSTR_PATH,
359
- GRPC_MDSTR_SLASH_GRPC_DOT_HEALTH_DOT_V1_DOT_HEALTH_SLASH_WATCH));
349
+ GRPC_MDSTR_SLASH_GRPC_DOT_HEALTH_DOT_V1_DOT_HEALTH_SLASH_WATCH),
350
+ GRPC_BATCH_PATH);
360
351
  GPR_ASSERT(error == GRPC_ERROR_NONE);
361
352
  payload_.send_initial_metadata.send_initial_metadata =
362
353
  &send_initial_metadata_;
@@ -47,10 +47,12 @@ static char* get_http_proxy_server(char** user_cred) {
47
47
  char* proxy_name = nullptr;
48
48
  char** authority_strs = nullptr;
49
49
  size_t authority_nstrs;
50
- /* Prefer using 'https_proxy'. Fallback on 'http_proxy' if it is not set. The
50
+ /* Prefer using 'grpc_proxy'. Fallback on 'http_proxy' if it is not set.
51
+ * Also prefer using 'https_proxy' with fallback on 'http_proxy'. The
51
52
  * fallback behavior can be removed if there's a demand for it.
52
53
  */
53
- char* uri_str = gpr_getenv("https_proxy");
54
+ char* uri_str = gpr_getenv("grpc_proxy");
55
+ if (uri_str == nullptr) uri_str = gpr_getenv("https_proxy");
54
56
  if (uri_str == nullptr) uri_str = gpr_getenv("http_proxy");
55
57
  if (uri_str == nullptr) return nullptr;
56
58
  grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */);
@@ -122,7 +124,9 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,
122
124
  server_uri);
123
125
  goto no_use_proxy;
124
126
  }
125
- no_proxy_str = gpr_getenv("no_proxy");
127
+ /* Prefer using 'no_grpc_proxy'. Fallback on 'no_proxy' if it is not set. */
128
+ no_proxy_str = gpr_getenv("no_grpc_proxy");
129
+ if (no_proxy_str == nullptr) no_proxy_str = gpr_getenv("no_proxy");
126
130
  if (no_proxy_str != nullptr) {
127
131
  static const char* NO_PROXY_SEPARATOR = ",";
128
132
  bool use_proxy = true;
@@ -129,7 +129,7 @@ void LoadBalancingPolicy::QueuePicker::CallExitIdle(void* arg,
129
129
  LoadBalancingPolicy::PickResult
130
130
  LoadBalancingPolicy::TransientFailurePicker::Pick(PickArgs args) {
131
131
  PickResult result;
132
- result.type = PickResult::PICK_TRANSIENT_FAILURE;
132
+ result.type = PickResult::PICK_FAILED;
133
133
  result.error = GRPC_ERROR_REF(error_);
134
134
  return result;
135
135
  }
@@ -25,6 +25,7 @@
25
25
  #include "src/core/ext/filters/client_channel/service_config.h"
26
26
  #include "src/core/ext/filters/client_channel/subchannel_interface.h"
27
27
  #include "src/core/lib/gprpp/abstract.h"
28
+ #include "src/core/lib/gprpp/map.h"
28
29
  #include "src/core/lib/gprpp/orphanable.h"
29
30
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
30
31
  #include "src/core/lib/gprpp/string_view.h"
@@ -42,15 +43,15 @@ extern DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
42
43
  ///
43
44
  /// Channel: An abstraction that manages connections to backend servers
44
45
  /// on behalf of a client application. The application creates a channel
45
- /// for a given server name and then sends RPCs on it, and the channel
46
- /// figures out which backend server to send each RPC to. A channel
46
+ /// for a given server name and then sends calls (RPCs) on it, and the
47
+ /// channel figures out which backend server to send each call to. A channel
47
48
  /// contains a resolver, a load balancing policy (or a tree of LB policies),
48
49
  /// and a set of one or more subchannels.
49
50
  ///
50
51
  /// Subchannel: A subchannel represents a connection to one backend server.
51
52
  /// The LB policy decides which subchannels to create, manages the
52
53
  /// connectivity state of those subchannels, and decides which subchannel
53
- /// to send any given RPC to.
54
+ /// to send any given call to.
54
55
  ///
55
56
  /// Resolver: A plugin that takes a gRPC server URI and resolves it to a
56
57
  /// list of one or more addresses and a service config, as described
@@ -59,12 +60,12 @@ extern DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
59
60
  ///
60
61
  /// Load Balancing (LB) Policy: A plugin that takes a list of addresses
61
62
  /// from the resolver, maintains and manages a subchannel for each
62
- /// backend address, and decides which subchannel to send each RPC on.
63
+ /// backend address, and decides which subchannel to send each call on.
63
64
  /// An LB policy has two parts:
64
65
  /// - A LoadBalancingPolicy, which deals with the control plane work of
65
66
  /// managing subchannels.
66
67
  /// - A SubchannelPicker, which handles the data plane work of
67
- /// determining which subchannel a given RPC should be sent on.
68
+ /// determining which subchannel a given call should be sent on.
68
69
 
69
70
  /// LoadBalacingPolicy API.
70
71
  ///
@@ -77,7 +78,28 @@ extern DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
77
78
  // interested_parties() hooks from the API.
78
79
  class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
79
80
  public:
81
+ // Represents backend metrics reported by the backend to the client.
82
+ struct BackendMetricData {
83
+ /// CPU utilization expressed as a fraction of available CPU resources.
84
+ double cpu_utilization;
85
+ /// Memory utilization expressed as a fraction of available memory
86
+ /// resources.
87
+ double mem_utilization;
88
+ /// Total requests per second being served by the backend. This
89
+ /// should include all services that a backend is responsible for.
90
+ uint64_t requests_per_second;
91
+ /// Application-specific requests cost metrics. Metric names are
92
+ /// determined by the application. Each value is an absolute cost
93
+ /// (e.g. 3487 bytes of storage) associated with the request.
94
+ Map<StringView, double, StringLess> request_cost;
95
+ /// Application-specific resource utilization metrics. Metric names
96
+ /// are determined by the application. Each value is expressed as a
97
+ /// fraction of total resources available.
98
+ Map<StringView, double, StringLess> utilization;
99
+ };
100
+
80
101
  /// Interface for accessing per-call state.
102
+ /// Implemented by the client channel and used by the SubchannelPicker.
81
103
  class CallState {
82
104
  public:
83
105
  CallState() = default;
@@ -89,10 +111,15 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
89
111
  /// for allocations that need to be made on a per-call basis.
90
112
  virtual void* Alloc(size_t size) GRPC_ABSTRACT;
91
113
 
114
+ /// Returns the backend metric data returned by the server for the call,
115
+ /// or null if no backend metric data was returned.
116
+ virtual const BackendMetricData* GetBackendMetricData() GRPC_ABSTRACT;
117
+
92
118
  GRPC_ABSTRACT_BASE_CLASS
93
119
  };
94
120
 
95
121
  /// Interface for accessing metadata.
122
+ /// Implemented by the client channel and used by the SubchannelPicker.
96
123
  class MetadataInterface {
97
124
  public:
98
125
  // Implementations whose iterators fit in intptr_t may internally
@@ -123,7 +150,7 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
123
150
  GRPC_ABSTRACT_BASE_CLASS
124
151
  };
125
152
 
126
- /// Arguments used when picking a subchannel for an RPC.
153
+ /// Arguments used when picking a subchannel for a call.
127
154
  struct PickArgs {
128
155
  /// Initial metadata associated with the picking call.
129
156
  /// The LB policy may use the existing metadata to influence its routing
@@ -135,24 +162,23 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
135
162
  CallState* call_state;
136
163
  };
137
164
 
138
- /// The result of picking a subchannel for an RPC.
165
+ /// The result of picking a subchannel for a call.
139
166
  struct PickResult {
140
167
  enum ResultType {
141
- /// Pick complete. If connected_subchannel is non-null, client channel
142
- /// can immediately proceed with the call on connected_subchannel;
143
- /// otherwise, call should be dropped.
168
+ /// Pick complete. If \a subchannel is non-null, the client channel
169
+ /// will immediately proceed with the call on that subchannel;
170
+ /// otherwise, it will drop the call.
144
171
  PICK_COMPLETE,
145
172
  /// Pick cannot be completed until something changes on the control
146
- /// plane. Client channel will queue the pick and try again the
173
+ /// plane. The client channel will queue the pick and try again the
147
174
  /// next time the picker is updated.
148
175
  PICK_QUEUE,
149
- /// LB policy is in transient failure. If the pick is wait_for_ready,
150
- /// client channel will wait for the next picker and try again;
151
- /// otherwise, the call will be failed immediately (although it may
152
- /// be retried if the client channel is configured to do so).
153
- /// The Pick() method will set its error parameter if this value is
154
- /// returned.
155
- PICK_TRANSIENT_FAILURE,
176
+ /// Pick failed. If the call is wait_for_ready, the client channel
177
+ /// will wait for the next picker and try again; otherwise, it
178
+ /// will immediately fail the call with the status indicated via
179
+ /// \a error (although the call may be retried if the client channel
180
+ /// is configured to do so).
181
+ PICK_FAILED,
156
182
  };
157
183
  ResultType type;
158
184
 
@@ -160,32 +186,37 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
160
186
  /// subchannel, or nullptr if the LB policy decides to drop the call.
161
187
  RefCountedPtr<SubchannelInterface> subchannel;
162
188
 
163
- /// Used only if type is PICK_TRANSIENT_FAILURE.
164
- /// Error to be set when returning a transient failure.
189
+ /// Used only if type is PICK_FAILED.
190
+ /// Error to be set when returning a failure.
165
191
  // TODO(roth): Replace this with something similar to grpc::Status,
166
192
  // so that we don't expose grpc_error to this API.
167
193
  grpc_error* error = GRPC_ERROR_NONE;
168
194
 
169
195
  /// Used only if type is PICK_COMPLETE.
170
- /// Callback set by lb policy to be notified of trailing metadata.
196
+ /// Callback set by LB policy to be notified of trailing metadata.
171
197
  /// The user_data argument will be set to the
172
198
  /// recv_trailing_metadata_ready_user_data field.
173
199
  /// recv_trailing_metadata will be set to the metadata, which may be
174
200
  /// modified by the callback. The callback does not take ownership,
175
201
  /// however, so any data that needs to be used after returning must
176
202
  /// be copied.
203
+ /// call_state can be used to obtain backend metric data.
204
+ // TODO(roth): Replace grpc_error with something better before we allow
205
+ // people outside of gRPC team to use this API.
177
206
  void (*recv_trailing_metadata_ready)(
178
- void* user_data, MetadataInterface* recv_trailing_metadata,
207
+ void* user_data, grpc_error* error,
208
+ MetadataInterface* recv_trailing_metadata,
179
209
  CallState* call_state) = nullptr;
180
210
  void* recv_trailing_metadata_ready_user_data = nullptr;
181
211
  };
182
212
 
183
213
  /// A subchannel picker is the object used to pick the subchannel to
184
- /// use for a given RPC.
214
+ /// use for a given call. This is implemented by the LB policy and
215
+ /// used by the client channel to perform picks.
185
216
  ///
186
217
  /// Pickers are intended to encapsulate all of the state and logic
187
218
  /// needed on the data plane (i.e., to actually process picks for
188
- /// individual RPCs sent on the channel) while excluding all of the
219
+ /// individual calls sent on the channel) while excluding all of the
189
220
  /// state and logic needed on the control plane (i.e., resolver
190
221
  /// updates, connectivity state notifications, etc); the latter should
191
222
  /// live in the LB policy object itself.
@@ -203,8 +234,8 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
203
234
  GRPC_ABSTRACT_BASE_CLASS
204
235
  };
205
236
 
206
- /// A proxy object used by the LB policy to communicate with the client
207
- /// channel.
237
+ /// A proxy object implemented by the client channel and used by the
238
+ /// LB policy to communicate with the channel.
208
239
  // TODO(juanlishen): Consider adding a mid-layer subclass that helps handle
209
240
  // things like swapping in pending policy when it's ready. Currently, we are
210
241
  // duplicating the logic in many subclasses.
@@ -217,12 +248,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
217
248
  virtual RefCountedPtr<SubchannelInterface> CreateSubchannel(
218
249
  const grpc_channel_args& args) GRPC_ABSTRACT;
219
250
 
220
- /// Creates a channel with the specified target and channel args.
221
- /// This can be used in cases where the LB policy needs to create a
222
- /// channel for its own use (e.g., to talk to an external load balancer).
223
- virtual grpc_channel* CreateChannel(
224
- const char* target, const grpc_channel_args& args) GRPC_ABSTRACT;
225
-
226
251
  /// Sets the connectivity state and returns a new picker to be used
227
252
  /// by the client channel.
228
253
  virtual void UpdateState(grpc_connectivity_state state,
@@ -232,10 +257,9 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
232
257
  virtual void RequestReresolution() GRPC_ABSTRACT;
233
258
 
234
259
  /// Adds a trace message associated with the channel.
235
- /// Does NOT take ownership of \a message.
236
260
  enum TraceSeverity { TRACE_INFO, TRACE_WARNING, TRACE_ERROR };
237
261
  virtual void AddTraceEvent(TraceSeverity severity,
238
- const char* message) GRPC_ABSTRACT;
262
+ StringView message) GRPC_ABSTRACT;
239
263
 
240
264
  GRPC_ABSTRACT_BASE_CLASS
241
265
  };
@@ -293,12 +293,10 @@ class GrpcLb : public LoadBalancingPolicy {
293
293
 
294
294
  RefCountedPtr<SubchannelInterface> CreateSubchannel(
295
295
  const grpc_channel_args& args) override;
296
- grpc_channel* CreateChannel(const char* target,
297
- const grpc_channel_args& args) override;
298
296
  void UpdateState(grpc_connectivity_state state,
299
297
  UniquePtr<SubchannelPicker> picker) override;
300
298
  void RequestReresolution() override;
301
- void AddTraceEvent(TraceSeverity severity, const char* message) override;
299
+ void AddTraceEvent(TraceSeverity severity, StringView message) override;
302
300
 
303
301
  void set_child(LoadBalancingPolicy* child) { child_ = child; }
304
302
 
@@ -409,18 +407,18 @@ void ParseServer(const grpc_grpclb_server* server,
409
407
  const uint16_t netorder_port = grpc_htons((uint16_t)server->port);
410
408
  /* the addresses are given in binary format (a in(6)_addr struct) in
411
409
  * server->ip_address.bytes. */
412
- const grpc_grpclb_ip_address* ip = &server->ip_address;
413
- if (ip->size == 4) {
410
+ const grpc_grpclb_server_ip_address& ip = server->ip_address;
411
+ if (ip.size == 4) {
414
412
  addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in));
415
413
  grpc_sockaddr_in* addr4 = reinterpret_cast<grpc_sockaddr_in*>(&addr->addr);
416
414
  addr4->sin_family = GRPC_AF_INET;
417
- memcpy(&addr4->sin_addr, ip->bytes, ip->size);
415
+ memcpy(&addr4->sin_addr, ip.data, ip.size);
418
416
  addr4->sin_port = netorder_port;
419
- } else if (ip->size == 16) {
417
+ } else if (ip.size == 16) {
420
418
  addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in6));
421
419
  grpc_sockaddr_in6* addr6 = (grpc_sockaddr_in6*)&addr->addr;
422
420
  addr6->sin6_family = GRPC_AF_INET6;
423
- memcpy(&addr6->sin6_addr, ip->bytes, ip->size);
421
+ memcpy(&addr6->sin6_addr, ip.data, ip.size);
424
422
  addr6->sin6_port = netorder_port;
425
423
  }
426
424
  }
@@ -490,7 +488,7 @@ const grpc_arg_pointer_vtable client_stats_arg_vtable = {
490
488
 
491
489
  bool IsServerValid(const grpc_grpclb_server* server, size_t idx, bool log) {
492
490
  if (server->drop) return false;
493
- const grpc_grpclb_ip_address* ip = &server->ip_address;
491
+ const grpc_grpclb_server_ip_address& ip = server->ip_address;
494
492
  if (GPR_UNLIKELY(server->port >> 16 != 0)) {
495
493
  if (log) {
496
494
  gpr_log(GPR_ERROR,
@@ -499,12 +497,12 @@ bool IsServerValid(const grpc_grpclb_server* server, size_t idx, bool log) {
499
497
  }
500
498
  return false;
501
499
  }
502
- if (GPR_UNLIKELY(ip->size != 4 && ip->size != 16)) {
500
+ if (GPR_UNLIKELY(ip.size != 4 && ip.size != 16)) {
503
501
  if (log) {
504
502
  gpr_log(GPR_ERROR,
505
503
  "Expected IP to be 4 or 16 bytes, got %d at index %lu of "
506
504
  "serverlist. Ignoring",
507
- ip->size, (unsigned long)idx);
505
+ ip.size, (unsigned long)idx);
508
506
  }
509
507
  return false;
510
508
  }
@@ -523,7 +521,7 @@ ServerAddressList GrpcLb::Serverlist::GetServerAddressList(
523
521
  ParseServer(server, &addr);
524
522
  // LB token processing.
525
523
  char lb_token[GPR_ARRAY_SIZE(server->load_balance_token) + 1];
526
- if (server->has_load_balance_token) {
524
+ if (server->load_balance_token[0] != 0) {
527
525
  const size_t lb_token_max_length =
528
526
  GPR_ARRAY_SIZE(server->load_balance_token);
529
527
  const size_t lb_token_length =
@@ -652,15 +650,6 @@ RefCountedPtr<SubchannelInterface> GrpcLb::Helper::CreateSubchannel(
652
650
  return parent_->channel_control_helper()->CreateSubchannel(args);
653
651
  }
654
652
 
655
- grpc_channel* GrpcLb::Helper::CreateChannel(const char* target,
656
- const grpc_channel_args& args) {
657
- if (parent_->shutting_down_ ||
658
- (!CalledByPendingChild() && !CalledByCurrentChild())) {
659
- return nullptr;
660
- }
661
- return parent_->channel_control_helper()->CreateChannel(target, args);
662
- }
663
-
664
653
  void GrpcLb::Helper::UpdateState(grpc_connectivity_state state,
665
654
  UniquePtr<SubchannelPicker> picker) {
666
655
  if (parent_->shutting_down_) return;
@@ -756,8 +745,7 @@ void GrpcLb::Helper::RequestReresolution() {
756
745
  }
757
746
  }
758
747
 
759
- void GrpcLb::Helper::AddTraceEvent(TraceSeverity severity,
760
- const char* message) {
748
+ void GrpcLb::Helper::AddTraceEvent(TraceSeverity severity, StringView message) {
761
749
  if (parent_->shutting_down_ ||
762
750
  (!CalledByPendingChild() && !CalledByCurrentChild())) {
763
751
  return;
@@ -790,13 +778,14 @@ GrpcLb::BalancerCallState::BalancerCallState(
790
778
  GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD,
791
779
  nullptr, deadline, nullptr);
792
780
  // Init the LB call request payload.
781
+ upb::Arena arena;
793
782
  grpc_grpclb_request* request =
794
- grpc_grpclb_request_create(grpclb_policy()->server_name_);
795
- grpc_slice request_payload_slice = grpc_grpclb_request_encode(request);
783
+ grpc_grpclb_request_create(grpclb_policy()->server_name_, arena.ptr());
784
+ grpc_slice request_payload_slice =
785
+ grpc_grpclb_request_encode(request, arena.ptr());
796
786
  send_message_payload_ =
797
787
  grpc_raw_byte_buffer_create(&request_payload_slice, 1);
798
788
  grpc_slice_unref_internal(request_payload_slice);
799
- grpc_grpclb_request_destroy(request);
800
789
  // Init other data associated with the LB call.
801
790
  grpc_metadata_array_init(&lb_initial_metadata_recv_);
802
791
  grpc_metadata_array_init(&lb_trailing_metadata_recv_);
@@ -940,27 +929,32 @@ void GrpcLb::BalancerCallState::MaybeSendClientLoadReportLocked(
940
929
 
941
930
  bool GrpcLb::BalancerCallState::LoadReportCountersAreZero(
942
931
  grpc_grpclb_request* request) {
943
- GrpcLbClientStats::DroppedCallCounts* drop_entries =
944
- static_cast<GrpcLbClientStats::DroppedCallCounts*>(
945
- request->client_stats.calls_finished_with_drop.arg);
946
- return request->client_stats.num_calls_started == 0 &&
947
- request->client_stats.num_calls_finished == 0 &&
948
- request->client_stats.num_calls_finished_with_client_failed_to_send ==
932
+ const grpc_lb_v1_ClientStats* cstats =
933
+ grpc_lb_v1_LoadBalanceRequest_client_stats(request);
934
+ if (cstats == nullptr) {
935
+ return true;
936
+ }
937
+ size_t drop_count;
938
+ grpc_lb_v1_ClientStats_calls_finished_with_drop(cstats, &drop_count);
939
+ return grpc_lb_v1_ClientStats_num_calls_started(cstats) == 0 &&
940
+ grpc_lb_v1_ClientStats_num_calls_finished(cstats) == 0 &&
941
+ grpc_lb_v1_ClientStats_num_calls_finished_with_client_failed_to_send(
942
+ cstats) == 0 &&
943
+ grpc_lb_v1_ClientStats_num_calls_finished_known_received(cstats) ==
949
944
  0 &&
950
- request->client_stats.num_calls_finished_known_received == 0 &&
951
- (drop_entries == nullptr || drop_entries->size() == 0);
945
+ drop_count == 0;
952
946
  }
953
947
 
954
948
  void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
955
949
  // Construct message payload.
956
950
  GPR_ASSERT(send_message_payload_ == nullptr);
951
+ upb::Arena arena;
957
952
  grpc_grpclb_request* request =
958
- grpc_grpclb_load_report_request_create(client_stats_.get());
953
+ grpc_grpclb_load_report_request_create(client_stats_.get(), arena.ptr());
959
954
  // Skip client load report if the counters were all zero in the last
960
955
  // report and they are still zero in this one.
961
956
  if (LoadReportCountersAreZero(request)) {
962
957
  if (last_client_load_report_counters_were_zero_) {
963
- grpc_grpclb_request_destroy(request);
964
958
  ScheduleNextClientLoadReportLocked();
965
959
  return;
966
960
  }
@@ -968,11 +962,11 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
968
962
  } else {
969
963
  last_client_load_report_counters_were_zero_ = false;
970
964
  }
971
- grpc_slice request_payload_slice = grpc_grpclb_request_encode(request);
965
+ grpc_slice request_payload_slice =
966
+ grpc_grpclb_request_encode(request, arena.ptr());
972
967
  send_message_payload_ =
973
968
  grpc_raw_byte_buffer_create(&request_payload_slice, 1);
974
969
  grpc_slice_unref_internal(request_payload_slice);
975
- grpc_grpclb_request_destroy(request);
976
970
  // Send the report.
977
971
  grpc_op op;
978
972
  memset(&op, 0, sizeof(op));
@@ -1034,16 +1028,20 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
1034
1028
  grpc_byte_buffer_reader_destroy(&bbr);
1035
1029
  grpc_byte_buffer_destroy(lb_calld->recv_message_payload_);
1036
1030
  lb_calld->recv_message_payload_ = nullptr;
1037
- grpc_grpclb_initial_response* initial_response;
1031
+ const grpc_grpclb_initial_response* initial_response;
1038
1032
  grpc_grpclb_serverlist* serverlist;
1033
+ upb::Arena arena;
1039
1034
  if (!lb_calld->seen_initial_response_ &&
1040
- (initial_response = grpc_grpclb_initial_response_parse(response_slice)) !=
1041
- nullptr) {
1035
+ (initial_response = grpc_grpclb_initial_response_parse(
1036
+ response_slice, arena.ptr())) != nullptr) {
1042
1037
  // Have NOT seen initial response, look for initial response.
1043
- if (initial_response->has_client_stats_report_interval) {
1044
- lb_calld->client_stats_report_interval_ = GPR_MAX(
1045
- GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis(
1046
- &initial_response->client_stats_report_interval));
1038
+ const google_protobuf_Duration* client_stats_report_interval =
1039
+ grpc_lb_v1_InitialLoadBalanceResponse_client_stats_report_interval(
1040
+ initial_response);
1041
+ if (client_stats_report_interval != nullptr) {
1042
+ lb_calld->client_stats_report_interval_ =
1043
+ GPR_MAX(GPR_MS_PER_SEC,
1044
+ grpc_grpclb_duration_to_millis(client_stats_report_interval));
1047
1045
  if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) {
1048
1046
  gpr_log(GPR_INFO,
1049
1047
  "[grpclb %p] lb_calld=%p: Received initial LB response "
@@ -1058,7 +1056,6 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
1058
1056
  "client load reporting NOT enabled",
1059
1057
  grpclb_policy, lb_calld);
1060
1058
  }
1061
- grpc_grpclb_initial_response_destroy(initial_response);
1062
1059
  lb_calld->seen_initial_response_ = true;
1063
1060
  } else if ((serverlist = grpc_grpclb_response_parse_serverlist(
1064
1061
  response_slice)) != nullptr) {
@@ -1267,7 +1264,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
1267
1264
  // the LB channel.
1268
1265
  GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
1269
1266
  // The LB channel should use the authority indicated by the target
1270
- // authority table (see \a grpc_lb_policy_grpclb_modify_lb_channel_args),
1267
+ // authority table (see \a ModifyGrpclbBalancerChannelArgs),
1271
1268
  // as opposed to the authority from the parent channel.
1272
1269
  GRPC_ARG_DEFAULT_AUTHORITY,
1273
1270
  // Just as for \a GRPC_ARG_DEFAULT_AUTHORITY, the LB channel should be
@@ -1303,7 +1300,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
1303
1300
  args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add.data(),
1304
1301
  args_to_add.size());
1305
1302
  // Make any necessary modifications for security.
1306
- return grpc_lb_policy_grpclb_modify_lb_channel_args(addresses, new_args);
1303
+ return ModifyGrpclbBalancerChannelArgs(addresses, new_args);
1307
1304
  }
1308
1305
 
1309
1306
  //
@@ -1479,8 +1476,7 @@ void GrpcLb::ProcessAddressesAndChannelArgsLocked(
1479
1476
  if (lb_channel_ == nullptr) {
1480
1477
  char* uri_str;
1481
1478
  gpr_asprintf(&uri_str, "fake:///%s", server_name_);
1482
- lb_channel_ =
1483
- channel_control_helper()->CreateChannel(uri_str, *lb_channel_args);
1479
+ lb_channel_ = CreateGrpclbBalancerChannel(uri_str, *lb_channel_args);
1484
1480
  GPR_ASSERT(lb_channel_ != nullptr);
1485
1481
  gpr_free(uri_str);
1486
1482
  }