grpc 1.28.0 → 1.30.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 (497) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +7694 -11190
  3. data/include/grpc/grpc.h +2 -2
  4. data/include/grpc/grpc_security.h +22 -9
  5. data/include/grpc/grpc_security_constants.h +1 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +19 -21
  7. data/include/grpc/impl/codegen/port_platform.h +6 -2
  8. data/include/grpc/module.modulemap +24 -39
  9. data/src/core/ext/filters/client_channel/backend_metric.cc +7 -4
  10. data/src/core/ext/filters/client_channel/client_channel.cc +203 -236
  11. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -2
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +7 -22
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
  14. data/src/core/ext/filters/client_channel/http_proxy.cc +17 -10
  15. data/src/core/ext/filters/client_channel/lb_policy.cc +19 -18
  16. data/src/core/ext/filters/client_channel/lb_policy.h +42 -33
  17. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +83 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +99 -0
  19. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +10 -4
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +240 -301
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +11 -9
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +3 -2
  25. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +871 -0
  26. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +5 -11
  28. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +734 -0
  29. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +84 -37
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +938 -0
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +528 -0
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +1 -2
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +834 -0
  34. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +6 -2
  35. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +2 -1
  36. data/src/core/ext/filters/client_channel/parse_address.cc +22 -21
  37. data/src/core/ext/filters/client_channel/resolver.cc +5 -8
  38. data/src/core/ext/filters/client_channel/resolver.h +12 -14
  39. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +73 -59
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +35 -35
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +8 -7
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +16 -20
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +4 -4
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +72 -117
  45. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +184 -133
  46. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -3
  47. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +7 -4
  48. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +40 -43
  49. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +93 -102
  50. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +0 -4
  51. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +2 -2
  52. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +32 -5
  53. data/src/core/ext/filters/client_channel/resolver_factory.h +2 -2
  54. data/src/core/ext/filters/client_channel/resolver_registry.cc +6 -3
  55. data/src/core/ext/filters/client_channel/resolver_registry.h +8 -8
  56. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +16 -16
  57. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +19 -16
  58. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +20 -31
  59. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +4 -3
  60. data/src/core/ext/filters/client_channel/server_address.cc +6 -9
  61. data/src/core/ext/filters/client_channel/server_address.h +6 -12
  62. data/src/core/ext/filters/client_channel/service_config.cc +104 -144
  63. data/src/core/ext/filters/client_channel/service_config.h +28 -98
  64. data/src/core/ext/filters/client_channel/service_config_call_data.h +68 -0
  65. data/src/core/ext/filters/client_channel/service_config_parser.cc +87 -0
  66. data/src/core/ext/filters/client_channel/service_config_parser.h +89 -0
  67. data/src/core/ext/filters/client_channel/subchannel.cc +54 -24
  68. data/src/core/ext/filters/client_channel/subchannel.h +35 -11
  69. data/src/core/ext/filters/client_channel/xds/xds_api.cc +348 -221
  70. data/src/core/ext/filters/client_channel/xds/xds_api.h +37 -37
  71. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +44 -49
  72. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +4 -3
  73. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +4 -2
  74. data/src/core/ext/filters/client_channel/xds/xds_client.cc +532 -339
  75. data/src/core/ext/filters/client_channel/xds/xds_client.h +57 -22
  76. data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +11 -12
  77. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +31 -19
  78. data/src/core/ext/filters/http/client/http_client_filter.cc +23 -28
  79. data/src/core/ext/filters/http/client_authority_filter.cc +4 -4
  80. data/src/core/ext/filters/http/http_filters_plugin.cc +27 -12
  81. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +258 -221
  82. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +358 -0
  83. data/src/core/ext/filters/http/message_compress/message_decompress_filter.h +29 -0
  84. data/src/core/ext/filters/message_size/message_size_filter.cc +7 -10
  85. data/src/core/ext/filters/message_size/message_size_filter.h +4 -4
  86. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +4 -4
  87. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +4 -6
  88. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +23 -22
  89. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
  90. data/src/core/ext/transport/chttp2/transport/flow_control.cc +3 -3
  91. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -3
  92. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -3
  93. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -3
  94. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -3
  95. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -3
  96. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +29 -16
  97. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -3
  98. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +2 -3
  99. data/src/core/ext/transport/chttp2/transport/hpack_table.h +2 -2
  100. data/src/core/ext/transport/chttp2/transport/http2_settings.h +4 -5
  101. data/src/core/ext/transport/chttp2/transport/huffsyms.h +2 -3
  102. data/src/core/ext/transport/chttp2/transport/internal.h +14 -21
  103. data/src/core/ext/transport/chttp2/transport/stream_map.h +2 -3
  104. data/src/core/ext/transport/chttp2/transport/writing.cc +15 -8
  105. data/src/core/ext/transport/inproc/inproc_transport.cc +19 -0
  106. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +4 -229
  107. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +5 -875
  108. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +114 -0
  109. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +418 -0
  110. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +72 -0
  111. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +197 -0
  112. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +105 -0
  113. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +378 -0
  114. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +1 -0
  115. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +21 -8
  116. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +43 -7
  117. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +1 -0
  118. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +1 -0
  119. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +1 -0
  120. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +2 -1
  121. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.c +35 -0
  122. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +78 -0
  123. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +47 -26
  124. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +115 -65
  125. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +1 -0
  126. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +34 -0
  127. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +72 -0
  128. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +2 -1
  129. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +24 -20
  130. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +28 -13
  131. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +1 -0
  132. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +38 -18
  133. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +88 -6
  134. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.c +34 -0
  135. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +89 -0
  136. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +1 -0
  137. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +1 -0
  138. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +1 -0
  139. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +1 -0
  140. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +9 -6
  141. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +12 -4
  142. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +1 -0
  143. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.c +1 -0
  144. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +15 -10
  145. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +16 -0
  146. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +1 -0
  147. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +2 -1
  148. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +1 -0
  149. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.c +1 -0
  150. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +1 -0
  151. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +1 -0
  152. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +63 -41
  153. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +173 -77
  154. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +1 -0
  155. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.c +1 -0
  156. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +1 -0
  157. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +48 -28
  158. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +90 -30
  159. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.c +1 -0
  160. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +51 -0
  161. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +125 -0
  162. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +1 -0
  163. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +4 -2
  164. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +4 -0
  165. data/src/core/ext/upb-generated/envoy/type/http.upb.c +1 -0
  166. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +16 -0
  167. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +36 -0
  168. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +1 -0
  169. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +1 -0
  170. data/src/core/ext/upb-generated/envoy/type/percent.upb.c +1 -0
  171. data/src/core/ext/upb-generated/envoy/type/range.upb.c +1 -0
  172. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.c +1 -0
  173. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +1 -0
  174. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +9 -8
  175. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +30 -24
  176. data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +28 -0
  177. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +65 -0
  178. data/src/core/ext/upb-generated/validate/validate.upb.c +21 -20
  179. data/src/core/ext/upb-generated/validate/validate.upb.h +69 -63
  180. data/src/core/lib/channel/channel_args.cc +15 -14
  181. data/src/core/lib/channel/channel_args.h +3 -1
  182. data/src/core/lib/channel/channel_stack.h +20 -13
  183. data/src/core/lib/channel/channelz.cc +5 -6
  184. data/src/core/lib/channel/channelz.h +3 -2
  185. data/src/core/lib/channel/channelz_registry.cc +5 -3
  186. data/src/core/lib/channel/connected_channel.cc +7 -5
  187. data/src/core/lib/channel/context.h +1 -1
  188. data/src/core/lib/channel/handshaker.cc +11 -13
  189. data/src/core/lib/channel/handshaker.h +4 -2
  190. data/src/core/lib/channel/handshaker_registry.cc +5 -17
  191. data/src/core/lib/channel/status_util.cc +2 -3
  192. data/src/core/lib/compression/message_compress.cc +5 -1
  193. data/src/core/lib/debug/stats.cc +21 -27
  194. data/src/core/lib/debug/stats.h +3 -1
  195. data/src/core/lib/gpr/spinlock.h +2 -3
  196. data/src/core/lib/gpr/string.cc +2 -26
  197. data/src/core/lib/gpr/string.h +0 -16
  198. data/src/core/lib/gpr/sync_abseil.cc +2 -0
  199. data/src/core/lib/gpr/time.cc +4 -0
  200. data/src/core/lib/gpr/time_posix.cc +1 -1
  201. data/src/core/lib/gprpp/atomic.h +6 -6
  202. data/src/core/lib/gprpp/fork.cc +1 -1
  203. data/src/core/lib/gprpp/host_port.cc +29 -35
  204. data/src/core/lib/gprpp/host_port.h +14 -17
  205. data/src/core/lib/gprpp/map.h +5 -11
  206. data/src/core/lib/gprpp/ref_counted_ptr.h +5 -0
  207. data/src/core/lib/http/format_request.cc +46 -65
  208. data/src/core/lib/http/httpcli.cc +2 -3
  209. data/src/core/lib/http/httpcli.h +2 -3
  210. data/src/core/lib/http/httpcli_security_connector.cc +5 -5
  211. data/src/core/lib/http/parser.h +2 -3
  212. data/src/core/lib/iomgr/buffer_list.h +22 -21
  213. data/src/core/lib/iomgr/call_combiner.h +3 -2
  214. data/src/core/lib/iomgr/cfstream_handle.cc +3 -2
  215. data/src/core/lib/iomgr/closure.h +2 -3
  216. data/src/core/lib/iomgr/dualstack_socket_posix.cc +47 -0
  217. data/src/core/lib/iomgr/endpoint_cfstream.cc +2 -3
  218. data/src/core/lib/iomgr/endpoint_pair.h +2 -3
  219. data/src/core/lib/iomgr/error.cc +6 -9
  220. data/src/core/lib/iomgr/error.h +0 -1
  221. data/src/core/lib/iomgr/ev_apple.cc +356 -0
  222. data/src/core/lib/iomgr/ev_apple.h +43 -0
  223. data/src/core/lib/iomgr/ev_epoll1_linux.cc +20 -23
  224. data/src/core/lib/iomgr/ev_epollex_linux.cc +2 -3
  225. data/src/core/lib/iomgr/ev_poll_posix.cc +3 -3
  226. data/src/core/lib/iomgr/ev_posix.cc +2 -3
  227. data/src/core/lib/iomgr/exec_ctx.h +14 -2
  228. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +84 -20
  229. data/src/core/lib/iomgr/pollset_set_custom.cc +10 -10
  230. data/src/core/lib/{gprpp/optional.h → iomgr/pollset_uv.h} +11 -12
  231. data/src/core/lib/iomgr/port.h +1 -0
  232. data/src/core/lib/iomgr/python_util.h +46 -0
  233. data/src/core/lib/iomgr/resolve_address.h +4 -6
  234. data/src/core/lib/iomgr/resolve_address_custom.cc +29 -39
  235. data/src/core/lib/iomgr/resolve_address_custom.h +4 -2
  236. data/src/core/lib/iomgr/resolve_address_posix.cc +10 -11
  237. data/src/core/lib/iomgr/resolve_address_windows.cc +8 -17
  238. data/src/core/lib/iomgr/resource_quota.cc +4 -6
  239. data/src/core/lib/iomgr/sockaddr_utils.cc +23 -29
  240. data/src/core/lib/iomgr/sockaddr_utils.h +9 -14
  241. data/src/core/lib/iomgr/socket_factory_posix.h +2 -3
  242. data/src/core/lib/iomgr/socket_mutator.h +2 -3
  243. data/src/core/lib/iomgr/socket_utils_common_posix.cc +7 -26
  244. data/src/core/lib/iomgr/socket_utils_posix.h +3 -0
  245. data/src/core/lib/iomgr/tcp_client_cfstream.cc +5 -7
  246. data/src/core/lib/iomgr/tcp_client_posix.cc +8 -5
  247. data/src/core/lib/iomgr/tcp_client_windows.cc +2 -3
  248. data/src/core/lib/iomgr/tcp_custom.cc +2 -3
  249. data/src/core/lib/iomgr/tcp_server_custom.cc +5 -9
  250. data/src/core/lib/iomgr/tcp_server_posix.cc +5 -4
  251. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +5 -4
  252. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +8 -11
  253. data/src/core/lib/iomgr/tcp_uv.cc +3 -2
  254. data/src/core/lib/iomgr/time_averaged_stats.h +2 -3
  255. data/src/core/lib/iomgr/timer_generic.cc +2 -3
  256. data/src/core/lib/{gprpp/inlined_vector.h → iomgr/timer_generic.h} +19 -17
  257. data/src/core/lib/iomgr/timer_heap.h +2 -3
  258. data/src/core/lib/iomgr/udp_server.cc +9 -14
  259. data/src/core/lib/json/json.h +3 -2
  260. data/src/core/lib/json/json_reader.cc +5 -5
  261. data/src/core/lib/json/json_writer.cc +13 -12
  262. data/src/core/lib/security/credentials/composite/composite_credentials.cc +12 -0
  263. data/src/core/lib/security/credentials/composite/composite_credentials.h +6 -3
  264. data/src/core/lib/security/credentials/credentials.cc +0 -84
  265. data/src/core/lib/security/credentials/credentials.h +8 -59
  266. data/src/core/lib/security/credentials/fake/fake_credentials.h +4 -0
  267. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +3 -8
  268. data/src/core/lib/security/credentials/iam/iam_credentials.cc +8 -6
  269. data/src/core/lib/security/credentials/iam/iam_credentials.h +4 -0
  270. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  271. data/src/core/lib/security/credentials/jwt/json_token.h +2 -5
  272. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +12 -0
  273. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +8 -15
  274. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -3
  275. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +55 -27
  276. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +9 -3
  277. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +13 -0
  278. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
  279. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -13
  280. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +38 -11
  281. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +21 -6
  282. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +7 -7
  283. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +3 -2
  284. data/src/core/lib/security/security_connector/local/local_security_connector.cc +1 -1
  285. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  286. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +20 -25
  287. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +4 -6
  288. data/src/core/lib/security/security_connector/ssl_utils.cc +59 -12
  289. data/src/core/lib/security/security_connector/ssl_utils.h +12 -10
  290. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +77 -51
  291. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +27 -5
  292. data/src/core/lib/security/transport/client_auth_filter.cc +1 -2
  293. data/src/core/lib/slice/slice_intern.cc +2 -3
  294. data/src/core/lib/slice/slice_internal.h +14 -0
  295. data/src/core/lib/slice/slice_utils.h +9 -0
  296. data/src/core/lib/surface/byte_buffer_reader.cc +2 -47
  297. data/src/core/lib/surface/call.cc +2 -3
  298. data/src/core/lib/surface/call_log_batch.cc +50 -58
  299. data/src/core/lib/surface/channel.cc +53 -31
  300. data/src/core/lib/surface/channel.h +35 -4
  301. data/src/core/lib/surface/channel_ping.cc +2 -3
  302. data/src/core/lib/surface/completion_queue.cc +33 -33
  303. data/src/core/lib/surface/event_string.cc +18 -25
  304. data/src/core/lib/surface/event_string.h +3 -1
  305. data/src/core/lib/surface/init_secure.cc +1 -4
  306. data/src/core/lib/surface/server.cc +570 -369
  307. data/src/core/lib/surface/server.h +32 -0
  308. data/src/core/lib/surface/version.cc +2 -2
  309. data/src/core/lib/transport/byte_stream.h +7 -2
  310. data/src/core/lib/transport/connectivity_state.cc +7 -6
  311. data/src/core/lib/transport/connectivity_state.h +5 -3
  312. data/src/core/lib/transport/metadata.cc +3 -3
  313. data/src/core/lib/transport/metadata_batch.h +2 -3
  314. data/src/core/lib/transport/static_metadata.h +1 -1
  315. data/src/core/lib/transport/status_conversion.cc +6 -14
  316. data/src/core/lib/transport/transport.cc +2 -3
  317. data/src/core/lib/transport/transport.h +3 -2
  318. data/src/core/lib/transport/transport_op_string.cc +61 -102
  319. data/src/core/lib/uri/uri_parser.h +2 -3
  320. data/src/core/plugin_registry/grpc_plugin_registry.cc +20 -4
  321. data/src/core/tsi/alts/crypt/aes_gcm.cc +0 -2
  322. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +8 -1
  323. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +8 -4
  324. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +32 -2
  325. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +9 -1
  326. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h +2 -3
  327. data/src/core/tsi/fake_transport_security.cc +10 -15
  328. data/src/core/tsi/ssl/session_cache/ssl_session.h +0 -2
  329. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +0 -2
  330. data/src/core/tsi/ssl_transport_security.cc +52 -39
  331. data/src/core/tsi/ssl_transport_security.h +8 -8
  332. data/src/core/tsi/ssl_types.h +0 -2
  333. data/src/core/tsi/transport_security.h +6 -9
  334. data/src/core/tsi/transport_security_grpc.h +2 -3
  335. data/src/core/tsi/transport_security_interface.h +3 -3
  336. data/src/ruby/ext/grpc/rb_call.c +9 -1
  337. data/src/ruby/lib/grpc/errors.rb +103 -42
  338. data/src/ruby/lib/grpc/generic/active_call.rb +2 -3
  339. data/src/ruby/lib/grpc/generic/interceptors.rb +4 -4
  340. data/src/ruby/lib/grpc/generic/rpc_server.rb +9 -10
  341. data/src/ruby/lib/grpc/generic/service.rb +5 -4
  342. data/src/ruby/lib/grpc/structs.rb +1 -1
  343. data/src/ruby/lib/grpc/version.rb +1 -1
  344. data/src/ruby/pb/generate_proto_ruby.sh +5 -3
  345. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +11 -0
  346. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +16 -0
  347. data/src/ruby/spec/debug_message_spec.rb +134 -0
  348. data/src/ruby/spec/generic/service_spec.rb +2 -0
  349. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +5 -0
  350. data/src/ruby/spec/pb/codegen/package_option_spec.rb +2 -0
  351. data/src/ruby/spec/testdata/ca.pem +18 -13
  352. data/src/ruby/spec/testdata/client.key +26 -14
  353. data/src/ruby/spec/testdata/client.pem +18 -12
  354. data/src/ruby/spec/testdata/server1.key +26 -14
  355. data/src/ruby/spec/testdata/server1.pem +20 -14
  356. data/third_party/abseil-cpp/absl/time/civil_time.cc +175 -0
  357. data/third_party/abseil-cpp/absl/time/civil_time.h +538 -0
  358. data/third_party/abseil-cpp/absl/time/clock.cc +569 -0
  359. data/third_party/abseil-cpp/absl/time/clock.h +74 -0
  360. data/third_party/abseil-cpp/absl/time/duration.cc +922 -0
  361. data/third_party/abseil-cpp/absl/time/format.cc +153 -0
  362. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time.h +332 -0
  363. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +622 -0
  364. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +384 -0
  365. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +102 -0
  366. data/third_party/abseil-cpp/absl/time/internal/cctz/src/civil_time_detail.cc +94 -0
  367. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +140 -0
  368. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.h +52 -0
  369. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +922 -0
  370. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.cc +45 -0
  371. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.h +76 -0
  372. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +121 -0
  373. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +93 -0
  374. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +958 -0
  375. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +138 -0
  376. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +308 -0
  377. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.h +55 -0
  378. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +187 -0
  379. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.cc +159 -0
  380. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.h +132 -0
  381. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +122 -0
  382. data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +115 -0
  383. data/third_party/abseil-cpp/absl/time/internal/get_current_time_chrono.inc +31 -0
  384. data/third_party/abseil-cpp/absl/time/internal/get_current_time_posix.inc +24 -0
  385. data/third_party/abseil-cpp/absl/time/time.cc +499 -0
  386. data/third_party/abseil-cpp/absl/time/time.h +1584 -0
  387. data/third_party/boringssl-with-bazel/err_data.c +329 -297
  388. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/derive_key.c +1 -1
  389. data/third_party/boringssl-with-bazel/src/crypto/cpu-arm-linux.c +7 -5
  390. data/third_party/boringssl-with-bazel/src/crypto/cpu-intel.c +13 -4
  391. data/third_party/boringssl-with-bazel/src/crypto/crypto.c +11 -0
  392. data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/curve25519.c +18 -26
  393. data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/curve25519_tables.h +13 -21
  394. data/third_party/boringssl-with-bazel/src/{third_party/fiat → crypto/curve25519}/internal.h +14 -22
  395. data/third_party/boringssl-with-bazel/src/crypto/curve25519/spake25519.c +1 -1
  396. data/third_party/boringssl-with-bazel/src/crypto/dh/dh.c +15 -0
  397. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +10 -0
  398. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +425 -0
  399. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +78 -0
  400. data/third_party/boringssl-with-bazel/src/crypto/ecdh_extra/ecdh_extra.c +2 -2
  401. data/third_party/boringssl-with-bazel/src/crypto/err/err.c +33 -32
  402. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/aes_nohw.c +1 -1
  403. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +2 -1
  404. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/exponentiation.c +3 -3
  405. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +14 -11
  406. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery.c +8 -8
  407. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/mul.c +30 -154
  408. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digests.c +16 -0
  409. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +289 -117
  410. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +13 -27
  411. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_montgomery.c +96 -55
  412. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/felem.c +25 -7
  413. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +432 -160
  414. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/oct.c +63 -71
  415. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +5 -14
  416. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64-table.h +9481 -9485
  417. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64.c +80 -99
  418. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +736 -0
  419. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256_table.h +297 -0
  420. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/scalar.c +90 -11
  421. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple.c +125 -148
  422. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +189 -3
  423. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/wnaf.c +61 -18
  424. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdh/ecdh.c +2 -2
  425. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +20 -5
  426. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.c +137 -0
  427. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.h +49 -0
  428. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/getrandom_fillin.h +64 -0
  429. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +41 -5
  430. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +32 -17
  431. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +24 -114
  432. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/blinding.c +4 -0
  433. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +1 -0
  434. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +51 -38
  435. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +15 -1
  436. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +44 -35
  437. data/third_party/boringssl-with-bazel/src/crypto/mem.c +29 -12
  438. data/third_party/boringssl-with-bazel/src/crypto/obj/obj_dat.h +15 -1
  439. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/deterministic.c +6 -10
  440. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/windows.c +16 -0
  441. data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +4 -0
  442. data/third_party/boringssl-with-bazel/src/crypto/thread_win.c +4 -0
  443. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +278 -0
  444. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +1474 -0
  445. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +720 -0
  446. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +16 -0
  447. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +5 -0
  448. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +4 -3
  449. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +5 -1
  450. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +9 -4
  451. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +20 -0
  452. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +1 -0
  453. data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +16 -0
  454. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +6 -0
  455. data/third_party/boringssl-with-bazel/src/include/openssl/err.h +2 -0
  456. data/third_party/boringssl-with-bazel/src/include/openssl/nid.h +5 -0
  457. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +3 -17
  458. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +31 -0
  459. data/third_party/boringssl-with-bazel/src/include/openssl/sha.h +26 -0
  460. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +172 -77
  461. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +1 -0
  462. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +291 -0
  463. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +5 -3
  464. data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +1 -0
  465. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +0 -4
  466. data/third_party/boringssl-with-bazel/src/ssl/d1_lib.cc +3 -3
  467. data/third_party/boringssl-with-bazel/src/ssl/dtls_method.cc +13 -4
  468. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +146 -57
  469. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +14 -3
  470. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +28 -20
  471. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +12 -4
  472. data/third_party/boringssl-with-bazel/src/ssl/internal.h +64 -47
  473. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +10 -10
  474. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
  475. data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +21 -21
  476. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +29 -0
  477. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +4 -0
  478. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +6 -1
  479. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +13 -2
  480. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +64 -5
  481. data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +6 -0
  482. data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +6 -2
  483. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +47 -53
  484. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -1
  485. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +98 -27
  486. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +23 -75
  487. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +50 -20
  488. data/third_party/boringssl-with-bazel/src/ssl/tls_method.cc +63 -25
  489. data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_32.h +245 -175
  490. data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64.h +135 -75
  491. data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_32.h +1593 -1672
  492. data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_64.h +512 -503
  493. metadata +111 -37
  494. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +0 -1754
  495. data/src/core/lib/gprpp/string_view.h +0 -60
  496. data/src/core/tsi/grpc_shadow_boringssl.h +0 -3311
  497. data/third_party/boringssl-with-bazel/src/third_party/fiat/p256.c +0 -1063
