grpc 1.32.0 → 1.33.0.pre1

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 (214) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +175 -376
  3. data/include/grpc/grpc.h +0 -5
  4. data/include/grpc/grpc_security.h +16 -0
  5. data/include/grpc/impl/codegen/grpc_types.h +0 -5
  6. data/src/core/ext/filters/client_channel/client_channel.cc +204 -170
  7. data/src/core/ext/filters/client_channel/config_selector.cc +0 -4
  8. data/src/core/ext/filters/client_channel/config_selector.h +34 -5
  9. data/src/core/ext/filters/client_channel/lb_policy.h +1 -1
  10. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +48 -35
  11. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  12. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +3 -2
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -106
  14. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +2 -2
  15. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +3 -3
  16. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +3 -3
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +9 -32
  18. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -3
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +198 -126
  20. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +439 -249
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc +571 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +727 -0
  23. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +8 -1
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
  25. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +553 -358
  26. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +28 -0
  27. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -39
  28. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +4 -2
  29. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +44 -43
  30. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +5 -9
  31. data/src/core/ext/filters/client_channel/server_address.cc +80 -0
  32. data/src/core/ext/filters/client_channel/server_address.h +25 -36
  33. data/src/core/ext/filters/client_channel/service_config.cc +16 -13
  34. data/src/core/ext/filters/client_channel/service_config.h +7 -4
  35. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +2 -2
  36. data/src/core/ext/filters/client_channel/service_config_parser.cc +8 -6
  37. data/src/core/ext/filters/client_channel/service_config_parser.h +8 -5
  38. data/src/core/ext/filters/client_channel/subchannel_interface.h +44 -0
  39. data/src/core/ext/filters/message_size/message_size_filter.cc +2 -1
  40. data/src/core/ext/filters/message_size/message_size_filter.h +2 -1
  41. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +17 -10
  42. data/src/core/ext/transport/chttp2/transport/flow_control.cc +10 -2
  43. data/src/core/ext/transport/chttp2/transport/flow_control.h +10 -0
  44. data/src/core/ext/transport/chttp2/transport/internal.h +5 -0
  45. data/src/core/ext/transport/chttp2/transport/parsing.cc +16 -2
  46. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +29 -9
  47. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +66 -0
  48. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +123 -45
  49. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +310 -53
  50. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +17 -5
  51. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +45 -0
  52. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +1 -0
  53. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +16 -9
  54. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +38 -15
  55. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +53 -0
  56. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +133 -0
  57. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +54 -8
  58. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +123 -5
  59. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +40 -16
  60. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +114 -5
  61. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +36 -0
  62. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +85 -0
  63. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +36 -16
  64. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +86 -20
  65. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +23 -6
  66. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +54 -5
  67. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +10 -6
  68. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +28 -11
  69. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +184 -57
  70. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +504 -69
  71. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +6 -5
  72. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +11 -7
  73. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +78 -26
  74. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +236 -25
  75. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +8 -9
  76. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +19 -33
  77. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +7 -3
  78. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +16 -0
  79. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +65 -23
  80. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +229 -47
  81. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +20 -10
  82. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +67 -4
  83. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +3 -2
  84. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +6 -0
  85. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +242 -0
  86. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +753 -0
  87. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +31 -0
  88. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +57 -0
  89. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +28 -0
  90. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +53 -0
  91. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +52 -0
  92. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +129 -0
  93. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +42 -0
  94. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +77 -0
  95. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +36 -0
  96. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +85 -0
  97. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +54 -0
  98. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +160 -0
  99. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +36 -0
  100. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +84 -0
  101. data/src/core/ext/xds/certificate_provider_factory.h +59 -0
  102. data/src/core/ext/xds/certificate_provider_registry.cc +103 -0
  103. data/src/core/ext/xds/certificate_provider_registry.h +57 -0
  104. data/src/core/ext/xds/certificate_provider_store.h +50 -0
  105. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +377 -0
  106. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +102 -0
  107. data/src/core/ext/xds/xds_api.cc +301 -93
  108. data/src/core/ext/xds/xds_api.h +129 -92
  109. data/src/core/ext/xds/xds_channel_args.h +6 -3
  110. data/src/core/ext/xds/xds_client.cc +498 -410
  111. data/src/core/ext/xds/xds_client.h +105 -51
  112. data/src/core/ext/xds/xds_client_stats.cc +18 -12
  113. data/src/core/ext/xds/xds_client_stats.h +33 -5
  114. data/src/core/lib/channel/channel_args.h +0 -1
  115. data/src/core/lib/channel/channelz.cc +10 -45
  116. data/src/core/lib/channel/channelz.h +11 -19
  117. data/src/core/lib/channel/channelz_registry.cc +12 -11
  118. data/src/core/lib/channel/channelz_registry.h +3 -0
  119. data/src/core/lib/gpr/time_precise.cc +2 -0
  120. data/src/core/lib/gpr/time_precise.h +6 -2
  121. data/src/core/lib/gprpp/dual_ref_counted.h +336 -0
  122. data/src/core/lib/gprpp/ref_counted.h +51 -22
  123. data/src/core/lib/gprpp/ref_counted_ptr.h +153 -0
  124. data/src/core/lib/iomgr/endpoint_cfstream.cc +9 -5
  125. data/src/core/lib/iomgr/exec_ctx.h +10 -8
  126. data/src/core/lib/json/json_util.cc +58 -0
  127. data/src/core/lib/json/json_util.h +37 -0
  128. data/src/core/lib/security/certificate_provider.h +60 -0
  129. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +321 -0
  130. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +214 -0
  131. data/src/core/lib/security/credentials/xds/xds_credentials.cc +45 -0
  132. data/src/core/lib/security/credentials/xds/xds_credentials.h +51 -0
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +6 -10
  134. data/src/core/lib/security/security_connector/ssl_utils.h +5 -0
  135. data/src/core/lib/surface/channel.cc +9 -31
  136. data/src/core/lib/surface/channel.h +6 -1
  137. data/src/core/lib/surface/init.cc +26 -9
  138. data/src/core/lib/surface/version.cc +2 -2
  139. data/src/core/lib/transport/bdp_estimator.h +2 -1
  140. data/src/core/lib/transport/connectivity_state.h +2 -2
  141. data/src/core/lib/transport/metadata.cc +11 -1
  142. data/src/core/plugin_registry/grpc_plugin_registry.cc +35 -20
  143. data/src/core/tsi/ssl_transport_security.cc +2 -2
  144. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -2
  145. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -3
  146. data/src/ruby/lib/grpc/version.rb +1 -1
  147. data/third_party/boringssl-with-bazel/err_data.c +465 -463
  148. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +0 -6
  149. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +9 -43
  150. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.c +55 -4
  151. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +34 -0
  152. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +4 -0
  153. data/third_party/boringssl-with-bazel/src/crypto/evp/p_dsa_asn1.c +6 -2
  154. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +2 -0
  155. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +4 -0
  156. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +30 -10
  157. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -15
  158. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +98 -11
  159. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +51 -6
  160. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +44 -2
  161. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +221 -49
  162. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +64 -20
  163. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +3 -3
  164. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +0 -8
  165. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +3 -3
  166. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +1 -1
  167. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +7 -2
  168. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +21 -18
  169. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_obj.c +1 -1
  170. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +24 -3
  171. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +3 -3
  172. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_txt.c +67 -67
  173. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +3 -3
  174. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +29 -35
  175. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +13 -2
  176. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +9 -8
  177. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +10 -10
  178. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +2 -2
  179. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +28 -40
  180. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +3 -1
  181. data/third_party/boringssl-with-bazel/src/crypto/x509v3/ext_dat.h +1 -4
  182. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +7 -3
  183. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_genn.c +2 -2
  184. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +1 -1
  185. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +55 -8
  186. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -1
  187. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +0 -1
  188. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +1 -1
  189. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +6 -0
  190. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +1 -1
  191. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +12 -0
  192. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +9 -0
  193. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +4 -1
  194. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +9 -2
  195. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +26 -6
  196. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +188 -78
  197. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +52 -43
  198. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +18 -18
  199. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -3
  200. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
  201. data/third_party/boringssl-with-bazel/src/ssl/internal.h +9 -9
  202. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +8 -9
  203. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -2
  204. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +4 -8
  205. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +2 -2
  206. metadata +72 -42
  207. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +0 -537
  208. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +0 -1141
  209. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +0 -17
  210. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -29
  211. data/src/core/ext/xds/xds_channel.h +0 -46
  212. data/src/core/ext/xds/xds_channel_secure.cc +0 -103
  213. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_pku.c +0 -110
  214. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_sxnet.c +0 -274
