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
@@ -20,6 +20,7 @@
20
20
  #include <grpc/support/port_platform.h>
21
21
 
22
22
  #include <set>
23
+ #include <vector>
23
24
 
24
25
  #include "absl/strings/string_view.h"
25
26
  #include "absl/types/optional.h"
@@ -27,28 +28,36 @@
27
28
  #include "src/core/ext/xds/xds_api.h"
28
29
  #include "src/core/ext/xds/xds_bootstrap.h"
29
30
  #include "src/core/ext/xds/xds_client_stats.h"
31
+ #include "src/core/lib/channel/channelz.h"
32
+ #include "src/core/lib/gprpp/dual_ref_counted.h"
30
33
  #include "src/core/lib/gprpp/map.h"
31
34
  #include "src/core/lib/gprpp/memory.h"
32
35
  #include "src/core/lib/gprpp/orphanable.h"
33
36
  #include "src/core/lib/gprpp/ref_counted.h"
34
37
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
35
- #include "src/core/lib/iomgr/work_serializer.h"
38
+ #include "src/core/lib/gprpp/sync.h"
36
39
 
37
40
  namespace grpc_core {
38
41
 
39
42
  extern TraceFlag xds_client_trace;
40
43
 
41
- class XdsClient : public InternallyRefCounted<XdsClient> {
44
+ class XdsClient : public DualRefCounted<XdsClient> {
42
45
  public:
43
46
  // Listener data watcher interface. Implemented by callers.
44
47
  class ListenerWatcherInterface {
45
48
  public:
46
49
  virtual ~ListenerWatcherInterface() = default;
47
-
48
- virtual void OnListenerChanged(std::vector<XdsApi::Route> routes) = 0;
49
-
50
+ virtual void OnListenerChanged(XdsApi::LdsUpdate listener) = 0;
50
51
  virtual void OnError(grpc_error* error) = 0;
52
+ virtual void OnResourceDoesNotExist() = 0;
53
+ };
51
54
 
55
+ // RouteConfiguration data watcher interface. Implemented by callers.
56
+ class RouteConfigWatcherInterface {
57
+ public:
58
+ virtual ~RouteConfigWatcherInterface() = default;
59
+ virtual void OnRouteConfigChanged(XdsApi::RdsUpdate route_config) = 0;
60
+ virtual void OnError(grpc_error* error) = 0;
52
61
  virtual void OnResourceDoesNotExist() = 0;
53
62
  };
54
63
 
@@ -56,11 +65,8 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
56
65
  class ClusterWatcherInterface {
57
66
  public:
58
67
  virtual ~ClusterWatcherInterface() = default;
59
-
60
68
  virtual void OnClusterChanged(XdsApi::CdsUpdate cluster_data) = 0;
61
-
62
69
  virtual void OnError(grpc_error* error) = 0;
63
-
64
70
  virtual void OnResourceDoesNotExist() = 0;
65
71
  };
66
72
 
@@ -68,24 +74,63 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
68
74
  class EndpointWatcherInterface {
69
75
  public:
70
76
  virtual ~EndpointWatcherInterface() = default;
71
-
72
77
  virtual void OnEndpointChanged(XdsApi::EdsUpdate update) = 0;
73
-
74
78
  virtual void OnError(grpc_error* error) = 0;
75
-
76
79
  virtual void OnResourceDoesNotExist() = 0;
77
80
  };
78
81
 
79
- // If *error is not GRPC_ERROR_NONE after construction, then there was
82
+ // Factory function to get or create the global XdsClient instance.
83
+ // If *error is not GRPC_ERROR_NONE upon return, then there was
80
84
  // an error initializing the client.
81
- XdsClient(std::shared_ptr<WorkSerializer> work_serializer,
82
- grpc_pollset_set* interested_parties, absl::string_view server_name,
83
- std::unique_ptr<ListenerWatcherInterface> watcher,
84
- const grpc_channel_args& channel_args, grpc_error** error);
85
+ static RefCountedPtr<XdsClient> GetOrCreate(grpc_error** error);
86
+
87
+ // Callers should not instantiate directly. Use GetOrCreate() instead.
88
+ explicit XdsClient(grpc_error** error);
85
89
  ~XdsClient();
86
90
 
91
+ grpc_pollset_set* interested_parties() const { return interested_parties_; }
92
+
93
+ // TODO(roth): When we add federation, there will be multiple channels
94
+ // inside the XdsClient, and the set of channels may change over time,
95
+ // but not every channel may use every one of the child channels, so
96
+ // this API will need to change. At minumum, we will need to hold a
97
+ // ref to the parent channelz node so that we can update its list of
98
+ // children as the set of xDS channels changes. However, we may also
99
+ // want to make this a bit more selective such that only those
100
+ // channels on which a given parent channel is actually requesting
101
+ // resources will actually be marked as its children.
102
+ void AddChannelzLinkage(channelz::ChannelNode* parent_channelz_node);
103
+ void RemoveChannelzLinkage(channelz::ChannelNode* parent_channelz_node);
104
+
87
105
  void Orphan() override;
88
106
 
107
+ // Start and cancel listener data watch for a listener.
108
+ // The XdsClient takes ownership of the watcher, but the caller may
109
+ // keep a raw pointer to the watcher, which may be used only for
110
+ // cancellation. (Because the caller does not own the watcher, the
111
+ // pointer must not be used for any other purpose.)
112
+ // If the caller is going to start a new watch after cancelling the
113
+ // old one, it should set delay_unsubscription to true.
114
+ void WatchListenerData(absl::string_view listener_name,
115
+ std::unique_ptr<ListenerWatcherInterface> watcher);
116
+ void CancelListenerDataWatch(absl::string_view listener_name,
117
+ ListenerWatcherInterface* watcher,
118
+ bool delay_unsubscription = false);
119
+
120
+ // Start and cancel route config data watch for a listener.
121
+ // The XdsClient takes ownership of the watcher, but the caller may
122
+ // keep a raw pointer to the watcher, which may be used only for
123
+ // cancellation. (Because the caller does not own the watcher, the
124
+ // pointer must not be used for any other purpose.)
125
+ // If the caller is going to start a new watch after cancelling the
126
+ // old one, it should set delay_unsubscription to true.
127
+ void WatchRouteConfigData(
128
+ absl::string_view route_config_name,
129
+ std::unique_ptr<RouteConfigWatcherInterface> watcher);
130
+ void CancelRouteConfigDataWatch(absl::string_view route_config_name,
131
+ RouteConfigWatcherInterface* watcher,
132
+ bool delay_unsubscription = false);
133
+
89
134
  // Start and cancel cluster data watch for a cluster.
90
135
  // The XdsClient takes ownership of the watcher, but the caller may
91
136
  // keep a raw pointer to the watcher, which may be used only for
@@ -136,24 +181,14 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
136
181
  // Resets connection backoff state.
137
182
  void ResetBackoff();
138
183
 
139
- // Helpers for encoding the XdsClient object in channel args.
140
- grpc_arg MakeChannelArg() const;
141
- static RefCountedPtr<XdsClient> GetFromChannelArgs(
142
- const grpc_channel_args& args);
143
- static grpc_channel_args* RemoveFromChannelArgs(
144
- const grpc_channel_args& args);
145
-
146
184
  private:
147
185
  // Contains a channel to the xds server and all the data related to the
148
186
  // channel. Holds a ref to the xds client object.
149
- // TODO(roth): This is separate from the XdsClient object because it was
150
- // originally designed to be able to swap itself out in case the
151
- // balancer name changed. Now that the balancer name is going to be
152
- // coming from the bootstrap file, we don't really need this level of
153
- // indirection unless we decide to support watching the bootstrap file
154
- // for changes. At some point, if we decide that we're never going to
155
- // need to do that, then we can eliminate this class and move its
156
- // contents directly into the XdsClient class.
187
+ //
188
+ // Currently, there is only one ChannelState object per XdsClient
189
+ // object, and it has essentially the same lifetime. But in the
190
+ // future, when we add federation support, a single XdsClient may have
191
+ // multiple underlying channels to talk to different xDS servers.
157
192
  class ChannelState : public InternallyRefCounted<ChannelState> {
158
193
  public:
159
194
  template <typename T>
@@ -162,7 +197,8 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
162
197
  class AdsCallState;
163
198
  class LrsCallState;
164
199
 
165
- ChannelState(RefCountedPtr<XdsClient> xds_client, grpc_channel* channel);
200
+ ChannelState(WeakRefCountedPtr<XdsClient> xds_client,
201
+ grpc_channel* channel);
166
202
  ~ChannelState();
167
203
 
168
204
  void Orphan() override;
@@ -188,7 +224,7 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
188
224
  class StateWatcher;
189
225
 
190
226
  // The owning xds client.
191
- RefCountedPtr<XdsClient> xds_client_;
227
+ WeakRefCountedPtr<XdsClient> xds_client_;
192
228
 
193
229
  // The channel and its status.
194
230
  grpc_channel* channel_;
@@ -200,6 +236,22 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
200
236
  OrphanablePtr<RetryableCall<LrsCallState>> lrs_calld_;
201
237
  };
202
238
 
239
+ struct ListenerState {
240
+ std::map<ListenerWatcherInterface*,
241
+ std::unique_ptr<ListenerWatcherInterface>>
242
+ watchers;
243
+ // The latest data seen from LDS.
244
+ absl::optional<XdsApi::LdsUpdate> update;
245
+ };
246
+
247
+ struct RouteConfigState {
248
+ std::map<RouteConfigWatcherInterface*,
249
+ std::unique_ptr<RouteConfigWatcherInterface>>
250
+ watchers;
251
+ // The latest data seen from RDS.
252
+ absl::optional<XdsApi::RdsUpdate> update;
253
+ };
254
+
203
255
  struct ClusterState {
204
256
  std::map<ClusterWatcherInterface*, std::unique_ptr<ClusterWatcherInterface>>
205
257
  watchers;
@@ -215,6 +267,10 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
215
267
  absl::optional<XdsApi::EdsUpdate> update;
216
268
  };
217
269
 
270
+ // TODO(roth): Change this to store exactly one instance of
271
+ // XdsClusterDropStats and exactly one instance of
272
+ // XdsClusterLocalityStats per locality. We can return multiple refs
273
+ // to the same object instead of registering multiple objects.
218
274
  struct LoadReportState {
219
275
  struct LocalityState {
220
276
  std::set<XdsClusterLocalityStats*> locality_stats;
@@ -222,7 +278,7 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
222
278
  };
223
279
 
224
280
  std::set<XdsClusterDropStats*> drop_stats;
225
- XdsClusterDropStats::DroppedRequestsMap deleted_drop_stats;
281
+ XdsClusterDropStats::Snapshot deleted_drop_stats;
226
282
  std::map<RefCountedPtr<XdsLocalityName>, LocalityState,
227
283
  XdsLocalityName::Less>
228
284
  locality_stats;
@@ -230,39 +286,32 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
230
286
  };
231
287
 
232
288
  // Sends an error notification to all watchers.
233
- void NotifyOnError(grpc_error* error);
289
+ void NotifyOnErrorLocked(grpc_error* error);
234
290
 
235
- XdsApi::ClusterLoadReportMap BuildLoadReportSnapshot(
291
+ XdsApi::ClusterLoadReportMap BuildLoadReportSnapshotLocked(
236
292
  bool send_all_clusters, const std::set<std::string>& clusters);
237
293
 
238
- // Channel arg vtable functions.
239
- static void* ChannelArgCopy(void* p);
240
- static void ChannelArgDestroy(void* p);
241
- static int ChannelArgCmp(void* p, void* q);
242
-
243
- static const grpc_arg_pointer_vtable kXdsClientVtable;
244
-
245
294
  const grpc_millis request_timeout_;
246
-
247
- std::shared_ptr<WorkSerializer> work_serializer_;
248
295
  grpc_pollset_set* interested_parties_;
249
-
250
296
  std::unique_ptr<XdsBootstrap> bootstrap_;
251
297
  XdsApi api_;
252
298
 
253
- const std::string server_name_;
254
- std::unique_ptr<ListenerWatcherInterface> listener_watcher_;
299
+ Mutex mu_;
255
300
 
256
301
  // The channel for communicating with the xds server.
257
302
  OrphanablePtr<ChannelState> chand_;
258
303
 
259
- absl::optional<XdsApi::LdsUpdate> lds_result_;
260
- absl::optional<XdsApi::RdsUpdate> rds_result_;
261
-
304
+ // One entry for each watched LDS resource.
305
+ std::map<std::string /*listener_name*/, ListenerState> listener_map_;
306
+ // One entry for each watched RDS resource.
307
+ std::map<std::string /*route_config_name*/, RouteConfigState>
308
+ route_config_map_;
262
309
  // One entry for each watched CDS resource.
263
310
  std::map<std::string /*cluster_name*/, ClusterState> cluster_map_;
264
311
  // One entry for each watched EDS resource.
265
312
  std::map<std::string /*eds_service_name*/, EndpointState> endpoint_map_;
313
+
314
+ // Load report data.
266
315
  std::map<
267
316
  std::pair<std::string /*cluster_name*/, std::string /*eds_service_name*/>,
268
317
  LoadReportState>
@@ -271,6 +320,11 @@ class XdsClient : public InternallyRefCounted<XdsClient> {
271
320
  bool shutting_down_ = false;
272
321
  };
273
322
 
323
+ namespace internal {
324
+ void SetXdsChannelArgsForTest(grpc_channel_args* args);
325
+ void UnsetGlobalXdsClientForTest();
326
+ } // namespace internal
327
+
274
328
  } // namespace grpc_core
275
329
 
276
330
  #endif /* GRPC_CORE_EXT_XDS_XDS_CLIENT_H */
@@ -29,6 +29,14 @@
29
29
 
30
30
  namespace grpc_core {
31
31
 
32
+ namespace {
33
+
34
+ uint64_t GetAndResetCounter(Atomic<uint64_t>* from) {
35
+ return from->Exchange(0, MemoryOrder::RELAXED);
36
+ }
37
+
38
+ } // namespace
39
+
32
40
  //
33
41
  // XdsClusterDropStats
34
42
  //
@@ -48,15 +56,21 @@ XdsClusterDropStats::~XdsClusterDropStats() {
48
56
  xds_client_.reset(DEBUG_LOCATION, "DropStats");
49
57
  }
50
58
 
51
- XdsClusterDropStats::DroppedRequestsMap
52
- XdsClusterDropStats::GetSnapshotAndReset() {
59
+ XdsClusterDropStats::Snapshot XdsClusterDropStats::GetSnapshotAndReset() {
60
+ Snapshot snapshot;
61
+ snapshot.uncategorized_drops = GetAndResetCounter(&uncategorized_drops_);
53
62
  MutexLock lock(&mu_);
54
- return std::move(dropped_requests_);
63
+ snapshot.categorized_drops = std::move(categorized_drops_);
64
+ return snapshot;
65
+ }
66
+
67
+ void XdsClusterDropStats::AddUncategorizedDrops() {
68
+ uncategorized_drops_.FetchAdd(1);
55
69
  }
56
70
 
57
71
  void XdsClusterDropStats::AddCallDropped(const std::string& category) {
58
72
  MutexLock lock(&mu_);
59
- ++dropped_requests_[category];
73
+ ++categorized_drops_[category];
60
74
  }
61
75
 
62
76
  //
@@ -79,14 +93,6 @@ XdsClusterLocalityStats::~XdsClusterLocalityStats() {
79
93
  xds_client_.reset(DEBUG_LOCATION, "LocalityStats");
80
94
  }
81
95
 
82
- namespace {
83
-
84
- uint64_t GetAndResetCounter(Atomic<uint64_t>* from) {
85
- return from->Exchange(0, MemoryOrder::RELAXED);
86
- }
87
-
88
- } // namespace
89
-
90
96
  XdsClusterLocalityStats::Snapshot
91
97
  XdsClusterLocalityStats::GetSnapshotAndReset() {
92
98
  Snapshot snapshot = {GetAndResetCounter(&total_successful_requests_),
@@ -28,6 +28,7 @@
28
28
  #include "absl/strings/str_format.h"
29
29
  #include "absl/strings/string_view.h"
30
30
 
31
+ #include "src/core/lib/gpr/useful.h"
31
32
  #include "src/core/lib/gprpp/atomic.h"
32
33
  #include "src/core/lib/gprpp/memory.h"
33
34
  #include "src/core/lib/gprpp/ref_counted.h"
@@ -45,6 +46,7 @@ class XdsLocalityName : public RefCounted<XdsLocalityName> {
45
46
  struct Less {
46
47
  bool operator()(const XdsLocalityName* lhs,
47
48
  const XdsLocalityName* rhs) const {
49
+ if (lhs == nullptr || rhs == nullptr) return GPR_ICMP(lhs, rhs);
48
50
  return lhs->Compare(*rhs) < 0;
49
51
  }
50
52
 
@@ -99,7 +101,31 @@ class XdsLocalityName : public RefCounted<XdsLocalityName> {
99
101
  // Drop stats for an xds cluster.
100
102
  class XdsClusterDropStats : public RefCounted<XdsClusterDropStats> {
101
103
  public:
102
- using DroppedRequestsMap = std::map<std::string /* category */, uint64_t>;
104
+ // The total number of requests dropped for any reason is the sum of
105
+ // uncategorized_drops, and dropped_requests map.
106
+ using CategorizedDropsMap = std::map<std::string /* category */, uint64_t>;
107
+ struct Snapshot {
108
+ uint64_t uncategorized_drops = 0;
109
+ // The number of requests dropped for the specific drop categories
110
+ // outlined in the drop_overloads field in the EDS response.
111
+ CategorizedDropsMap categorized_drops;
112
+
113
+ Snapshot& operator+=(const Snapshot& other) {
114
+ uncategorized_drops += other.uncategorized_drops;
115
+ for (const auto& p : other.categorized_drops) {
116
+ categorized_drops[p.first] += p.second;
117
+ }
118
+ return *this;
119
+ }
120
+
121
+ bool IsZero() const {
122
+ if (uncategorized_drops != 0) return false;
123
+ for (const auto& p : categorized_drops) {
124
+ if (p.second != 0) return false;
125
+ }
126
+ return true;
127
+ }
128
+ };
103
129
 
104
130
  XdsClusterDropStats(RefCountedPtr<XdsClient> xds_client,
105
131
  absl::string_view lrs_server_name,
@@ -108,8 +134,9 @@ class XdsClusterDropStats : public RefCounted<XdsClusterDropStats> {
108
134
  ~XdsClusterDropStats();
109
135
 
110
136
  // Returns a snapshot of this instance and resets all the counters.
111
- DroppedRequestsMap GetSnapshotAndReset();
137
+ Snapshot GetSnapshotAndReset();
112
138
 
139
+ void AddUncategorizedDrops();
113
140
  void AddCallDropped(const std::string& category);
114
141
 
115
142
  private:
@@ -117,11 +144,12 @@ class XdsClusterDropStats : public RefCounted<XdsClusterDropStats> {
117
144
  absl::string_view lrs_server_name_;
118
145
  absl::string_view cluster_name_;
119
146
  absl::string_view eds_service_name_;
120
- // Protects dropped_requests_. A mutex is necessary because the length of
121
- // dropped_requests_ can be accessed by both the picker (from data plane
147
+ Atomic<uint64_t> uncategorized_drops_{0};
148
+ // Protects categorized_drops_. A mutex is necessary because the length of
149
+ // dropped_requests can be accessed by both the picker (from data plane
122
150
  // mutex) and the load reporting thread (from the control plane combiner).
123
151
  Mutex mu_;
124
- DroppedRequestsMap dropped_requests_;
152
+ CategorizedDropsMap categorized_drops_;
125
153
  };
126
154
 
127
155
  // Locality stats for an xds cluster.
@@ -117,7 +117,6 @@ grpc_arg grpc_channel_arg_pointer_create(char* name, void* value,
117
117
  const grpc_arg_pointer_vtable* vtable);
118
118
 
119
119
  // Returns a string representing channel args in human-readable form.
120
- // Callers takes ownership of result.
121
120
  std::string grpc_channel_args_string(const grpc_channel_args* args);
122
121
 
123
122
  // Takes ownership of the old_args
@@ -48,40 +48,6 @@
48
48
  namespace grpc_core {
49
49
  namespace channelz {
50
50
 
51
- //
52
- // channel arg code
53
- //
54
-
55
- namespace {
56
-
57
- void* parent_uuid_copy(void* p) { return p; }
58
- void parent_uuid_destroy(void* /*p*/) {}
59
- int parent_uuid_cmp(void* p1, void* p2) { return GPR_ICMP(p1, p2); }
60
- const grpc_arg_pointer_vtable parent_uuid_vtable = {
61
- parent_uuid_copy, parent_uuid_destroy, parent_uuid_cmp};
62
-
63
- } // namespace
64
-
65
- grpc_arg MakeParentUuidArg(intptr_t parent_uuid) {
66
- // We would ideally like to store the uuid in an integer argument.
67
- // Unfortunately, that won't work, because intptr_t (the type used for
68
- // uuids) doesn't fit in an int (the type used for integer args).
69
- // So instead, we use a hack to store it as a pointer, because
70
- // intptr_t should be the same size as void*.
71
- static_assert(sizeof(intptr_t) <= sizeof(void*),
72
- "can't fit intptr_t inside of void*");
73
- return grpc_channel_arg_pointer_create(
74
- const_cast<char*>(GRPC_ARG_CHANNELZ_PARENT_UUID),
75
- reinterpret_cast<void*>(parent_uuid), &parent_uuid_vtable);
76
- }
77
-
78
- intptr_t GetParentUuidFromArgs(const grpc_channel_args& args) {
79
- const grpc_arg* arg =
80
- grpc_channel_args_find(&args, GRPC_ARG_CHANNELZ_PARENT_UUID);
81
- if (arg == nullptr || arg->type != GRPC_ARG_POINTER) return 0;
82
- return reinterpret_cast<intptr_t>(arg->value.pointer.p);
83
- }
84
-
85
51
  //
86
52
  // BaseNode
87
53
  //
@@ -171,13 +137,12 @@ void CallCountingHelper::PopulateCallCounts(Json::Object* object) {
171
137
  //
172
138
 
173
139
  ChannelNode::ChannelNode(std::string target, size_t channel_tracer_max_nodes,
174
- intptr_t parent_uuid)
175
- : BaseNode(parent_uuid == 0 ? EntityType::kTopLevelChannel
176
- : EntityType::kInternalChannel,
140
+ bool is_internal_channel)
141
+ : BaseNode(is_internal_channel ? EntityType::kInternalChannel
142
+ : EntityType::kTopLevelChannel,
177
143
  target),
178
144
  target_(std::move(target)),
179
- trace_(channel_tracer_max_nodes),
180
- parent_uuid_(parent_uuid) {}
145
+ trace_(channel_tracer_max_nodes) {}
181
146
 
182
147
  const char* ChannelNode::GetChannelConnectivityStateChangeString(
183
148
  grpc_connectivity_state state) {
@@ -235,18 +200,18 @@ void ChannelNode::PopulateChildRefs(Json::Object* json) {
235
200
  MutexLock lock(&child_mu_);
236
201
  if (!child_subchannels_.empty()) {
237
202
  Json::Array array;
238
- for (const auto& p : child_subchannels_) {
203
+ for (intptr_t subchannel_uuid : child_subchannels_) {
239
204
  array.emplace_back(Json::Object{
240
- {"subchannelId", std::to_string(p.first)},
205
+ {"subchannelId", std::to_string(subchannel_uuid)},
241
206
  });
242
207
  }
243
208
  (*json)["subchannelRef"] = std::move(array);
244
209
  }
245
210
  if (!child_channels_.empty()) {
246
211
  Json::Array array;
247
- for (const auto& p : child_channels_) {
212
+ for (intptr_t channel_uuid : child_channels_) {
248
213
  array.emplace_back(Json::Object{
249
- {"channelId", std::to_string(p.first)},
214
+ {"channelId", std::to_string(channel_uuid)},
250
215
  });
251
216
  }
252
217
  (*json)["channelRef"] = std::move(array);
@@ -261,7 +226,7 @@ void ChannelNode::SetConnectivityState(grpc_connectivity_state state) {
261
226
 
262
227
  void ChannelNode::AddChildChannel(intptr_t child_uuid) {
263
228
  MutexLock lock(&child_mu_);
264
- child_channels_.insert(std::make_pair(child_uuid, true));
229
+ child_channels_.insert(child_uuid);
265
230
  }
266
231
 
267
232
  void ChannelNode::RemoveChildChannel(intptr_t child_uuid) {
@@ -271,7 +236,7 @@ void ChannelNode::RemoveChildChannel(intptr_t child_uuid) {
271
236
 
272
237
  void ChannelNode::AddChildSubchannel(intptr_t child_uuid) {
273
238
  MutexLock lock(&child_mu_);
274
- child_subchannels_.insert(std::make_pair(child_uuid, true));
239
+ child_subchannels_.insert(child_uuid);
275
240
  }
276
241
 
277
242
  void ChannelNode::RemoveChildSubchannel(intptr_t child_uuid) {