@@ -18,6 +18,8 @@
18
18
 
19
19
  #include <string.h>
20
20
 
21
+ #include "absl/strings/str_cat.h"
22
+
21
23
  #include "src/core/ext/filters/client_channel/lb_policy.h"
22
24
  #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
23
25
  #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
@@ -37,9 +39,9 @@ namespace {
37
39
  constexpr char kCds[] = "cds_experimental";
38
40
 
39
41
  // Config for this LB policy.
40
- class CdsConfig : public LoadBalancingPolicy::Config {
42
+ class CdsLbConfig : public LoadBalancingPolicy::Config {
41
43
  public:
42
- explicit CdsConfig(std::string cluster) : cluster_(std::move(cluster)) {}
44
+ explicit CdsLbConfig(std::string cluster) : cluster_(std::move(cluster)) {}
43
45
  const std::string& cluster() const { return cluster_; }
44
46
  const char* name() const override { return kCds; }
45
47
 
@@ -50,7 +52,7 @@ class CdsConfig : public LoadBalancingPolicy::Config {
50
52
  // CDS LB policy.
51
53
  class CdsLb : public LoadBalancingPolicy {
52
54
  public:
53
- explicit CdsLb(Args args);
55
+ CdsLb(RefCountedPtr<XdsClient> xds_client, Args args);
54
56
 
55
57
  const char* name() const override { return kCds; }
56
58
 
@@ -65,6 +67,7 @@ class CdsLb : public LoadBalancingPolicy {
65
67
  : parent_(std::move(parent)) {}
66
68
  void OnClusterChanged(XdsApi::CdsUpdate cluster_data) override;
67
69
  void OnError(grpc_error* error) override;
70
+ void OnResourceDoesNotExist() override;
68
71
 
69
72
  private:
70
73
  RefCountedPtr<CdsLb> parent_;
@@ -79,7 +82,8 @@ class CdsLb : public LoadBalancingPolicy {
79
82
  void UpdateState(grpc_connectivity_state state,
80
83
  std::unique_ptr<SubchannelPicker> picker) override;
81
84
  void RequestReresolution() override;
82
- void AddTraceEvent(TraceSeverity severity, StringView message) override;
85
+ void AddTraceEvent(TraceSeverity severity,
86
+ absl::string_view message) override;
83
87
 
84
88
  private:
85
89
  RefCountedPtr<CdsLb> parent_;
@@ -89,7 +93,9 @@ class CdsLb : public LoadBalancingPolicy {
89
93
 
90
94
  void ShutdownLocked() override;
91
95
 
92
- RefCountedPtr<CdsConfig> config_;
96
+ void MaybeDestroyChildPolicyLocked();
97
+
98
+ RefCountedPtr<CdsLbConfig> config_;
93
99
 
94
100
  // Current channel args from the resolver.
95
101
  const grpc_channel_args* args_ = nullptr;
@@ -124,21 +130,37 @@ void CdsLb::ClusterWatcher::OnClusterChanged(XdsApi::CdsUpdate cluster_data) {
124
130
  }
125
131
  // Construct config for child policy.
126
132
  Json::Object child_config = {
127
- {"edsServiceName",
128
- (cluster_data.eds_service_name.empty() ? parent_->config_->cluster()
129
- : cluster_data.eds_service_name)},
133
+ {"clusterName", parent_->config_->cluster()},
134
+ {"localityPickingPolicy",
135
+ Json::Array{
136
+ Json::Object{
137
+ {"weighted_target_experimental",
138
+ Json::Object{
139
+ {"targets", Json::Object()},
140
+ }},
141
+ },
142
+ }},
143
+ {"endpointPickingPolicy",
144
+ Json::Array{
145
+ Json::Object{
146
+ {"round_robin", Json::Object()},
147
+ },
148
+ }},
130
149
  };
150
+ if (!cluster_data.eds_service_name.empty()) {
151
+ child_config["edsServiceName"] = cluster_data.eds_service_name;
152
+ }
131
153
  if (cluster_data.lrs_load_reporting_server_name.has_value()) {
132
154
  child_config["lrsLoadReportingServerName"] =
133
155
  cluster_data.lrs_load_reporting_server_name.value();
134
156
  }
135
157
  Json json = Json::Array{
136
158
  Json::Object{
137
- {"xds_experimental", std::move(child_config)},
159
+ {"eds_experimental", std::move(child_config)},
138
160
  },
139
161
  };
140
162
  if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
141
- std::string json_str = json.Dump();
163
+ std::string json_str = json.Dump(/*indent=*/1);
142
164
  gpr_log(GPR_INFO, "[cdslb %p] generated config for child policy: %s",
143
165
  parent_.get(), json_str.c_str());
144
166
  }
@@ -152,23 +174,23 @@ void CdsLb::ClusterWatcher::OnClusterChanged(XdsApi::CdsUpdate cluster_data) {
152
174
  // Create child policy if not already present.
153
175
  if (parent_->child_policy_ == nullptr) {
154
176
  LoadBalancingPolicy::Args args;
155
- args.combiner = parent_->combiner();
177
+ args.work_serializer = parent_->work_serializer();
156
178
  args.args = parent_->args_;
157
179
  args.channel_control_helper = absl::make_unique<Helper>(parent_->Ref());
158
180
  parent_->child_policy_ =
159
- LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
160
- "xds_experimental", std::move(args));
181
+ LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(config->name(),
182
+ std::move(args));
161
183
  if (parent_->child_policy_ == nullptr) {
162
184
  OnError(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
163
- "failed to create xds_experimental child policy"));
185
+ "failed to create child policy"));
164
186
  return;
165
187
  }
166
188
  grpc_pollset_set_add_pollset_set(
167
189
  parent_->child_policy_->interested_parties(),
168
190
  parent_->interested_parties());
169
191
  if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
170
- gpr_log(GPR_INFO, "[cdslb %p] created child policy xds_experimental (%p)",
171
- parent_.get(), parent_->child_policy_.get());
192
+ gpr_log(GPR_INFO, "[cdslb %p] created child policy %s (%p)",
193
+ parent_.get(), config->name(), parent_->child_policy_.get());
172
194
  }
173
195
  }
174
196
  // Update child policy.
@@ -194,6 +216,21 @@ void CdsLb::ClusterWatcher::OnError(grpc_error* error) {
194
216
  }
195
217
  }
196
218
 
219
+ void CdsLb::ClusterWatcher::OnResourceDoesNotExist() {
220
+ gpr_log(GPR_ERROR,
221
+ "[cdslb %p] CDS resource for %s does not exist -- reporting "
222
+ "TRANSIENT_FAILURE",
223
+ parent_.get(), parent_->config_->cluster().c_str());
224
+ parent_->channel_control_helper()->UpdateState(
225
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
226
+ absl::make_unique<TransientFailurePicker>(
227
+ GRPC_ERROR_CREATE_FROM_COPIED_STRING(
228
+ absl::StrCat("CDS resource \"", parent_->config_->cluster(),
229
+ "\" does not exist")
230
+ .c_str())));
231
+ parent_->MaybeDestroyChildPolicyLocked();
232
+ }
233
+
197
234
  //
198
235
  // CdsLb::Helper
199
236
  //
@@ -206,7 +243,7 @@ RefCountedPtr CdsLb::Helper::CreateSubchannel(
206
243
 
207
244
  void CdsLb::Helper::UpdateState(grpc_connectivity_state state,
208
245
  std::unique_ptr<SubchannelPicker> picker) {
209
- if (parent_->shutting_down_) return;
246
+ if (parent_->shutting_down_ || parent_->child_policy_ == nullptr) return;
210
247
  if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
211
248
  gpr_log(GPR_INFO, "[cdslb %p] state updated by child: %s", this,
212
249
  ConnectivityStateName(state));
@@ -223,7 +260,8 @@ void CdsLb::Helper::RequestReresolution() {
223
260
  parent_->channel_control_helper()->RequestReresolution();
224
261
  }
225
262
 
226
- void CdsLb::Helper::AddTraceEvent(TraceSeverity severity, StringView message) {
263
+ void CdsLb::Helper::AddTraceEvent(TraceSeverity severity,
264
+ absl::string_view message) {
227
265
  if (parent_->shutting_down_) return;
228
266
  parent_->channel_control_helper()->AddTraceEvent(severity, message);
229
267
  }
@@ -232,9 +270,8 @@ void CdsLb::Helper::AddTraceEvent(TraceSeverity severity, StringView message) {
232
270
  // CdsLb
233
271
  //
234
272
 
235
- CdsLb::CdsLb(Args args)
236
- : LoadBalancingPolicy(std::move(args)),
237
- xds_client_(XdsClient::GetFromChannelArgs(*args.args)) {
273
+ CdsLb::CdsLb(RefCountedPtr<XdsClient> xds_client, Args args)
274
+ : LoadBalancingPolicy(std::move(args)), xds_client_(std::move(xds_client)) {
238
275
  if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
239
276
  gpr_log(GPR_INFO, "[cdslb %p] created -- using xds client %p from channel",
240
277
  this, xds_client_.get());
@@ -253,24 +290,27 @@ void CdsLb::ShutdownLocked() {
253
290
  gpr_log(GPR_INFO, "[cdslb %p] shutting down", this);
254
291
  }
255
292
  shutting_down_ = true;
256
- if (child_policy_ != nullptr) {
257
- grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
258
- interested_parties());
259
- child_policy_.reset();
260
- }
293
+ MaybeDestroyChildPolicyLocked();
261
294
  if (xds_client_ != nullptr) {
262
295
  if (cluster_watcher_ != nullptr) {
263
296
  if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
264
297
  gpr_log(GPR_INFO, "[cdslb %p] cancelling watch for cluster %s", this,
265
298
  config_->cluster().c_str());
266
299
  }
267
- xds_client_->CancelClusterDataWatch(
268
- StringView(config_->cluster().c_str()), cluster_watcher_);
300
+ xds_client_->CancelClusterDataWatch(config_->cluster(), cluster_watcher_);
269
301
  }
270
302
  xds_client_.reset();
271
303
  }
272
304
  }
273
305
 
306
+ void CdsLb::MaybeDestroyChildPolicyLocked() {
307
+ if (child_policy_ != nullptr) {
308
+ grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
309
+ interested_parties());
310
+ child_policy_.reset();
311
+ }
312
+ }
313
+
274
314
  void CdsLb::ResetBackoffLocked() {
275
315
  if (child_policy_ != nullptr) child_policy_->ResetBackoffLocked();
276
316
  }
@@ -294,9 +334,9 @@ void CdsLb::UpdateLocked(UpdateArgs args) {
294
334
  gpr_log(GPR_INFO, "[cdslb %p] cancelling watch for cluster %s", this,
295
335
  old_config->cluster().c_str());
296
336
  }
297
- xds_client_->CancelClusterDataWatch(
298
- StringView(old_config->cluster().c_str()), cluster_watcher_,
299
- /*delay_unsubscription=*/true);
337
+ xds_client_->CancelClusterDataWatch(old_config->cluster(),
338
+ cluster_watcher_,
339
+ /*delay_unsubscription=*/true);
300
340
  }
301
341
  if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
302
342
  gpr_log(GPR_INFO, "[cdslb %p] starting watch for cluster %s", this,
@@ -304,8 +344,7 @@ void CdsLb::UpdateLocked(UpdateArgs args) {
304
344
  }
305
345
  auto watcher = absl::make_unique<ClusterWatcher>(Ref());
306
346
  cluster_watcher_ = watcher.get();
307
- xds_client_->WatchClusterData(StringView(config_->cluster().c_str()),
308
- std::move(watcher));
347
+ xds_client_->WatchClusterData(config_->cluster(), std::move(watcher));
309
348
  }
310
349
  }
311
350
 
@@ -313,11 +352,19 @@ void CdsLb::UpdateLocked(UpdateArgs args) {
313
352
  // factory
314
353
  //
315
354
 
316
- class CdsFactory : public LoadBalancingPolicyFactory {
355
+ class CdsLbFactory : public LoadBalancingPolicyFactory {
317
356
  public:
318
357
  OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
319
358
  LoadBalancingPolicy::Args args) const override {
320
- return MakeOrphanable<CdsLb>(std::move(args));
359
+ RefCountedPtr<XdsClient> xds_client =
360
+ XdsClient::GetFromChannelArgs(*args.args);
361
+ if (xds_client == nullptr) {
362
+ gpr_log(GPR_ERROR,
363
+ "XdsClient not present in channel args -- cannot instantiate "
364
+ "cds LB policy");
365
+ return nullptr;
366
+ }
367
+ return MakeOrphanable<CdsLb>(std::move(xds_client), std::move(args));
321
368
  }
322
369
 
323
370
  const char* name() const override { return kCds; }
@@ -349,7 +396,7 @@ class CdsFactory : public LoadBalancingPolicyFactory {
349
396
  *error = GRPC_ERROR_CREATE_FROM_VECTOR("Cds Parser", &error_list);
350
397
  return nullptr;
351
398
  }
352
- return MakeRefCounted<CdsConfig>(std::move(cluster));
399
+ return MakeRefCounted<CdsLbConfig>(std::move(cluster));
353
400
  }
354
401
  };
355
402
 
@@ -364,7 +411,7 @@ class CdsFactory : public LoadBalancingPolicyFactory {
364
411
  void grpc_lb_policy_cds_init() {
365
412
  grpc_core::LoadBalancingPolicyRegistry::Builder::
366
413
  RegisterLoadBalancingPolicyFactory(
367
- absl::make_unique<grpc_core::CdsFactory>());
414
+ absl::make_unique<grpc_core::CdsLbFactory>());
368
415
  }
369
416
 
370
417
  void grpc_lb_policy_cds_shutdown() {}
@@ -0,0 +1,938 @@
1
+ //
2
+ // Copyright 2018 gRPC authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ //
16
+
17
+ #include <grpc/support/port_platform.h>
18
+
19
+ #include <inttypes.h>
20
+ #include <limits.h>
21
+
22
+ #include "absl/strings/str_cat.h"
23
+ #include "absl/types/optional.h"
24
+
25
+ #include <grpc/grpc.h>
26
+
27
+ #include "src/core/ext/filters/client_channel/client_channel.h"
28
+ #include "src/core/ext/filters/client_channel/lb_policy.h"
29
+ #include "src/core/ext/filters/client_channel/lb_policy/address_filtering.h"
30
+ #include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
31
+ #include "src/core/ext/filters/client_channel/lb_policy/xds/xds.h"
32
+ #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
33
+ #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
34
+ #include "src/core/ext/filters/client_channel/server_address.h"
35
+ #include "src/core/ext/filters/client_channel/xds/xds_channel_args.h"
36
+ #include "src/core/ext/filters/client_channel/xds/xds_client.h"
37
+ #include "src/core/ext/filters/client_channel/xds/xds_client_stats.h"
38
+ #include "src/core/lib/channel/channel_args.h"
39
+ #include "src/core/lib/gprpp/orphanable.h"
40
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
41
+ #include "src/core/lib/iomgr/timer.h"
42
+ #include "src/core/lib/iomgr/work_serializer.h"
43
+ #include "src/core/lib/uri/uri_parser.h"
44
+
45
+ #define GRPC_EDS_DEFAULT_FALLBACK_TIMEOUT 10000
46
+
47
+ namespace grpc_core {
48
+
49
+ TraceFlag grpc_lb_eds_trace(false, "eds_lb");
50
+
51
+ namespace {
52
+
53
+ constexpr char kEds[] = "eds_experimental";
54
+
55
+ // Config for EDS LB policy.
56
+ class EdsLbConfig : public LoadBalancingPolicy::Config {
57
+ public:
58
+ EdsLbConfig(std::string cluster_name, std::string eds_service_name,
59
+ absl::optional<std::string> lrs_load_reporting_server_name,
60
+ Json locality_picking_policy, Json endpoint_picking_policy)
61
+ : cluster_name_(std::move(cluster_name)),
62
+ eds_service_name_(std::move(eds_service_name)),
63
+ lrs_load_reporting_server_name_(
64
+ std::move(lrs_load_reporting_server_name)),
65
+ locality_picking_policy_(std::move(locality_picking_policy)),
66
+ endpoint_picking_policy_(std::move(endpoint_picking_policy)) {}
67
+
68
+ const char* name() const override { return kEds; }
69
+
70
+ const std::string& cluster_name() const { return cluster_name_; }
71
+ const std::string& eds_service_name() const { return eds_service_name_; }
72
+ const absl::optional<std::string>& lrs_load_reporting_server_name() const {
73
+ return lrs_load_reporting_server_name_;
74
+ };
75
+ const Json& locality_picking_policy() const {
76
+ return locality_picking_policy_;
77
+ }
78
+ const Json& endpoint_picking_policy() const {
79
+ return endpoint_picking_policy_;
80
+ }
81
+
82
+ private:
83
+ std::string cluster_name_;
84
+ std::string eds_service_name_;
85
+ absl::optional<std::string> lrs_load_reporting_server_name_;
86
+ Json locality_picking_policy_;
87
+ Json endpoint_picking_policy_;
88
+ };
89
+
90
+ // EDS LB policy.
91
+ class EdsLb : public LoadBalancingPolicy {
92
+ public:
93
+ explicit EdsLb(Args args);
94
+
95
+ const char* name() const override { return kEds; }
96
+
97
+ void UpdateLocked(UpdateArgs args) override;
98
+ void ResetBackoffLocked() override;
99
+
100
+ private:
101
+ class EndpointWatcher;
102
+
103
+ // A simple wrapper for ref-counting a picker from the child policy.
104
+ class ChildPickerWrapper : public RefCounted<ChildPickerWrapper> {
105
+ public:
106
+ explicit ChildPickerWrapper(std::unique_ptr<SubchannelPicker> picker)
107
+ : picker_(std::move(picker)) {}
108
+ PickResult Pick(PickArgs args) { return picker_->Pick(args); }
109
+
110
+ private:
111
+ std::unique_ptr<SubchannelPicker> picker_;
112
+ };
113
+
114
+ // A picker that handles drops.
115
+ class DropPicker : public SubchannelPicker {
116
+ public:
117
+ explicit DropPicker(EdsLb* eds_policy);
118
+
119
+ PickResult Pick(PickArgs args) override;
120
+
121
+ private:
122
+ RefCountedPtr<XdsApi::DropConfig> drop_config_;
123
+ RefCountedPtr<XdsClusterDropStats> drop_stats_;
124
+ RefCountedPtr<ChildPickerWrapper> child_picker_;
125
+ };
126
+
127
+ class Helper : public ChannelControlHelper {
128
+ public:
129
+ explicit Helper(RefCountedPtr<EdsLb> eds_policy)
130
+ : eds_policy_(std::move(eds_policy)) {}
131
+
132
+ ~Helper() { eds_policy_.reset(DEBUG_LOCATION, "Helper"); }
133
+
134
+ RefCountedPtr<SubchannelInterface> CreateSubchannel(
135
+ const grpc_channel_args& args) override;
136
+ void UpdateState(grpc_connectivity_state state,
137
+ std::unique_ptr<SubchannelPicker> picker) override;
138
+ // This is a no-op, because we get the addresses from the xds
139
+ // client, which is a watch-based API.
140
+ void RequestReresolution() override {}
141
+ void AddTraceEvent(TraceSeverity severity,
142
+ absl::string_view message) override;
143
+
144
+ private:
145
+ RefCountedPtr<EdsLb> eds_policy_;
146
+ };
147
+
148
+ ~EdsLb();
149
+
150
+ void ShutdownLocked() override;
151
+
152
+ void MaybeDestroyChildPolicyLocked();
153
+
154
+ void UpdatePriorityList(XdsApi::PriorityListUpdate priority_list_update);
155
+ void UpdateChildPolicyLocked();
156
+ OrphanablePtr<LoadBalancingPolicy> CreateChildPolicyLocked(
157
+ const grpc_channel_args* args);
158
+ ServerAddressList CreateChildPolicyAddressesLocked();
159
+ RefCountedPtr<Config> CreateChildPolicyConfigLocked();
160
+ grpc_channel_args* CreateChildPolicyArgsLocked(
161
+ const grpc_channel_args* args_in);
162
+ void MaybeUpdateDropPickerLocked();
163
+
164
+ // Caller must ensure that config_ is set before calling.
165
+ const absl::string_view GetEdsResourceName() const {
166
+ if (xds_client_from_channel_ == nullptr) return server_name_;
167
+ if (!config_->eds_service_name().empty()) {
168
+ return config_->eds_service_name();
169
+ }
170
+ return config_->cluster_name();
171
+ }
172
+
173
+ // Returns a pair containing the cluster and eds_service_name to use
174
+ // for LRS load reporting.
175
+ // Caller must ensure that config_ is set before calling.
176
+ std::pair<absl::string_view, absl::string_view> GetLrsClusterKey() const {
177
+ if (xds_client_from_channel_ == nullptr) return {server_name_, nullptr};
178
+ return {config_->cluster_name(), config_->eds_service_name()};
179
+ }
180
+
181
+ XdsClient* xds_client() const {
182
+ return xds_client_from_channel_ != nullptr ? xds_client_from_channel_.get()
183
+ : xds_client_.get();
184
+ }
185
+
186
+ // Server name from target URI.
187
+ std::string server_name_;
188
+
189
+ // Current channel args and config from the resolver.
190
+ const grpc_channel_args* args_ = nullptr;
191
+ RefCountedPtr<EdsLbConfig> config_;
192
+
193
+ // Internal state.
194
+ bool shutting_down_ = false;
195
+
196
+ // The xds client and endpoint watcher.
197
+ // If we get the XdsClient from the channel, we store it in
198
+ // xds_client_from_channel_; if we create it ourselves, we store it in
199
+ // xds_client_.
200
+ RefCountedPtr<XdsClient> xds_client_from_channel_;
201
+ OrphanablePtr<XdsClient> xds_client_;
202
+ // A pointer to the endpoint watcher, to be used when cancelling the watch.
203
+ // Note that this is not owned, so this pointer must never be derefernced.
204
+ EndpointWatcher* endpoint_watcher_ = nullptr;
205
+ // The latest data from the endpoint watcher.
206
+ XdsApi::PriorityListUpdate priority_list_update_;
207
+ // State used to retain child policy names for priority policy.
208
+ std::vector<size_t /*child_number*/> priority_child_numbers_;
209
+
210
+ RefCountedPtr<XdsApi::DropConfig> drop_config_;
211
+ RefCountedPtr<XdsClusterDropStats> drop_stats_;
212
+
213
+ OrphanablePtr<LoadBalancingPolicy> child_policy_;
214
+
215
+ // The latest state and picker returned from the child policy.
216
+ grpc_connectivity_state child_state_;
217
+ RefCountedPtr<ChildPickerWrapper> child_picker_;
218
+ };
219
+
220
+ //
221
+ // EdsLb::DropPicker
222
+ //
223
+
224
+ EdsLb::DropPicker::DropPicker(EdsLb* eds_policy)
225
+ : drop_config_(eds_policy->drop_config_),
226
+ drop_stats_(eds_policy->drop_stats_),
227
+ child_picker_(eds_policy->child_picker_) {
228
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
229
+ gpr_log(GPR_INFO, "[edslb %p] constructed new drop picker %p", eds_policy,
230
+ this);
231
+ }
232
+ }
233
+
234
+ EdsLb::PickResult EdsLb::DropPicker::Pick(PickArgs args) {
235
+ // Handle drop.
236
+ const std::string* drop_category;
237
+ if (drop_config_->ShouldDrop(&drop_category)) {
238
+ if (drop_stats_ != nullptr) drop_stats_->AddCallDropped(*drop_category);
239
+ PickResult result;
240
+ result.type = PickResult::PICK_COMPLETE;
241
+ return result;
242
+ }
243
+ // If we're not dropping all calls, we should always have a child picker.
244
+ if (child_picker_ == nullptr) { // Should never happen.
245
+ PickResult result;
246
+ result.type = PickResult::PICK_FAILED;
247
+ result.error =
248
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
249
+ "eds drop picker not given any child picker"),
250
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL);
251
+ return result;
252
+ }
253
+ // Not dropping, so delegate to child's picker.
254
+ return child_picker_->Pick(args);
255
+ }
256
+
257
+ //
258
+ // EdsLb::Helper
259
+ //
260
+
261
+ RefCountedPtr<SubchannelInterface> EdsLb::Helper::CreateSubchannel(
262
+ const grpc_channel_args& args) {
263
+ if (eds_policy_->shutting_down_) return nullptr;
264
+ return eds_policy_->channel_control_helper()->CreateSubchannel(args);
265
+ }
266
+
267
+ void EdsLb::Helper::UpdateState(grpc_connectivity_state state,
268
+ std::unique_ptr<SubchannelPicker> picker) {
269
+ if (eds_policy_->shutting_down_ || eds_policy_->child_policy_ == nullptr) {
270
+ return;
271
+ }
272
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
273
+ gpr_log(GPR_INFO, "[edslb %p] child policy updated state=%s picker=%p",
274
+ eds_policy_.get(), ConnectivityStateName(state), picker.get());
275
+ }
276
+ // Save the state and picker.
277
+ eds_policy_->child_state_ = state;
278
+ eds_policy_->child_picker_ =
279
+ MakeRefCounted<ChildPickerWrapper>(std::move(picker));
280
+ // Wrap the picker in a DropPicker and pass it up.
281
+ eds_policy_->MaybeUpdateDropPickerLocked();
282
+ }
283
+
284
+ void EdsLb::Helper::AddTraceEvent(TraceSeverity severity,
285
+ absl::string_view message) {
286
+ if (eds_policy_->shutting_down_) return;
287
+ eds_policy_->channel_control_helper()->AddTraceEvent(severity, message);
288
+ }
289
+
290
+ //
291
+ // EdsLb::EndpointWatcher
292
+ //
293
+
294
+ class EdsLb::EndpointWatcher : public XdsClient::EndpointWatcherInterface {
295
+ public:
296
+ explicit EndpointWatcher(RefCountedPtr<EdsLb> eds_policy)
297
+ : eds_policy_(std::move(eds_policy)) {}
298
+
299
+ ~EndpointWatcher() { eds_policy_.reset(DEBUG_LOCATION, "EndpointWatcher"); }
300
+
301
+ void OnEndpointChanged(XdsApi::EdsUpdate update) override {
302
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
303
+ gpr_log(GPR_INFO, "[edslb %p] Received EDS update from xds client",
304
+ eds_policy_.get());
305
+ }
306
+ // Update the drop config.
307
+ const bool drop_config_changed =
308
+ eds_policy_->drop_config_ == nullptr ||
309
+ *eds_policy_->drop_config_ != *update.drop_config;
310
+ if (drop_config_changed) {
311
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
312
+ gpr_log(GPR_INFO, "[edslb %p] Updating drop config", eds_policy_.get());
313
+ }
314
+ eds_policy_->drop_config_ = std::move(update.drop_config);
315
+ eds_policy_->MaybeUpdateDropPickerLocked();
316
+ } else if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
317
+ gpr_log(GPR_INFO, "[edslb %p] Drop config unchanged, ignoring",
318
+ eds_policy_.get());
319
+ }
320
+ // Update priority and locality info.
321
+ if (eds_policy_->child_policy_ == nullptr ||
322
+ eds_policy_->priority_list_update_ != update.priority_list_update) {
323
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
324
+ gpr_log(GPR_INFO, "[edslb %p] Updating priority list",
325
+ eds_policy_.get());
326
+ }
327
+ eds_policy_->UpdatePriorityList(std::move(update.priority_list_update));
328
+ } else if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
329
+ gpr_log(GPR_INFO, "[edslb %p] Priority list unchanged, ignoring",
330
+ eds_policy_.get());
331
+ }
332
+ }
333
+
334
+ void OnError(grpc_error* error) override {
335
+ gpr_log(GPR_ERROR, "[edslb %p] xds watcher reported error: %s",
336
+ eds_policy_.get(), grpc_error_string(error));
337
+ // Go into TRANSIENT_FAILURE if we have not yet created the child
338
+ // policy (i.e., we have not yet received data from xds). Otherwise,
339
+ // we keep running with the data we had previously.
340
+ if (eds_policy_->child_policy_ == nullptr) {
341
+ eds_policy_->channel_control_helper()->UpdateState(
342
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
343
+ absl::make_unique<TransientFailurePicker>(error));
344
+ } else {
345
+ GRPC_ERROR_UNREF(error);
346
+ }
347
+ }
348
+
349
+ void OnResourceDoesNotExist() override {
350
+ gpr_log(
351
+ GPR_ERROR,
352
+ "[edslb %p] EDS resource does not exist -- reporting TRANSIENT_FAILURE",
353
+ eds_policy_.get());
354
+ eds_policy_->channel_control_helper()->UpdateState(
355
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
356
+ absl::make_unique<TransientFailurePicker>(
357
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING(
358
+ "EDS resource does not exist")));
359
+ eds_policy_->MaybeDestroyChildPolicyLocked();
360
+ }
361
+
362
+ private:
363
+ RefCountedPtr<EdsLb> eds_policy_;
364
+ };
365
+
366
+ //
367
+ // EdsLb public methods
368
+ //
369
+
370
+ EdsLb::EdsLb(Args args)
371
+ : LoadBalancingPolicy(std::move(args)),
372
+ xds_client_from_channel_(XdsClient::GetFromChannelArgs(*args.args)) {
373
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
374
+ gpr_log(GPR_INFO, "[edslb %p] created -- xds client from channel: %p", this,
375
+ xds_client_from_channel_.get());
376
+ }
377
+ // Record server name.
378
+ const grpc_arg* arg = grpc_channel_args_find(args.args, GRPC_ARG_SERVER_URI);
379
+ const char* server_uri = grpc_channel_arg_get_string(arg);
380
+ GPR_ASSERT(server_uri != nullptr);
381
+ grpc_uri* uri = grpc_uri_parse(server_uri, true);
382
+ GPR_ASSERT(uri->path[0] != '\0');
383
+ server_name_ = uri->path[0] == '/' ? uri->path + 1 : uri->path;
384
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
385
+ gpr_log(GPR_INFO, "[edslb %p] server name from channel: %s", this,
386
+ server_name_.c_str());
387
+ }
388
+ grpc_uri_destroy(uri);
389
+ }
390
+
391
+ EdsLb::~EdsLb() {
392
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
393
+ gpr_log(GPR_INFO, "[edslb %p] destroying xds LB policy", this);
394
+ }
395
+ grpc_channel_args_destroy(args_);
396
+ }
397
+
398
+ void EdsLb::ShutdownLocked() {
399
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
400
+ gpr_log(GPR_INFO, "[edslb %p] shutting down", this);
401
+ }
402
+ shutting_down_ = true;
403
+ // Drop our ref to the child's picker, in case it's holding a ref to
404
+ // the child.
405
+ child_picker_.reset();
406
+ MaybeDestroyChildPolicyLocked();
407
+ drop_stats_.reset();
408
+ // Cancel the endpoint watch here instead of in our dtor if we are using the
409
+ // xds resolver, because the watcher holds a ref to us and we might not be
410
+ // destroying the XdsClient, leading to a situation where this LB policy is
411
+ // never destroyed.
412
+ if (xds_client_from_channel_ != nullptr) {
413
+ if (config_ != nullptr) {
414
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
415
+ gpr_log(GPR_INFO, "[edslb %p] cancelling xds watch for %s", this,
416
+ std::string(GetEdsResourceName()).c_str());
417
+ }
418
+ xds_client()->CancelEndpointDataWatch(GetEdsResourceName(),
419
+ endpoint_watcher_);
420
+ }
421
+ xds_client_from_channel_.reset();
422
+ }
423
+ xds_client_.reset();
424
+ }
425
+
426
+ void EdsLb::MaybeDestroyChildPolicyLocked() {
427
+ if (child_policy_ != nullptr) {
428
+ grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
429
+ interested_parties());
430
+ child_policy_.reset();
431
+ }
432
+ }
433
+
434
+ void EdsLb::UpdateLocked(UpdateArgs args) {
435
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
436
+ gpr_log(GPR_INFO, "[edslb %p] Received update", this);
437
+ }
438
+ const bool is_initial_update = args_ == nullptr;
439
+ // Update config.
440
+ auto old_config = std::move(config_);
441
+ config_ = std::move(args.config);
442
+ // Update args.
443
+ grpc_channel_args_destroy(args_);
444
+ args_ = args.args;
445
+ args.args = nullptr;
446
+ if (is_initial_update) {
447
+ // Initialize XdsClient.
448
+ if (xds_client_from_channel_ == nullptr) {
449
+ grpc_error* error = GRPC_ERROR_NONE;
450
+ xds_client_ = MakeOrphanable<XdsClient>(
451
+ work_serializer(), interested_parties(), GetEdsResourceName(),
452
+ nullptr /* service config watcher */, *args_, &error);
453
+ // TODO(roth): If we decide that we care about EDS-only mode, add
454
+ // proper error handling here.
455
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
456
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
457
+ gpr_log(GPR_INFO, "[edslb %p] Created xds client %p", this,
458
+ xds_client_.get());
459
+ }
460
+ }
461
+ }
462
+ // Update drop stats for load reporting if needed.
463
+ if (is_initial_update || config_->lrs_load_reporting_server_name() !=
464
+ old_config->lrs_load_reporting_server_name()) {
465
+ drop_stats_.reset();
466
+ if (config_->lrs_load_reporting_server_name().has_value()) {
467
+ const auto key = GetLrsClusterKey();
468
+ drop_stats_ = xds_client()->AddClusterDropStats(
469
+ config_->lrs_load_reporting_server_name().value(),
470
+ key.first /*cluster_name*/, key.second /*eds_service_name*/);
471
+ }
472
+ MaybeUpdateDropPickerLocked();
473
+ }
474
+ // Update child policy if needed.
475
+ // Note that this comes after updating drop_stats_, since we want that
476
+ // to be used by any new picker we create here.
477
+ if (child_policy_ != nullptr) UpdateChildPolicyLocked();
478
+ // Create endpoint watcher if needed.
479
+ if (is_initial_update) {
480
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
481
+ gpr_log(GPR_INFO, "[edslb %p] starting xds watch for %s", this,
482
+ std::string(GetEdsResourceName()).c_str());
483
+ }
484
+ auto watcher = absl::make_unique<EndpointWatcher>(
485
+ Ref(DEBUG_LOCATION, "EndpointWatcher"));
486
+ endpoint_watcher_ = watcher.get();
487
+ xds_client()->WatchEndpointData(GetEdsResourceName(), std::move(watcher));
488
+ }
489
+ }
490
+
491
+ void EdsLb::ResetBackoffLocked() {
492
+ // When the XdsClient is instantiated in the resolver instead of in this
493
+ // LB policy, this is done via the resolver, so we don't need to do it
494
+ // for xds_client_from_channel_ here.
495
+ if (xds_client_ != nullptr) xds_client_->ResetBackoff();
496
+ if (child_policy_ != nullptr) {
497
+ child_policy_->ResetBackoffLocked();
498
+ }
499
+ }
500
+
501
+ //
502
+ // child policy-related methods
503
+ //
504
+
505
+ void EdsLb::UpdatePriorityList(
506
+ XdsApi::PriorityListUpdate priority_list_update) {
507
+ // Build some maps from locality to child number and the reverse from
508
+ // the old data in priority_list_update_ and priority_child_numbers_.
509
+ std::map<XdsLocalityName*, size_t /*child_number*/, XdsLocalityName::Less>
510
+ locality_child_map;
511
+ std::map<size_t, std::set<XdsLocalityName*>> child_locality_map;
512
+ for (uint32_t priority = 0; priority < priority_list_update_.size();
513
+ ++priority) {
514
+ auto* locality_map = priority_list_update_.Find(priority);
515
+ GPR_ASSERT(locality_map != nullptr);
516
+ size_t child_number = priority_child_numbers_[priority];
517
+ for (const auto& p : locality_map->localities) {
518
+ XdsLocalityName* locality_name = p.first.get();
519
+ locality_child_map[locality_name] = child_number;
520
+ child_locality_map[child_number].insert(locality_name);
521
+ }
522
+ }
523
+ // Construct new list of children.
524
+ std::vector<size_t> priority_child_numbers;
525
+ for (uint32_t priority = 0; priority < priority_list_update.size();
526
+ ++priority) {
527
+ auto* locality_map = priority_list_update.Find(priority);
528
+ GPR_ASSERT(locality_map != nullptr);
529
+ absl::optional<size_t> child_number;
530
+ // If one of the localities in this priority already existed, reuse its
531
+ // child number.
532
+ for (const auto& p : locality_map->localities) {
533
+ XdsLocalityName* locality_name = p.first.get();
534
+ if (!child_number.has_value()) {
535
+ auto it = locality_child_map.find(locality_name);
536
+ if (it != locality_child_map.end()) {
537
+ child_number = it->second;
538
+ locality_child_map.erase(it);
539
+ // Remove localities that *used* to be in this child number, so
540
+ // that we don't incorrectly reuse this child number for a
541
+ // subsequent priority.
542
+ for (XdsLocalityName* old_locality :
543
+ child_locality_map[*child_number]) {
544
+ locality_child_map.erase(old_locality);
545
+ }
546
+ }
547
+ } else {
548
+ // Remove all localities that are now in this child number, so
549
+ // that we don't accidentally reuse this child number for a
550
+ // subsequent priority.
551
+ locality_child_map.erase(locality_name);
552
+ }
553
+ }
554
+ // If we didn't find an existing child number, assign a new one.
555
+ if (!child_number.has_value()) {
556
+ for (child_number = 0;
557
+ child_locality_map.find(*child_number) != child_locality_map.end();
558
+ ++(*child_number))
559
+ ;
560
+ // Add entry so we know that the child number is in use.
561
+ // (Don't need to add the list of localities, since we won't use them.)
562
+ child_locality_map[*child_number];
563
+ }
564
+ priority_child_numbers.push_back(*child_number);
565
+ }
566
+ // Save update.
567
+ priority_list_update_ = std::move(priority_list_update);
568
+ priority_child_numbers_ = std::move(priority_child_numbers);
569
+ // Update child policy.
570
+ UpdateChildPolicyLocked();
571
+ }
572
+
573
+ ServerAddressList EdsLb::CreateChildPolicyAddressesLocked() {
574
+ ServerAddressList addresses;
575
+ for (uint32_t priority = 0; priority < priority_list_update_.size();
576
+ ++priority) {
577
+ std::string priority_child_name =
578
+ absl::StrCat("child", priority_child_numbers_[priority]);
579
+ const auto* locality_map = priority_list_update_.Find(priority);
580
+ GPR_ASSERT(locality_map != nullptr);
581
+ for (const auto& p : locality_map->localities) {
582
+ const auto& locality_name = p.first;
583
+ const auto& locality = p.second;
584
+ std::vector<std::string> hierarchical_path = {
585
+ priority_child_name, locality_name->AsHumanReadableString()};
586
+ for (size_t i = 0; i < locality.serverlist.size(); ++i) {
587
+ const ServerAddress& address = locality.serverlist[i];
588
+ grpc_arg new_arg = MakeHierarchicalPathArg(hierarchical_path);
589
+ grpc_channel_args* args =
590
+ grpc_channel_args_copy_and_add(address.args(), &new_arg, 1);
591
+ addresses.emplace_back(address.address(), args);
592
+ }
593
+ }
594
+ }
595
+ return addresses;
596
+ }
597
+
598
+ RefCountedPtr<LoadBalancingPolicy::Config>
599
+ EdsLb::CreateChildPolicyConfigLocked() {
600
+ Json::Object priority_children;
601
+ Json::Array priority_priorities;
602
+ for (uint32_t priority = 0; priority < priority_list_update_.size();
603
+ ++priority) {
604
+ const auto* locality_map = priority_list_update_.Find(priority);
605
+ GPR_ASSERT(locality_map != nullptr);
606
+ Json::Object weighted_targets;
607
+ for (const auto& p : locality_map->localities) {
608
+ XdsLocalityName* locality_name = p.first.get();
609
+ const auto& locality = p.second;
610
+ // Construct JSON object containing locality name.
611
+ Json::Object locality_name_json;
612
+ if (!locality_name->region().empty()) {
613
+ locality_name_json["region"] = locality_name->region();
614
+ }
615
+ if (!locality_name->zone().empty()) {
616
+ locality_name_json["zone"] = locality_name->zone();
617
+ }
618
+ if (!locality_name->sub_zone().empty()) {
619
+ locality_name_json["subzone"] = locality_name->sub_zone();
620
+ }
621
+ // Construct endpoint-picking policy.
622
+ // Wrap it in the LRS policy if load reporting is enabled.
623
+ Json endpoint_picking_policy;
624
+ if (config_->lrs_load_reporting_server_name().has_value()) {
625
+ const auto key = GetLrsClusterKey();
626
+ Json::Object lrs_config = {
627
+ {"clusterName", std::string(key.first)},
628
+ {"locality", std::move(locality_name_json)},
629
+ {"lrsLoadReportingServerName",
630
+ config_->lrs_load_reporting_server_name().value()},
631
+ {"childPolicy", config_->endpoint_picking_policy()},
632
+ };
633
+ if (!key.second.empty()) {
634
+ lrs_config["edsServiceName"] = std::string(key.second);
635
+ }
636
+ endpoint_picking_policy = Json::Array{Json::Object{
637
+ {"lrs_experimental", std::move(lrs_config)},
638
+ }};
639
+ } else {
640
+ endpoint_picking_policy = config_->endpoint_picking_policy();
641
+ }
642
+ // Add weighted target entry.
643
+ weighted_targets[locality_name->AsHumanReadableString()] = Json::Object{
644
+ {"weight", locality.lb_weight},
645
+ {"childPolicy", std::move(endpoint_picking_policy)},
646
+ };
647
+ }
648
+ // Add priority entry.
649
+ const size_t child_number = priority_child_numbers_[priority];
650
+ std::string child_name = absl::StrCat("child", child_number);
651
+ priority_priorities.emplace_back(child_name);
652
+ Json locality_picking_config = config_->locality_picking_policy();
653
+ Json::Object& config =
654
+ *(*locality_picking_config.mutable_array())[0].mutable_object();
655
+ auto it = config.begin();
656
+ GPR_ASSERT(it != config.end());
657
+ (*it->second.mutable_object())["targets"] = std::move(weighted_targets);
658
+ priority_children[child_name] = Json::Object{
659
+ {"config", std::move(locality_picking_config)},
660
+ };
661
+ }
662
+ Json json = Json::Array{Json::Object{
663
+ {"priority_experimental",
664
+ Json::Object{
665
+ {"children", std::move(priority_children)},
666
+ {"priorities", std::move(priority_priorities)},
667
+ }},
668
+ }};
669
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
670
+ std::string json_str = json.Dump(/*indent=*/1);
671
+ gpr_log(GPR_INFO, "[edslb %p] generated config for child policy: %s", this,
672
+ json_str.c_str());
673
+ }
674
+ grpc_error* error = GRPC_ERROR_NONE;
675
+ RefCountedPtr<LoadBalancingPolicy::Config> config =
676
+ LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(json, &error);
677
+ if (error != GRPC_ERROR_NONE) {
678
+ // This should never happen, but if it does, we basically have no
679
+ // way to fix it, so we put the channel in TRANSIENT_FAILURE.
680
+ gpr_log(GPR_ERROR,
681
+ "[edslb %p] error parsing generated child policy config -- "
682
+ "will put channel in TRANSIENT_FAILURE: %s",
683
+ this, grpc_error_string(error));
684
+ error = grpc_error_set_int(
685
+ grpc_error_add_child(
686
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING(
687
+ "eds LB policy: error parsing generated child policy config"),
688
+ error),
689
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL);
690
+ channel_control_helper()->UpdateState(
691
+ GRPC_CHANNEL_TRANSIENT_FAILURE,
692
+ absl::make_unique<TransientFailurePicker>(error));
693
+ return nullptr;
694
+ }
695
+ return config;
696
+ }
697
+
698
+ void EdsLb::UpdateChildPolicyLocked() {
699
+ if (shutting_down_) return;
700
+ UpdateArgs update_args;
701
+ update_args.config = CreateChildPolicyConfigLocked();
702
+ if (update_args.config == nullptr) return;
703
+ update_args.addresses = CreateChildPolicyAddressesLocked();
704
+ update_args.args = CreateChildPolicyArgsLocked(args_);
705
+ if (child_policy_ == nullptr) {
706
+ child_policy_ = CreateChildPolicyLocked(update_args.args);
707
+ }
708
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
709
+ gpr_log(GPR_INFO, "[edslb %p] Updating child policy %p", this,
710
+ child_policy_.get());
711
+ }
712
+ child_policy_->UpdateLocked(std::move(update_args));
713
+ }
714
+
715
+ grpc_channel_args* EdsLb::CreateChildPolicyArgsLocked(
716
+ const grpc_channel_args* args) {
717
+ absl::InlinedVector<grpc_arg, 3> args_to_add = {
718
+ // A channel arg indicating if the target is a backend inferred from an
719
+ // xds load balancer.
720
+ grpc_channel_arg_integer_create(
721
+ const_cast<char*>(GRPC_ARG_ADDRESS_IS_BACKEND_FROM_XDS_LOAD_BALANCER),
722
+ 1),
723
+ // Inhibit client-side health checking, since the balancer does
724
+ // this for us.
725
+ grpc_channel_arg_integer_create(
726
+ const_cast<char*>(GRPC_ARG_INHIBIT_HEALTH_CHECKING), 1),
727
+ };
728
+ absl::InlinedVector<const char*, 1> args_to_remove;
729
+ if (xds_client_from_channel_ == nullptr) {
730
+ args_to_add.emplace_back(xds_client_->MakeChannelArg());
731
+ } else if (!config_->lrs_load_reporting_server_name().has_value()) {
732
+ // Remove XdsClient from channel args, so that its presence doesn't
733
+ // prevent us from sharing subchannels between channels.
734
+ // If load reporting is enabled, this happens in the LRS policy instead.
735
+ args_to_remove.push_back(GRPC_ARG_XDS_CLIENT);
736
+ }
737
+ return grpc_channel_args_copy_and_add_and_remove(
738
+ args, args_to_remove.data(), args_to_remove.size(), args_to_add.data(),
739
+ args_to_add.size());
740
+ }
741
+
742
+ OrphanablePtr<LoadBalancingPolicy> EdsLb::CreateChildPolicyLocked(
743
+ const grpc_channel_args* args) {
744
+ LoadBalancingPolicy::Args lb_policy_args;
745
+ lb_policy_args.work_serializer = work_serializer();
746
+ lb_policy_args.args = args;
747
+ lb_policy_args.channel_control_helper =
748
+ absl::make_unique<Helper>(Ref(DEBUG_LOCATION, "Helper"));
749
+ OrphanablePtr<LoadBalancingPolicy> lb_policy =
750
+ LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
751
+ "priority_experimental", std::move(lb_policy_args));
752
+ if (GPR_UNLIKELY(lb_policy == nullptr)) {
753
+ gpr_log(GPR_ERROR, "[edslb %p] failure creating child policy", this);
754
+ return nullptr;
755
+ }
756
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_eds_trace)) {
757
+ gpr_log(GPR_INFO, "[edslb %p]: Created new child policy %p", this,
758
+ lb_policy.get());
759
+ }
760
+ // Add our interested_parties pollset_set to that of the newly created
761
+ // child policy. This will make the child policy progress upon activity on
762
+ // this policy, which in turn is tied to the application's call.
763
+ grpc_pollset_set_add_pollset_set(lb_policy->interested_parties(),
764
+ interested_parties());
765
+ return lb_policy;
766
+ }
767
+
768
+ void EdsLb::MaybeUpdateDropPickerLocked() {
769
+ // If we're dropping all calls, report READY, regardless of what (or
770
+ // whether) the child has reported.
771
+ if (drop_config_ != nullptr && drop_config_->drop_all()) {
772
+ channel_control_helper()->UpdateState(GRPC_CHANNEL_READY,
773
+ absl::make_unique<DropPicker>(this));
774
+ return;
775
+ }
776
+ // Update only if we have a child picker.
777
+ if (child_picker_ != nullptr) {
778
+ channel_control_helper()->UpdateState(child_state_,
779
+ absl::make_unique<DropPicker>(this));
780
+ }
781
+ }
782
+
783
+ //
784
+ // factory
785
+ //
786
+
787
+ class EdsLbFactory : public LoadBalancingPolicyFactory {
788
+ public:
789
+ OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
790
+ LoadBalancingPolicy::Args args) const override {
791
+ return MakeOrphanable<EdsChildHandler>(std::move(args), &grpc_lb_eds_trace);
792
+ }
793
+
794
+ const char* name() const override { return kEds; }
795
+
796
+ RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
797
+ const Json& json, grpc_error** error) const override {
798
+ GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
799
+ if (json.type() == Json::Type::JSON_NULL) {
800
+ // eds was mentioned as a policy in the deprecated loadBalancingPolicy
801
+ // field or in the client API.
802
+ *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
803
+ "field:loadBalancingPolicy error:eds policy requires configuration. "
804
+ "Please use loadBalancingConfig field of service config instead.");
805
+ return nullptr;
806
+ }
807
+ std::vector<grpc_error*> error_list;
808
+ // EDS service name.
809
+ std::string eds_service_name;
810
+ auto it = json.object_value().find("edsServiceName");
811
+ if (it != json.object_value().end()) {
812
+ if (it->second.type() != Json::Type::STRING) {
813
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
814
+ "field:edsServiceName error:type should be string"));
815
+ } else {
816
+ eds_service_name = it->second.string_value();
817
+ }
818
+ }
819
+ // Cluster name.
820
+ std::string cluster_name;
821
+ it = json.object_value().find("clusterName");
822
+ if (it == json.object_value().end()) {
823
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
824
+ "field:clusterName error:required field missing"));
825
+ } else if (it->second.type() != Json::Type::STRING) {
826
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
827
+ "field:clusterName error:type should be string"));
828
+ } else {
829
+ cluster_name = it->second.string_value();
830
+ }
831
+ // LRS load reporting server name.
832
+ absl::optional<std::string> lrs_load_reporting_server_name;
833
+ it = json.object_value().find("lrsLoadReportingServerName");
834
+ if (it != json.object_value().end()) {
835
+ if (it->second.type() != Json::Type::STRING) {
836
+ error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
837
+ "field:lrsLoadReportingServerName error:type should be string"));
838
+ } else {
839
+ lrs_load_reporting_server_name.emplace(it->second.string_value());
840
+ }
841
+ }
842
+ // Locality-picking policy.
843
+ Json locality_picking_policy;
844
+ it = json.object_value().find("localityPickingPolicy");
845
+ if (it == json.object_value().end()) {
846
+ locality_picking_policy = Json::Array{
847
+ Json::Object{
848
+ {"weighted_target_experimental",
849
+ Json::Object{
850
+ {"targets", Json::Object()},
851
+ }},
852
+ },
853
+ };
854
+ } else {
855
+ locality_picking_policy = it->second;
856
+ }
857
+ grpc_error* parse_error = GRPC_ERROR_NONE;
858
+ if (LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
859
+ locality_picking_policy, &parse_error) == nullptr) {
860
+ GPR_DEBUG_ASSERT(parse_error != GRPC_ERROR_NONE);
861
+ error_list.push_back(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
862
+ "localityPickingPolicy", &parse_error, 1));
863
+ GRPC_ERROR_UNREF(parse_error);
864
+ }
865
+ // Endpoint-picking policy. Called "childPolicy" for xds policy.
866
+ Json endpoint_picking_policy;
867
+ it = json.object_value().find("endpointPickingPolicy");
868
+ if (it == json.object_value().end()) {
869
+ endpoint_picking_policy = Json::Array{
870
+ Json::Object{
871
+ {"round_robin", Json::Object()},
872
+ },
873
+ };
874
+ } else {
875
+ endpoint_picking_policy = it->second;
876
+ }
877
+ parse_error = GRPC_ERROR_NONE;
878
+ if (LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
879
+ endpoint_picking_policy, &parse_error) == nullptr) {
880
+ GPR_DEBUG_ASSERT(parse_error != GRPC_ERROR_NONE);
881
+ error_list.push_back(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
882
+ "endpointPickingPolicy", &parse_error, 1));
883
+ GRPC_ERROR_UNREF(parse_error);
884
+ }
885
+ // Construct config.
886
+ if (error_list.empty()) {
887
+ return MakeRefCounted<EdsLbConfig>(
888
+ std::move(cluster_name), std::move(eds_service_name),
889
+ std::move(lrs_load_reporting_server_name),
890
+ std::move(locality_picking_policy),
891
+ std::move(endpoint_picking_policy));
892
+ } else {
893
+ *error = GRPC_ERROR_CREATE_FROM_VECTOR(
894
+ "eds_experimental LB policy config", &error_list);
895
+ return nullptr;
896
+ }
897
+ }
898
+
899
+ private:
900
+ class EdsChildHandler : public ChildPolicyHandler {
901
+ public:
902
+ EdsChildHandler(Args args, TraceFlag* tracer)
903
+ : ChildPolicyHandler(std::move(args), tracer) {}
904
+
905
+ bool ConfigChangeRequiresNewPolicyInstance(
906
+ LoadBalancingPolicy::Config* old_config,
907
+ LoadBalancingPolicy::Config* new_config) const override {
908
+ GPR_ASSERT(old_config->name() == kEds);
909
+ GPR_ASSERT(new_config->name() == kEds);
910
+ EdsLbConfig* old_eds_config = static_cast<EdsLbConfig*>(old_config);
911
+ EdsLbConfig* new_eds_config = static_cast<EdsLbConfig*>(new_config);
912
+ return old_eds_config->cluster_name() != new_eds_config->cluster_name() ||
913
+ old_eds_config->eds_service_name() !=
914
+ new_eds_config->eds_service_name();
915
+ }
916
+
917
+ OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
918
+ const char* name, LoadBalancingPolicy::Args args) const override {
919
+ return MakeOrphanable<EdsLb>(std::move(args));
920
+ }
921
+ };
922
+ };
923
+
924
+ } // namespace
925
+
926
+ } // namespace grpc_core
927
+
928
+ //
929
+ // Plugin registration
930
+ //
931
+
932
+ void grpc_lb_policy_eds_init() {
933
+ grpc_core::LoadBalancingPolicyRegistry::Builder::
934
+ RegisterLoadBalancingPolicyFactory(
935
+ absl::make_unique<grpc_core::EdsLbFactory>());
936
+ }
937
+
938
+ void grpc_lb_policy_eds_shutdown() {}