@@ -1,537 +0,0 @@
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 <grpc/grpc.h>
20
-
21
- #include "src/core/ext/filters/client_channel/lb_policy.h"
22
- #include "src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h"
23
- #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
24
- #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
25
- #include "src/core/ext/xds/xds_client.h"
26
- #include "src/core/ext/xds/xds_client_stats.h"
27
- #include "src/core/lib/channel/channel_args.h"
28
- #include "src/core/lib/gprpp/orphanable.h"
29
- #include "src/core/lib/gprpp/ref_counted_ptr.h"
30
- #include "src/core/lib/iomgr/work_serializer.h"
31
-
32
- namespace grpc_core {
33
-
34
- TraceFlag grpc_lb_lrs_trace(false, "lrs_lb");
35
-
36
- namespace {
37
-
38
- constexpr char kLrs[] = "lrs_experimental";
39
-
40
- // Config for LRS LB policy.
41
- class LrsLbConfig : public LoadBalancingPolicy::Config {
42
- public:
43
- LrsLbConfig(RefCountedPtr<LoadBalancingPolicy::Config> child_policy,
44
- std::string cluster_name, std::string eds_service_name,
45
- std::string lrs_load_reporting_server_name,
46
- RefCountedPtr<XdsLocalityName> locality_name)
47
- : child_policy_(std::move(child_policy)),
48
- cluster_name_(std::move(cluster_name)),
49
- eds_service_name_(std::move(eds_service_name)),
50
- lrs_load_reporting_server_name_(
51
- std::move(lrs_load_reporting_server_name)),
52
- locality_name_(std::move(locality_name)) {}
53
-
54
- const char* name() const override { return kLrs; }
55
-
56
- RefCountedPtr<LoadBalancingPolicy::Config> child_policy() const {
57
- return child_policy_;
58
- }
59
- const std::string& cluster_name() const { return cluster_name_; }
60
- const std::string& eds_service_name() const { return eds_service_name_; }
61
- const std::string& lrs_load_reporting_server_name() const {
62
- return lrs_load_reporting_server_name_;
63
- };
64
- RefCountedPtr<XdsLocalityName> locality_name() const {
65
- return locality_name_;
66
- }
67
-
68
- private:
69
- RefCountedPtr<LoadBalancingPolicy::Config> child_policy_;
70
- std::string cluster_name_;
71
- std::string eds_service_name_;
72
- std::string lrs_load_reporting_server_name_;
73
- RefCountedPtr<XdsLocalityName> locality_name_;
74
- };
75
-
76
- // LRS LB policy.
77
- class LrsLb : public LoadBalancingPolicy {
78
- public:
79
- LrsLb(RefCountedPtr<XdsClient> xds_client, Args args);
80
-
81
- const char* name() const override { return kLrs; }
82
-
83
- void UpdateLocked(UpdateArgs args) override;
84
- void ExitIdleLocked() override;
85
- void ResetBackoffLocked() override;
86
-
87
- private:
88
- // A simple wrapper for ref-counting a picker from the child policy.
89
- class RefCountedPicker : public RefCounted<RefCountedPicker> {
90
- public:
91
- explicit RefCountedPicker(std::unique_ptr<SubchannelPicker> picker)
92
- : picker_(std::move(picker)) {}
93
- PickResult Pick(PickArgs args) { return picker_->Pick(args); }
94
-
95
- private:
96
- std::unique_ptr<SubchannelPicker> picker_;
97
- };
98
-
99
- // A picker that wraps the picker from the child to perform load reporting.
100
- class LoadReportingPicker : public SubchannelPicker {
101
- public:
102
- LoadReportingPicker(RefCountedPtr<RefCountedPicker> picker,
103
- RefCountedPtr<XdsClusterLocalityStats> locality_stats)
104
- : picker_(std::move(picker)),
105
- locality_stats_(std::move(locality_stats)) {}
106
-
107
- PickResult Pick(PickArgs args);
108
-
109
- private:
110
- RefCountedPtr<RefCountedPicker> picker_;
111
- RefCountedPtr<XdsClusterLocalityStats> locality_stats_;
112
- };
113
-
114
- class Helper : public ChannelControlHelper {
115
- public:
116
- explicit Helper(RefCountedPtr<LrsLb> lrs_policy)
117
- : lrs_policy_(std::move(lrs_policy)) {}
118
-
119
- ~Helper() { lrs_policy_.reset(DEBUG_LOCATION, "Helper"); }
120
-
121
- RefCountedPtr<SubchannelInterface> CreateSubchannel(
122
- const grpc_channel_args& args) override;
123
- void UpdateState(grpc_connectivity_state state, const absl::Status& status,
124
- std::unique_ptr<SubchannelPicker> picker) override;
125
- void RequestReresolution() override;
126
- void AddTraceEvent(TraceSeverity severity,
127
- absl::string_view message) override;
128
-
129
- private:
130
- RefCountedPtr<LrsLb> lrs_policy_;
131
- };
132
-
133
- ~LrsLb();
134
-
135
- void ShutdownLocked() override;
136
-
137
- OrphanablePtr<LoadBalancingPolicy> CreateChildPolicyLocked(
138
- const grpc_channel_args* args);
139
- void UpdateChildPolicyLocked(ServerAddressList addresses,
140
- const grpc_channel_args* args);
141
-
142
- void MaybeUpdatePickerLocked();
143
-
144
- // Current config from the resolver.
145
- RefCountedPtr<LrsLbConfig> config_;
146
-
147
- // Internal state.
148
- bool shutting_down_ = false;
149
-
150
- // The xds client.
151
- RefCountedPtr<XdsClient> xds_client_;
152
-
153
- // The stats for client-side load reporting.
154
- RefCountedPtr<XdsClusterLocalityStats> locality_stats_;
155
-
156
- OrphanablePtr<LoadBalancingPolicy> child_policy_;
157
-
158
- // Latest state and picker reported by the child policy.
159
- grpc_connectivity_state state_ = GRPC_CHANNEL_IDLE;
160
- absl::Status status_;
161
- RefCountedPtr<RefCountedPicker> picker_;
162
- };
163
-
164
- //
165
- // LrsLb::LoadReportingPicker
166
- //
167
-
168
- LoadBalancingPolicy::PickResult LrsLb::LoadReportingPicker::Pick(
169
- LoadBalancingPolicy::PickArgs args) {
170
- // Forward the pick to the picker returned from the child policy.
171
- PickResult result = picker_->Pick(args);
172
- if (result.type == PickResult::PICK_COMPLETE &&
173
- result.subchannel != nullptr) {
174
- // Record a call started.
175
- locality_stats_->AddCallStarted();
176
- // Intercept the recv_trailing_metadata op to record call completion.
177
- XdsClusterLocalityStats* locality_stats =
178
- locality_stats_->Ref(DEBUG_LOCATION, "LocalityStats+call").release();
179
- result.recv_trailing_metadata_ready =
180
- // Note: This callback does not run in either the control plane
181
- // work serializer or in the data plane mutex.
182
- [locality_stats](grpc_error* error, MetadataInterface* /*metadata*/,
183
- CallState* /*call_state*/) {
184
- const bool call_failed = error != GRPC_ERROR_NONE;
185
- locality_stats->AddCallFinished(call_failed);
186
- locality_stats->Unref(DEBUG_LOCATION, "LocalityStats+call");
187
- };
188
- }
189
- return result;
190
- }
191
-
192
- //
193
- // LrsLb
194
- //
195
-
196
- LrsLb::LrsLb(RefCountedPtr<XdsClient> xds_client, Args args)
197
- : LoadBalancingPolicy(std::move(args)), xds_client_(std::move(xds_client)) {
198
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_lrs_trace)) {
199
- gpr_log(GPR_INFO, "[lrs_lb %p] created -- using xds client %p from channel",
200
- this, xds_client_.get());
201
- }
202
- }
203
-
204
- LrsLb::~LrsLb() {
205
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_lrs_trace)) {
206
- gpr_log(GPR_INFO, "[lrs_lb %p] destroying xds LB policy", this);
207
- }
208
- }
209
-
210
- void LrsLb::ShutdownLocked() {
211
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_lrs_trace)) {
212
- gpr_log(GPR_INFO, "[lrs_lb %p] shutting down", this);
213
- }
214
- shutting_down_ = true;
215
- // Remove the child policy's interested_parties pollset_set from the
216
- // xDS policy.
217
- if (child_policy_ != nullptr) {
218
- grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
219
- interested_parties());
220
- child_policy_.reset();
221
- }
222
- // Drop our ref to the child's picker, in case it's holding a ref to
223
- // the child.
224
- picker_.reset();
225
- locality_stats_.reset();
226
- xds_client_.reset();
227
- }
228
-
229
- void LrsLb::ExitIdleLocked() {
230
- if (child_policy_ != nullptr) child_policy_->ExitIdleLocked();
231
- }
232
-
233
- void LrsLb::ResetBackoffLocked() {
234
- // The XdsClient will have its backoff reset by the xds resolver, so we
235
- // don't need to do it here.
236
- if (child_policy_ != nullptr) child_policy_->ResetBackoffLocked();
237
- }
238
-
239
- void LrsLb::UpdateLocked(UpdateArgs args) {
240
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_lrs_trace)) {
241
- gpr_log(GPR_INFO, "[lrs_lb %p] Received update", this);
242
- }
243
- // Update config.
244
- auto old_config = std::move(config_);
245
- config_ = std::move(args.config);
246
- // Update load reporting if needed.
247
- if (old_config == nullptr ||
248
- config_->lrs_load_reporting_server_name() !=
249
- old_config->lrs_load_reporting_server_name() ||
250
- config_->cluster_name() != old_config->cluster_name() ||
251
- config_->eds_service_name() != old_config->eds_service_name() ||
252
- *config_->locality_name() != *old_config->locality_name()) {
253
- locality_stats_ = xds_client_->AddClusterLocalityStats(
254
- config_->lrs_load_reporting_server_name(), config_->cluster_name(),
255
- config_->eds_service_name(), config_->locality_name());
256
- MaybeUpdatePickerLocked();
257
- }
258
- // Remove XdsClient from channel args, so that its presence doesn't
259
- // prevent us from sharing subchannels between channels.
260
- grpc_channel_args* new_args = XdsClient::RemoveFromChannelArgs(*args.args);
261
- // Update child policy.
262
- UpdateChildPolicyLocked(std::move(args.addresses), new_args);
263
- }
264
-
265
- void LrsLb::MaybeUpdatePickerLocked() {
266
- if (picker_ != nullptr) {
267
- auto lrs_picker =
268
- absl::make_unique<LoadReportingPicker>(picker_, locality_stats_);
269
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_lrs_trace)) {
270
- gpr_log(
271
- GPR_INFO,
272
- "[lrs_lb %p] updating connectivity: state=%s status=(%s) picker=%p",
273
- this, ConnectivityStateName(state_), status_.ToString().c_str(),
274
- lrs_picker.get());
275
- }
276
- channel_control_helper()->UpdateState(state_, status_,
277
- std::move(lrs_picker));
278
- }
279
- }
280
-
281
- OrphanablePtr<LoadBalancingPolicy> LrsLb::CreateChildPolicyLocked(
282
- const grpc_channel_args* args) {
283
- LoadBalancingPolicy::Args lb_policy_args;
284
- lb_policy_args.work_serializer = work_serializer();
285
- lb_policy_args.args = args;
286
- lb_policy_args.channel_control_helper =
287
- absl::make_unique<Helper>(Ref(DEBUG_LOCATION, "Helper"));
288
- OrphanablePtr<LoadBalancingPolicy> lb_policy =
289
- MakeOrphanable<ChildPolicyHandler>(std::move(lb_policy_args),
290
- &grpc_lb_lrs_trace);
291
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_lrs_trace)) {
292
- gpr_log(GPR_INFO, "[lrs_lb %p] Created new child policy handler %p", this,
293
- lb_policy.get());
294
- }
295
- // Add our interested_parties pollset_set to that of the newly created
296
- // child policy. This will make the child policy progress upon activity on
297
- // this policy, which in turn is tied to the application's call.
298
- grpc_pollset_set_add_pollset_set(lb_policy->interested_parties(),
299
- interested_parties());
300
- return lb_policy;
301
- }
302
-
303
- void LrsLb::UpdateChildPolicyLocked(ServerAddressList addresses,
304
- const grpc_channel_args* args) {
305
- // Create policy if needed.
306
- if (child_policy_ == nullptr) {
307
- child_policy_ = CreateChildPolicyLocked(args);
308
- }
309
- // Construct update args.
310
- UpdateArgs update_args;
311
- update_args.addresses = std::move(addresses);
312
- update_args.config = config_->child_policy();
313
- update_args.args = args;
314
- // Update the policy.
315
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_lrs_trace)) {
316
- gpr_log(GPR_INFO, "[lrs_lb %p] Updating child policy handler %p", this,
317
- child_policy_.get());
318
- }
319
- child_policy_->UpdateLocked(std::move(update_args));
320
- }
321
-
322
- //
323
- // LrsLb::Helper
324
- //
325
-
326
- RefCountedPtr<SubchannelInterface> LrsLb::Helper::CreateSubchannel(
327
- const grpc_channel_args& args) {
328
- if (lrs_policy_->shutting_down_) return nullptr;
329
- return lrs_policy_->channel_control_helper()->CreateSubchannel(args);
330
- }
331
-
332
- void LrsLb::Helper::UpdateState(grpc_connectivity_state state,
333
- const absl::Status& status,
334
- std::unique_ptr<SubchannelPicker> picker) {
335
- if (lrs_policy_->shutting_down_) return;
336
- if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_lrs_trace)) {
337
- gpr_log(
338
- GPR_INFO,
339
- "[lrs_lb %p] child connectivity state update: state=%s (%s) picker=%p",
340
- lrs_policy_.get(), ConnectivityStateName(state),
341
- status.ToString().c_str(), picker.get());
342
- }
343
- // Save the state and picker.
344
- lrs_policy_->state_ = state;
345
- lrs_policy_->status_ = status;
346
- lrs_policy_->picker_ = MakeRefCounted<RefCountedPicker>(std::move(picker));
347
- // Wrap the picker and return it to the channel.
348
- lrs_policy_->MaybeUpdatePickerLocked();
349
- }
350
-
351
- void LrsLb::Helper::RequestReresolution() {
352
- if (lrs_policy_->shutting_down_) return;
353
- lrs_policy_->channel_control_helper()->RequestReresolution();
354
- }
355
-
356
- void LrsLb::Helper::AddTraceEvent(TraceSeverity severity,
357
- absl::string_view message) {
358
- if (lrs_policy_->shutting_down_) return;
359
- lrs_policy_->channel_control_helper()->AddTraceEvent(severity, message);
360
- }
361
-
362
- //
363
- // factory
364
- //
365
-
366
- class LrsLbFactory : public LoadBalancingPolicyFactory {
367
- public:
368
- OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
369
- LoadBalancingPolicy::Args args) const override {
370
- RefCountedPtr<XdsClient> xds_client =
371
- XdsClient::GetFromChannelArgs(*args.args);
372
- if (xds_client == nullptr) {
373
- gpr_log(GPR_ERROR,
374
- "XdsClient not present in channel args -- cannot instantiate "
375
- "lrs LB policy");
376
- return nullptr;
377
- }
378
- return MakeOrphanable<LrsLb>(std::move(xds_client), std::move(args));
379
- }
380
-
381
- const char* name() const override { return kLrs; }
382
-
383
- RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
384
- const Json& json, grpc_error** error) const override {
385
- GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
386
- if (json.type() == Json::Type::JSON_NULL) {
387
- // lrs was mentioned as a policy in the deprecated loadBalancingPolicy
388
- // field or in the client API.
389
- *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
390
- "field:loadBalancingPolicy error:lrs policy requires configuration. "
391
- "Please use loadBalancingConfig field of service config instead.");
392
- return nullptr;
393
- }
394
- std::vector<grpc_error*> error_list;
395
- // Child policy.
396
- RefCountedPtr<LoadBalancingPolicy::Config> child_policy;
397
- auto it = json.object_value().find("childPolicy");
398
- if (it == json.object_value().end()) {
399
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
400
- "field:childPolicy error:required field missing"));
401
- } else {
402
- grpc_error* parse_error = GRPC_ERROR_NONE;
403
- child_policy = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(
404
- it->second, &parse_error);
405
- if (child_policy == nullptr) {
406
- GPR_DEBUG_ASSERT(parse_error != GRPC_ERROR_NONE);
407
- std::vector<grpc_error*> child_errors;
408
- child_errors.push_back(parse_error);
409
- error_list.push_back(
410
- GRPC_ERROR_CREATE_FROM_VECTOR("field:childPolicy", &child_errors));
411
- }
412
- }
413
- // Cluster name.
414
- std::string cluster_name;
415
- it = json.object_value().find("clusterName");
416
- if (it == json.object_value().end()) {
417
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
418
- "field:clusterName error:required field missing"));
419
- } else if (it->second.type() != Json::Type::STRING) {
420
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
421
- "field:clusterName error:type should be string"));
422
- } else {
423
- cluster_name = it->second.string_value();
424
- }
425
- // EDS service name.
426
- std::string eds_service_name;
427
- it = json.object_value().find("edsServiceName");
428
- if (it != json.object_value().end()) {
429
- if (it->second.type() != Json::Type::STRING) {
430
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
431
- "field:edsServiceName error:type should be string"));
432
- } else {
433
- eds_service_name = it->second.string_value();
434
- }
435
- }
436
- // Locality.
437
- RefCountedPtr<XdsLocalityName> locality_name;
438
- it = json.object_value().find("locality");
439
- if (it == json.object_value().end()) {
440
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
441
- "field:locality error:required field missing"));
442
- } else {
443
- std::vector<grpc_error*> child_errors =
444
- ParseLocality(it->second, &locality_name);
445
- if (!child_errors.empty()) {
446
- error_list.push_back(
447
- GRPC_ERROR_CREATE_FROM_VECTOR("field:locality", &child_errors));
448
- }
449
- }
450
- // LRS load reporting server name.
451
- std::string lrs_load_reporting_server_name;
452
- it = json.object_value().find("lrsLoadReportingServerName");
453
- if (it == json.object_value().end()) {
454
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
455
- "field:lrsLoadReportingServerName error:required field missing"));
456
- } else if (it->second.type() != Json::Type::STRING) {
457
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
458
- "field:lrsLoadReportingServerName error:type should be string"));
459
- } else {
460
- lrs_load_reporting_server_name = it->second.string_value();
461
- }
462
- if (!error_list.empty()) {
463
- *error = GRPC_ERROR_CREATE_FROM_VECTOR(
464
- "lrs_experimental LB policy config", &error_list);
465
- return nullptr;
466
- }
467
- return MakeRefCounted<LrsLbConfig>(
468
- std::move(child_policy), std::move(cluster_name),
469
- std::move(eds_service_name), std::move(lrs_load_reporting_server_name),
470
- std::move(locality_name));
471
- }
472
-
473
- private:
474
- static std::vector<grpc_error*> ParseLocality(
475
- const Json& json, RefCountedPtr<XdsLocalityName>* name) {
476
- std::vector<grpc_error*> error_list;
477
- if (json.type() != Json::Type::OBJECT) {
478
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
479
- "locality field is not an object"));
480
- return error_list;
481
- }
482
- std::string region;
483
- auto it = json.object_value().find("region");
484
- if (it != json.object_value().end()) {
485
- if (it->second.type() != Json::Type::STRING) {
486
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
487
- "\"region\" field is not a string"));
488
- } else {
489
- region = it->second.string_value();
490
- }
491
- }
492
- std::string zone;
493
- it = json.object_value().find("zone");
494
- if (it != json.object_value().end()) {
495
- if (it->second.type() != Json::Type::STRING) {
496
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
497
- "\"zone\" field is not a string"));
498
- } else {
499
- zone = it->second.string_value();
500
- }
501
- }
502
- std::string subzone;
503
- it = json.object_value().find("subzone");
504
- if (it != json.object_value().end()) {
505
- if (it->second.type() != Json::Type::STRING) {
506
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
507
- "\"subzone\" field is not a string"));
508
- } else {
509
- subzone = it->second.string_value();
510
- }
511
- }
512
- if (region.empty() && zone.empty() && subzone.empty()) {
513
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
514
- "at least one of region, zone, or subzone must be set"));
515
- }
516
- if (error_list.empty()) {
517
- *name = MakeRefCounted<XdsLocalityName>(region, zone, subzone);
518
- }
519
- return error_list;
520
- }
521
- };
522
-
523
- } // namespace
524
-
525
- } // namespace grpc_core
526
-
527
- //
528
- // Plugin registration
529
- //
530
-
531
- void grpc_lb_policy_lrs_init() {
532
- grpc_core::LoadBalancingPolicyRegistry::Builder::
533
- RegisterLoadBalancingPolicyFactory(
534
- absl::make_unique<grpc_core::LrsLbFactory>());
535
- }
536
-
537
- void grpc_lb_policy_lrs_shutdown() {}