grpc 1.60.2 → 1.61.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +208 -165
- data/include/grpc/event_engine/event_engine.h +59 -12
- data/include/grpc/event_engine/internal/memory_allocator_impl.h +6 -0
- data/include/grpc/event_engine/internal/slice_cast.h +12 -0
- data/include/grpc/event_engine/memory_allocator.h +3 -1
- data/include/grpc/event_engine/slice.h +5 -0
- data/include/grpc/grpc_security.h +22 -1
- data/include/grpc/impl/call.h +29 -0
- data/include/grpc/impl/channel_arg_names.h +12 -1
- data/include/grpc/impl/slice_type.h +1 -1
- data/include/grpc/module.modulemap +1 -0
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +54 -7
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.h +20 -6
- data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +10 -13
- data/src/core/ext/filters/channel_idle/channel_idle_filter.h +18 -10
- data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +326 -0
- data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.h +143 -0
- data/src/core/ext/filters/client_channel/backend_metric.cc +2 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +32 -6
- data/src/core/ext/filters/client_channel/client_channel_internal.h +2 -0
- data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +54 -21
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +2 -1
- data/src/core/ext/filters/client_channel/lb_policy/endpoint_list.cc +12 -15
- data/src/core/ext/filters/client_channel/lb_policy/endpoint_list.h +8 -5
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +139 -92
- data/src/core/ext/filters/client_channel/lb_policy/health_check_client.cc +9 -4
- data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +9 -4
- data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +10 -11
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +94 -93
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +5 -3
- data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +12 -15
- data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +38 -16
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +25 -28
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +10 -10
- data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/weighted_round_robin.cc +37 -35
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +11 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +504 -461
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +232 -122
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +8 -6
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc +642 -251
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.h +2 -6
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc +7 -8
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +3 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +6 -8
- data/src/core/ext/filters/client_channel/resolver/xds/xds_dependency_manager.cc +1031 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_dependency_manager.h +277 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +128 -270
- data/src/core/ext/filters/client_channel/resolver/xds/{xds_resolver.h → xds_resolver_attributes.h} +5 -4
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver_trace.cc +25 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver_trace.h +30 -0
- data/src/core/ext/filters/client_channel/retry_filter.cc +1 -0
- data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +35 -17
- data/src/core/ext/filters/deadline/deadline_filter.cc +12 -0
- data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +17 -13
- data/src/core/ext/filters/fault_injection/fault_injection_filter.h +13 -4
- data/src/core/ext/filters/http/client/http_client_filter.cc +23 -32
- data/src/core/ext/filters/http/client/http_client_filter.h +10 -5
- data/src/core/ext/filters/http/client_authority_filter.cc +14 -14
- data/src/core/ext/filters/http/client_authority_filter.h +12 -4
- data/src/core/ext/filters/http/http_filters_plugin.cc +42 -20
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +55 -80
- data/src/core/ext/filters/http/message_compress/compression_filter.h +54 -12
- data/src/core/ext/filters/http/message_compress/legacy_compression_filter.cc +325 -0
- data/src/core/ext/filters/http/message_compress/legacy_compression_filter.h +139 -0
- data/src/core/ext/filters/http/server/http_server_filter.cc +41 -41
- data/src/core/ext/filters/http/server/http_server_filter.h +11 -4
- data/src/core/ext/filters/message_size/message_size_filter.cc +56 -76
- data/src/core/ext/filters/message_size/message_size_filter.h +35 -23
- data/src/core/ext/filters/rbac/rbac_filter.cc +15 -11
- data/src/core/ext/filters/rbac/rbac_filter.h +11 -4
- data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +25 -13
- data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +47 -50
- data/src/core/ext/filters/stateful_session/stateful_session_filter.h +21 -4
- data/src/core/ext/transport/chttp2/alpn/alpn.cc +1 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -2
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +11 -2
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +68 -145
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -3
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +21 -82
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -8
- data/src/core/ext/transport/chttp2/transport/frame.cc +506 -0
- data/src/core/ext/transport/chttp2/transport/frame.h +214 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +33 -79
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +4 -7
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +27 -36
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +0 -2
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +122 -32
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +142 -37
- data/src/core/ext/transport/chttp2/transport/internal.h +1 -22
- data/src/core/ext/transport/chttp2/transport/parsing.cc +23 -37
- data/src/core/ext/transport/chttp2/transport/writing.cc +26 -58
- data/src/core/ext/transport/inproc/inproc_transport.cc +172 -13
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb.h +712 -0
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb_minitable.c +151 -0
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb_minitable.h +33 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.c +133 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.h +50 -0
- data/src/core/ext/xds/certificate_provider_store.cc +2 -1
- data/src/core/ext/xds/certificate_provider_store.h +0 -5
- data/src/core/ext/xds/xds_api.cc +31 -18
- data/src/core/ext/xds/xds_api.h +2 -2
- data/src/core/ext/xds/xds_bootstrap.h +3 -0
- data/src/core/ext/xds/xds_certificate_provider.cc +88 -287
- data/src/core/ext/xds/xds_certificate_provider.h +44 -111
- data/src/core/ext/xds/xds_client.cc +420 -414
- data/src/core/ext/xds/xds_client.h +31 -22
- data/src/core/ext/xds/xds_client_grpc.cc +3 -1
- data/src/core/ext/xds/xds_cluster.cc +104 -11
- data/src/core/ext/xds/xds_cluster.h +9 -1
- data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +9 -5
- data/src/core/ext/xds/xds_common_types.cc +14 -10
- data/src/core/ext/xds/xds_endpoint.cc +9 -4
- data/src/core/ext/xds/xds_endpoint.h +5 -1
- data/src/core/ext/xds/xds_health_status.cc +12 -2
- data/src/core/ext/xds/xds_health_status.h +4 -2
- data/src/core/ext/xds/xds_http_rbac_filter.cc +5 -3
- data/src/core/ext/xds/xds_listener.cc +14 -8
- data/src/core/ext/xds/xds_resource_type_impl.h +6 -4
- data/src/core/ext/xds/xds_route_config.cc +34 -22
- data/src/core/ext/xds/xds_route_config.h +1 -0
- data/src/core/ext/xds/xds_server_config_fetcher.cc +61 -57
- data/src/core/ext/xds/xds_transport.h +3 -0
- data/src/core/ext/xds/xds_transport_grpc.cc +47 -50
- data/src/core/ext/xds/xds_transport_grpc.h +4 -0
- data/src/core/lib/channel/call_tracer.cc +12 -0
- data/src/core/lib/channel/call_tracer.h +17 -3
- data/src/core/lib/channel/channel_args.cc +24 -14
- data/src/core/lib/channel/channel_args.h +74 -13
- data/src/core/lib/channel/channel_stack.cc +27 -0
- data/src/core/lib/channel/channel_stack.h +10 -10
- data/src/core/lib/channel/connected_channel.cc +64 -18
- data/src/core/lib/channel/promise_based_filter.h +1041 -1
- data/src/core/lib/channel/server_call_tracer_filter.cc +43 -35
- data/src/core/lib/compression/compression_internal.cc +0 -3
- data/src/core/lib/event_engine/ares_resolver.cc +35 -14
- data/src/core/lib/event_engine/ares_resolver.h +9 -10
- data/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc +8 -1
- data/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.cc +132 -0
- data/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.h +61 -0
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +52 -36
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +4 -9
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +11 -3
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +9 -2
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +7 -0
- data/src/core/lib/event_engine/posix_engine/timer_manager.cc +17 -27
- data/src/core/lib/event_engine/posix_engine/timer_manager.h +0 -3
- data/src/core/lib/event_engine/ref_counted_dns_resolver_interface.h +55 -0
- data/src/core/lib/event_engine/windows/native_windows_dns_resolver.cc +114 -0
- data/src/core/lib/event_engine/windows/native_windows_dns_resolver.h +51 -0
- data/src/core/lib/event_engine/windows/windows_engine.cc +7 -7
- data/src/core/lib/experiments/config.cc +13 -0
- data/src/core/lib/experiments/config.h +3 -0
- data/src/core/lib/experiments/experiments.cc +245 -366
- data/src/core/lib/experiments/experiments.h +50 -156
- data/src/core/lib/gprpp/debug_location.h +13 -0
- data/src/core/lib/gprpp/dual_ref_counted.h +36 -7
- data/src/core/lib/gprpp/orphanable.h +27 -0
- data/src/core/lib/gprpp/ref_counted.h +63 -22
- data/src/core/lib/gprpp/ref_counted_ptr.h +70 -27
- data/src/core/lib/gprpp/ref_counted_string.h +13 -0
- data/src/core/lib/gprpp/status_helper.cc +1 -2
- data/src/core/lib/iomgr/combiner.cc +15 -51
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +31 -0
- data/src/core/lib/iomgr/event_engine_shims/endpoint.h +16 -0
- data/src/core/lib/iomgr/tcp_client_posix.cc +4 -3
- data/src/core/lib/load_balancing/lb_policy.h +1 -1
- data/src/core/lib/promise/activity.cc +17 -2
- data/src/core/lib/promise/activity.h +5 -4
- data/src/core/lib/promise/all_ok.h +80 -0
- data/src/core/lib/promise/detail/join_state.h +2077 -0
- data/src/core/lib/promise/detail/promise_factory.h +1 -0
- data/src/core/lib/promise/detail/promise_like.h +8 -1
- data/src/core/lib/promise/detail/seq_state.h +3458 -150
- data/src/core/lib/promise/detail/status.h +42 -5
- data/src/core/lib/promise/for_each.h +13 -1
- data/src/core/lib/promise/if.h +4 -0
- data/src/core/lib/promise/latch.h +6 -3
- data/src/core/lib/promise/party.cc +33 -31
- data/src/core/lib/promise/party.h +142 -6
- data/src/core/lib/promise/poll.h +39 -13
- data/src/core/lib/promise/promise.h +4 -0
- data/src/core/lib/promise/seq.h +107 -7
- data/src/core/lib/promise/status_flag.h +196 -0
- data/src/core/lib/promise/try_join.h +132 -0
- data/src/core/lib/promise/try_seq.h +132 -10
- data/src/core/lib/resolver/endpoint_addresses.cc +0 -1
- data/src/core/lib/resolver/endpoint_addresses.h +48 -0
- data/src/core/lib/resource_quota/arena.h +2 -2
- data/src/core/lib/resource_quota/memory_quota.cc +57 -8
- data/src/core/lib/resource_quota/memory_quota.h +6 -0
- data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +14 -11
- data/src/core/lib/security/authorization/grpc_server_authz_filter.h +14 -5
- data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +4 -0
- data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +4 -0
- data/src/core/lib/security/credentials/external/external_account_credentials.cc +28 -20
- data/src/core/lib/security/credentials/external/external_account_credentials.h +4 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +4 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.h +4 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +4 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.h +4 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +2 -1
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +0 -3
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +12 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_crl_provider.cc +22 -5
- data/src/core/lib/security/credentials/tls/grpc_tls_crl_provider.h +1 -5
- data/src/core/lib/security/credentials/tls/tls_credentials.cc +16 -0
- data/src/core/lib/security/credentials/xds/xds_credentials.cc +21 -28
- data/src/core/lib/security/credentials/xds/xds_credentials.h +2 -4
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +4 -3
- data/src/core/lib/security/transport/auth_filters.h +71 -4
- data/src/core/lib/security/transport/client_auth_filter.cc +2 -4
- data/src/core/lib/security/transport/legacy_server_auth_filter.cc +244 -0
- data/src/core/lib/security/transport/server_auth_filter.cc +70 -90
- data/src/core/lib/slice/slice_buffer.h +3 -0
- data/src/core/lib/surface/builtins.cc +1 -1
- data/src/core/lib/surface/call.cc +683 -196
- data/src/core/lib/surface/call.h +26 -13
- data/src/core/lib/surface/call_trace.cc +42 -1
- data/src/core/lib/surface/channel.cc +0 -1
- data/src/core/lib/surface/channel.h +0 -6
- data/src/core/lib/surface/channel_init.h +26 -0
- data/src/core/lib/surface/init.cc +14 -8
- data/src/core/lib/surface/server.cc +256 -237
- data/src/core/lib/surface/server.h +26 -54
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/surface/wait_for_cq_end_op.h +94 -0
- data/src/core/lib/transport/call_final_info.cc +38 -0
- data/src/core/lib/transport/call_final_info.h +54 -0
- data/src/core/lib/transport/connectivity_state.cc +3 -2
- data/src/core/lib/transport/connectivity_state.h +4 -0
- data/src/core/lib/transport/metadata_batch.h +4 -4
- data/src/core/lib/transport/transport.cc +70 -19
- data/src/core/lib/transport/transport.h +395 -25
- data/src/core/plugin_registry/grpc_plugin_registry.cc +3 -0
- data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +0 -3
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +1 -1
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +1 -1
- data/src/core/tsi/ssl_transport_security.cc +65 -43
- data/src/ruby/ext/grpc/rb_channel_args.c +3 -1
- data/src/ruby/ext/grpc/rb_grpc.c +0 -1
- data/src/ruby/ext/grpc/rb_grpc.h +0 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/upb/upb/reflection/def_pool.h +2 -2
- data/third_party/zlib/adler32.c +5 -27
- data/third_party/zlib/compress.c +5 -16
- data/third_party/zlib/crc32.c +86 -162
- data/third_party/zlib/deflate.c +233 -336
- data/third_party/zlib/deflate.h +8 -8
- data/third_party/zlib/gzguts.h +11 -12
- data/third_party/zlib/infback.c +7 -23
- data/third_party/zlib/inffast.c +1 -4
- data/third_party/zlib/inffast.h +1 -1
- data/third_party/zlib/inflate.c +30 -99
- data/third_party/zlib/inftrees.c +6 -11
- data/third_party/zlib/inftrees.h +3 -3
- data/third_party/zlib/trees.c +224 -302
- data/third_party/zlib/uncompr.c +4 -12
- data/third_party/zlib/zconf.h +6 -2
- data/third_party/zlib/zlib.h +191 -188
- data/third_party/zlib/zutil.c +16 -44
- data/third_party/zlib/zutil.h +10 -10
- metadata +35 -13
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +0 -1173
- data/src/core/lib/event_engine/memory_allocator.cc +0 -74
- data/src/core/lib/transport/pid_controller.cc +0 -51
- data/src/core/lib/transport/pid_controller.h +0 -116
- data/third_party/upb/upb/collections/array.h +0 -17
- data/third_party/upb/upb/collections/map.h +0 -17
- data/third_party/upb/upb/upb.hpp +0 -18
@@ -37,10 +37,10 @@
|
|
37
37
|
#include <grpc/support/json.h>
|
38
38
|
#include <grpc/support/log.h>
|
39
39
|
|
40
|
+
#include "src/core/ext/filters/client_channel/lb_policy/address_filtering.h"
|
40
41
|
#include "src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h"
|
41
|
-
#include "src/core/ext/xds/
|
42
|
-
#include "src/core/ext/xds/
|
43
|
-
#include "src/core/ext/xds/xds_client_grpc.h"
|
42
|
+
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h"
|
43
|
+
#include "src/core/ext/filters/client_channel/resolver/xds/xds_dependency_manager.h"
|
44
44
|
#include "src/core/ext/xds/xds_cluster.h"
|
45
45
|
#include "src/core/ext/xds/xds_common_types.h"
|
46
46
|
#include "src/core/ext/xds/xds_health_status.h"
|
@@ -48,6 +48,7 @@
|
|
48
48
|
#include "src/core/lib/config/core_configuration.h"
|
49
49
|
#include "src/core/lib/debug/trace.h"
|
50
50
|
#include "src/core/lib/gprpp/debug_location.h"
|
51
|
+
#include "src/core/lib/gprpp/env.h"
|
51
52
|
#include "src/core/lib/gprpp/match.h"
|
52
53
|
#include "src/core/lib/gprpp/orphanable.h"
|
53
54
|
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
@@ -63,11 +64,6 @@
|
|
63
64
|
#include "src/core/lib/load_balancing/lb_policy.h"
|
64
65
|
#include "src/core/lib/load_balancing/lb_policy_factory.h"
|
65
66
|
#include "src/core/lib/load_balancing/lb_policy_registry.h"
|
66
|
-
#include "src/core/lib/matchers/matchers.h"
|
67
|
-
#include "src/core/lib/security/credentials/credentials.h"
|
68
|
-
#include "src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h"
|
69
|
-
#include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h"
|
70
|
-
#include "src/core/lib/security/credentials/xds/xds_credentials.h"
|
71
67
|
|
72
68
|
namespace grpc_core {
|
73
69
|
|
@@ -75,9 +71,18 @@ TraceFlag grpc_cds_lb_trace(false, "cds_lb");
|
|
75
71
|
|
76
72
|
namespace {
|
77
73
|
|
78
|
-
|
74
|
+
// TODO(roth): Remove this after the 1.63 release.
|
75
|
+
bool XdsAggregateClusterBackwardCompatibilityEnabled() {
|
76
|
+
auto value = GetEnv("GRPC_XDS_AGGREGATE_CLUSTER_BACKWARD_COMPAT");
|
77
|
+
if (!value.has_value()) return false;
|
78
|
+
bool parsed_value;
|
79
|
+
bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value);
|
80
|
+
return parse_succeeded && parsed_value;
|
81
|
+
}
|
79
82
|
|
80
|
-
|
83
|
+
using XdsConfig = XdsDependencyManager::XdsConfig;
|
84
|
+
|
85
|
+
constexpr absl::string_view kCds = "cds_experimental";
|
81
86
|
|
82
87
|
// Config for this LB policy.
|
83
88
|
class CdsLbConfig : public LoadBalancingPolicy::Config {
|
@@ -90,24 +95,29 @@ class CdsLbConfig : public LoadBalancingPolicy::Config {
|
|
90
95
|
CdsLbConfig(CdsLbConfig&& other) = delete;
|
91
96
|
CdsLbConfig& operator=(CdsLbConfig&& other) = delete;
|
92
97
|
|
93
|
-
const std::string& cluster() const { return cluster_; }
|
94
98
|
absl::string_view name() const override { return kCds; }
|
95
99
|
|
100
|
+
const std::string& cluster() const { return cluster_; }
|
101
|
+
bool is_dynamic() const { return is_dynamic_; }
|
102
|
+
|
96
103
|
static const JsonLoaderInterface* JsonLoader(const JsonArgs&) {
|
97
|
-
static const auto* loader =
|
98
|
-
|
99
|
-
|
104
|
+
static const auto* loader =
|
105
|
+
JsonObjectLoader<CdsLbConfig>()
|
106
|
+
.Field("cluster", &CdsLbConfig::cluster_)
|
107
|
+
.OptionalField("isDynamic", &CdsLbConfig::is_dynamic_)
|
108
|
+
.Finish();
|
100
109
|
return loader;
|
101
110
|
}
|
102
111
|
|
103
112
|
private:
|
104
113
|
std::string cluster_;
|
114
|
+
bool is_dynamic_ = false;
|
105
115
|
};
|
106
116
|
|
107
117
|
// CDS LB policy.
|
108
118
|
class CdsLb : public LoadBalancingPolicy {
|
109
119
|
public:
|
110
|
-
CdsLb(
|
120
|
+
explicit CdsLb(Args args);
|
111
121
|
|
112
122
|
absl::string_view name() const override { return kCds; }
|
113
123
|
|
@@ -116,92 +126,52 @@ class CdsLb : public LoadBalancingPolicy {
|
|
116
126
|
void ExitIdleLocked() override;
|
117
127
|
|
118
128
|
private:
|
119
|
-
//
|
120
|
-
|
121
|
-
public:
|
122
|
-
ClusterWatcher(RefCountedPtr<CdsLb> parent, std::string name)
|
123
|
-
: parent_(std::move(parent)), name_(std::move(name)) {}
|
124
|
-
|
125
|
-
void OnResourceChanged(
|
126
|
-
std::shared_ptr<const XdsClusterResource> cluster_data) override {
|
127
|
-
RefCountedPtr<ClusterWatcher> self = Ref();
|
128
|
-
parent_->work_serializer()->Run(
|
129
|
-
[self = std::move(self),
|
130
|
-
cluster_data = std::move(cluster_data)]() mutable {
|
131
|
-
self->parent_->OnClusterChanged(self->name_,
|
132
|
-
std::move(cluster_data));
|
133
|
-
},
|
134
|
-
DEBUG_LOCATION);
|
135
|
-
}
|
136
|
-
void OnError(absl::Status status) override {
|
137
|
-
RefCountedPtr<ClusterWatcher> self = Ref();
|
138
|
-
parent_->work_serializer()->Run(
|
139
|
-
[self = std::move(self), status = std::move(status)]() mutable {
|
140
|
-
self->parent_->OnError(self->name_, std::move(status));
|
141
|
-
},
|
142
|
-
DEBUG_LOCATION);
|
143
|
-
}
|
144
|
-
void OnResourceDoesNotExist() override {
|
145
|
-
RefCountedPtr<ClusterWatcher> self = Ref();
|
146
|
-
parent_->work_serializer()->Run(
|
147
|
-
[self = std::move(self)]() {
|
148
|
-
self->parent_->OnResourceDoesNotExist(self->name_);
|
149
|
-
},
|
150
|
-
DEBUG_LOCATION);
|
151
|
-
}
|
129
|
+
// Delegating helper to be passed to child policy.
|
130
|
+
using Helper = ParentOwningDelegatingChannelControlHelper<CdsLb>;
|
152
131
|
|
153
|
-
|
154
|
-
|
155
|
-
std::
|
156
|
-
|
132
|
+
// State used to retain child policy names for the priority policy.
|
133
|
+
struct ChildNameState {
|
134
|
+
std::vector<size_t /*child_number*/> priority_child_numbers;
|
135
|
+
size_t next_available_child_number = 0;
|
157
136
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
// Most recent update obtained from this watcher.
|
163
|
-
std::shared_ptr<const XdsClusterResource> update;
|
137
|
+
void Reset() {
|
138
|
+
priority_child_numbers.clear();
|
139
|
+
next_available_child_number = 0;
|
140
|
+
}
|
164
141
|
};
|
165
142
|
|
166
|
-
// Delegating helper to be passed to child policy.
|
167
|
-
using Helper = ParentOwningDelegatingChannelControlHelper<CdsLb>;
|
168
|
-
|
169
143
|
~CdsLb() override;
|
170
144
|
|
171
145
|
void ShutdownLocked() override;
|
172
146
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
absl::Status UpdateXdsCertificateProvider(
|
182
|
-
const std::string& cluster_name, const XdsClusterResource& cluster_data);
|
147
|
+
// Computes child numbers for new_cluster, reusing child numbers
|
148
|
+
// from old_cluster and child_name_state_ in an intelligent
|
149
|
+
// way to avoid unnecessary churn.
|
150
|
+
ChildNameState ComputeChildNames(
|
151
|
+
const XdsConfig::ClusterConfig* old_cluster,
|
152
|
+
const XdsConfig::ClusterConfig& new_cluster,
|
153
|
+
const XdsConfig::ClusterConfig::EndpointConfig& endpoint_config) const;
|
183
154
|
|
184
|
-
|
185
|
-
ClusterWatcher* watcher,
|
186
|
-
bool delay_unsubscription = false);
|
155
|
+
std::string GetChildPolicyName(const std::string& cluster, size_t priority);
|
187
156
|
|
188
|
-
|
157
|
+
Json CreateChildPolicyConfigForLeafCluster(
|
158
|
+
const XdsConfig::ClusterConfig& new_cluster,
|
159
|
+
const XdsConfig::ClusterConfig::EndpointConfig& endpoint_config,
|
160
|
+
const XdsClusterResource* aggregate_cluster_resource);
|
161
|
+
Json CreateChildPolicyConfigForAggregateCluster(
|
162
|
+
const XdsConfig::ClusterConfig::AggregateConfig& aggregate_config);
|
189
163
|
|
190
|
-
|
164
|
+
void ResetState();
|
191
165
|
|
192
|
-
|
193
|
-
ChannelArgs args_;
|
166
|
+
void ReportTransientFailure(absl::Status status);
|
194
167
|
|
195
|
-
|
196
|
-
RefCountedPtr<
|
168
|
+
std::string cluster_name_;
|
169
|
+
RefCountedPtr<const XdsConfig> xds_config_;
|
197
170
|
|
198
|
-
//
|
199
|
-
|
200
|
-
std::map<std::string, WatcherState> watchers_;
|
171
|
+
// Cluster subscription, for dynamic clusters (e.g., RLS).
|
172
|
+
RefCountedPtr<XdsDependencyManager::ClusterSubscription> subscription_;
|
201
173
|
|
202
|
-
|
203
|
-
RefCountedPtr<grpc_tls_certificate_provider> identity_certificate_provider_;
|
204
|
-
RefCountedPtr<XdsCertificateProvider> xds_certificate_provider_;
|
174
|
+
ChildNameState child_name_state_;
|
205
175
|
|
206
176
|
// Child LB policy.
|
207
177
|
OrphanablePtr<LoadBalancingPolicy> child_policy_;
|
@@ -214,11 +184,9 @@ class CdsLb : public LoadBalancingPolicy {
|
|
214
184
|
// CdsLb
|
215
185
|
//
|
216
186
|
|
217
|
-
CdsLb::CdsLb(
|
218
|
-
: LoadBalancingPolicy(std::move(args)), xds_client_(std::move(xds_client)) {
|
187
|
+
CdsLb::CdsLb(Args args) : LoadBalancingPolicy(std::move(args)) {
|
219
188
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
220
|
-
gpr_log(GPR_INFO, "[cdslb %p] created
|
221
|
-
xds_client_.get());
|
189
|
+
gpr_log(GPR_INFO, "[cdslb %p] created", this);
|
222
190
|
}
|
223
191
|
}
|
224
192
|
|
@@ -233,28 +201,7 @@ void CdsLb::ShutdownLocked() {
|
|
233
201
|
gpr_log(GPR_INFO, "[cdslb %p] shutting down", this);
|
234
202
|
}
|
235
203
|
shutting_down_ = true;
|
236
|
-
|
237
|
-
if (xds_client_ != nullptr) {
|
238
|
-
for (auto& watcher : watchers_) {
|
239
|
-
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
240
|
-
gpr_log(GPR_INFO, "[cdslb %p] cancelling watch for cluster %s", this,
|
241
|
-
watcher.first.c_str());
|
242
|
-
}
|
243
|
-
CancelClusterDataWatch(watcher.first, watcher.second.watcher,
|
244
|
-
/*delay_unsubscription=*/false);
|
245
|
-
}
|
246
|
-
watchers_.clear();
|
247
|
-
xds_client_.reset(DEBUG_LOCATION, "CdsLb");
|
248
|
-
}
|
249
|
-
args_ = ChannelArgs();
|
250
|
-
}
|
251
|
-
|
252
|
-
void CdsLb::MaybeDestroyChildPolicyLocked() {
|
253
|
-
if (child_policy_ != nullptr) {
|
254
|
-
grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
|
255
|
-
interested_parties());
|
256
|
-
child_policy_.reset();
|
257
|
-
}
|
204
|
+
ResetState();
|
258
205
|
}
|
259
206
|
|
260
207
|
void CdsLb::ResetBackoffLocked() {
|
@@ -265,101 +212,420 @@ void CdsLb::ExitIdleLocked() {
|
|
265
212
|
if (child_policy_ != nullptr) child_policy_->ExitIdleLocked();
|
266
213
|
}
|
267
214
|
|
215
|
+
// We need at least one priority for each discovery mechanism, just so that we
|
216
|
+
// have a child in which to create the xds_cluster_impl policy. This ensures
|
217
|
+
// that we properly handle the case of a discovery mechanism dropping 100% of
|
218
|
+
// calls, the OnError() case, and the OnResourceDoesNotExist() case.
|
219
|
+
const XdsEndpointResource::PriorityList& GetUpdatePriorityList(
|
220
|
+
const XdsEndpointResource* update) {
|
221
|
+
static const NoDestruct<XdsEndpointResource::PriorityList>
|
222
|
+
kPriorityListWithEmptyPriority(1);
|
223
|
+
if (update == nullptr || update->priorities.empty()) {
|
224
|
+
return *kPriorityListWithEmptyPriority;
|
225
|
+
}
|
226
|
+
return update->priorities;
|
227
|
+
}
|
228
|
+
|
229
|
+
std::string MakeChildPolicyName(absl::string_view cluster,
|
230
|
+
size_t child_number) {
|
231
|
+
return absl::StrCat("{cluster=", cluster, ", child_number=", child_number,
|
232
|
+
"}");
|
233
|
+
}
|
234
|
+
|
235
|
+
class PriorityEndpointIterator : public EndpointAddressesIterator {
|
236
|
+
public:
|
237
|
+
PriorityEndpointIterator(
|
238
|
+
std::string cluster_name,
|
239
|
+
std::shared_ptr<const XdsEndpointResource> endpoints,
|
240
|
+
std::vector<size_t /*child_number*/> priority_child_numbers)
|
241
|
+
: cluster_name_(std::move(cluster_name)),
|
242
|
+
endpoints_(std::move(endpoints)),
|
243
|
+
priority_child_numbers_(std::move(priority_child_numbers)) {}
|
244
|
+
|
245
|
+
void ForEach(absl::FunctionRef<void(const EndpointAddresses&)> callback)
|
246
|
+
const override {
|
247
|
+
const auto& priority_list = GetUpdatePriorityList(endpoints_.get());
|
248
|
+
for (size_t priority = 0; priority < priority_list.size(); ++priority) {
|
249
|
+
const auto& priority_entry = priority_list[priority];
|
250
|
+
std::string priority_child_name =
|
251
|
+
MakeChildPolicyName(cluster_name_, priority_child_numbers_[priority]);
|
252
|
+
for (const auto& p : priority_entry.localities) {
|
253
|
+
const auto& locality_name = p.first;
|
254
|
+
const auto& locality = p.second;
|
255
|
+
std::vector<RefCountedStringValue> hierarchical_path = {
|
256
|
+
RefCountedStringValue(priority_child_name),
|
257
|
+
RefCountedStringValue(locality_name->AsHumanReadableString())};
|
258
|
+
auto hierarchical_path_attr =
|
259
|
+
MakeRefCounted<HierarchicalPathArg>(std::move(hierarchical_path));
|
260
|
+
for (const auto& endpoint : locality.endpoints) {
|
261
|
+
uint32_t endpoint_weight =
|
262
|
+
locality.lb_weight *
|
263
|
+
endpoint.args().GetInt(GRPC_ARG_ADDRESS_WEIGHT).value_or(1);
|
264
|
+
callback(EndpointAddresses(
|
265
|
+
endpoint.addresses(),
|
266
|
+
endpoint.args()
|
267
|
+
.SetObject(hierarchical_path_attr)
|
268
|
+
.Set(GRPC_ARG_ADDRESS_WEIGHT, endpoint_weight)
|
269
|
+
.SetObject(locality_name->Ref())
|
270
|
+
.Set(GRPC_ARG_XDS_LOCALITY_WEIGHT, locality.lb_weight)));
|
271
|
+
}
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
private:
|
277
|
+
std::string cluster_name_;
|
278
|
+
std::shared_ptr<const XdsEndpointResource> endpoints_;
|
279
|
+
std::vector<size_t /*child_number*/> priority_child_numbers_;
|
280
|
+
};
|
281
|
+
|
268
282
|
absl::Status CdsLb::UpdateLocked(UpdateArgs args) {
|
269
|
-
//
|
270
|
-
auto
|
271
|
-
config_ = std::move(args.config);
|
283
|
+
// Get new config.
|
284
|
+
auto new_config = args.config.TakeAsSubclass<CdsLbConfig>();
|
272
285
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
273
|
-
gpr_log(GPR_INFO, "[cdslb %p] received update: cluster=%s",
|
274
|
-
|
286
|
+
gpr_log(GPR_INFO, "[cdslb %p] received update: cluster=%s is_dynamic=%d",
|
287
|
+
this, new_config->cluster().c_str(), new_config->is_dynamic());
|
288
|
+
}
|
289
|
+
GPR_ASSERT(new_config != nullptr);
|
290
|
+
// Cluster name should never change, because we should use a different
|
291
|
+
// child name in xds_cluster_manager in that case.
|
292
|
+
if (cluster_name_.empty()) {
|
293
|
+
cluster_name_ = new_config->cluster();
|
294
|
+
} else {
|
295
|
+
GPR_ASSERT(cluster_name_ == new_config->cluster());
|
275
296
|
}
|
276
|
-
//
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
297
|
+
// Get xDS config.
|
298
|
+
auto new_xds_config = args.args.GetObjectRef<XdsConfig>();
|
299
|
+
if (new_xds_config == nullptr) {
|
300
|
+
// Should never happen.
|
301
|
+
absl::Status status =
|
302
|
+
absl::InternalError("xDS config not passed to CDS LB policy");
|
303
|
+
ReportTransientFailure(status);
|
304
|
+
return status;
|
305
|
+
}
|
306
|
+
auto it = new_xds_config->clusters.find(cluster_name_);
|
307
|
+
if (it == new_xds_config->clusters.end()) {
|
308
|
+
// Cluster not present.
|
309
|
+
if (new_config->is_dynamic()) {
|
310
|
+
// This is a dynamic cluster. Subscribe to it if not yet subscribed.
|
311
|
+
if (subscription_ == nullptr) {
|
312
|
+
auto* dependency_mgr = args.args.GetObject<XdsDependencyManager>();
|
313
|
+
if (dependency_mgr == nullptr) {
|
314
|
+
// Should never happen.
|
315
|
+
absl::Status status = absl::InternalError(
|
316
|
+
"xDS dependency mgr not passed to CDS LB policy");
|
317
|
+
ReportTransientFailure(status);
|
318
|
+
return status;
|
285
319
|
}
|
286
|
-
|
287
|
-
|
320
|
+
subscription_ = dependency_mgr->GetClusterSubscription(cluster_name_);
|
321
|
+
// Stay in CONNECTING until we get an update that has the cluster.
|
322
|
+
return absl::OkStatus();
|
323
|
+
}
|
324
|
+
// If we are already subscribed, it's possible that we just
|
325
|
+
// recently subscribed but another update came through before we
|
326
|
+
// got the new cluster, in which case it will still be missing.
|
327
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
328
|
+
gpr_log(GPR_INFO,
|
329
|
+
"[cdslb %p] xDS config has no entry for dynamic cluster %s, "
|
330
|
+
"ignoring update",
|
331
|
+
this, cluster_name_.c_str());
|
288
332
|
}
|
289
|
-
|
333
|
+
// Stay in CONNECTING until we get an update that has the cluster.
|
334
|
+
return absl::OkStatus();
|
290
335
|
}
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
336
|
+
// Not a dynamic cluster. This should never happen.
|
337
|
+
absl::Status status = absl::UnavailableError(absl::StrCat(
|
338
|
+
"xDS config has no entry for static cluster ", cluster_name_));
|
339
|
+
ReportTransientFailure(status);
|
340
|
+
return status;
|
295
341
|
}
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
//
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
342
|
+
auto& new_cluster_config = it->second;
|
343
|
+
// If new list is not OK, report TRANSIENT_FAILURE.
|
344
|
+
if (!new_cluster_config.ok()) {
|
345
|
+
ReportTransientFailure(new_cluster_config.status());
|
346
|
+
return new_cluster_config.status();
|
347
|
+
}
|
348
|
+
GPR_ASSERT(new_cluster_config->cluster != nullptr);
|
349
|
+
// Find old cluster, if any.
|
350
|
+
const XdsConfig::ClusterConfig* old_cluster_config = nullptr;
|
351
|
+
if (xds_config_ != nullptr) {
|
352
|
+
auto it_old = xds_config_->clusters.find(cluster_name_);
|
353
|
+
if (it_old != xds_config_->clusters.end() && it_old->second.ok()) {
|
354
|
+
old_cluster_config = &*it_old->second;
|
355
|
+
// If nothing changed for a leaf cluster, then ignore the update.
|
356
|
+
// Can't do this for an aggregate cluster, because even if the aggregate
|
357
|
+
// cluster itself didn't change, the leaf clusters may have changed.
|
358
|
+
if (*new_cluster_config == *old_cluster_config &&
|
359
|
+
absl::holds_alternative<XdsConfig::ClusterConfig::EndpointConfig>(
|
360
|
+
new_cluster_config->children)) {
|
361
|
+
return absl::OkStatus();
|
362
|
+
}
|
363
|
+
}
|
313
364
|
}
|
314
|
-
|
315
|
-
|
365
|
+
// TODO(roth): Remove this after the 1.63 release.
|
366
|
+
const XdsClusterResource* aggregate_cluster_resource = nullptr;
|
367
|
+
static constexpr absl::string_view kArgXdsAggregateClusterName =
|
368
|
+
GRPC_ARG_NO_SUBCHANNEL_PREFIX "xds_aggregate_cluster_name";
|
369
|
+
if (XdsAggregateClusterBackwardCompatibilityEnabled()) {
|
370
|
+
if (absl::holds_alternative<XdsConfig::ClusterConfig::EndpointConfig>(
|
371
|
+
new_cluster_config->children)) {
|
372
|
+
auto aggregate_cluster = args.args.GetString(kArgXdsAggregateClusterName);
|
373
|
+
if (aggregate_cluster.has_value()) {
|
374
|
+
auto it = new_xds_config->clusters.find(*aggregate_cluster);
|
375
|
+
if (it == new_xds_config->clusters.end()) {
|
376
|
+
// Cluster not present. This should never happen.
|
377
|
+
absl::Status status = absl::UnavailableError(
|
378
|
+
absl::StrCat("xDS config has no entry for aggregate cluster ",
|
379
|
+
*aggregate_cluster));
|
380
|
+
ReportTransientFailure(status);
|
381
|
+
return status;
|
382
|
+
}
|
383
|
+
auto& aggregate_cluster_config = it->second;
|
384
|
+
if (!aggregate_cluster_config.ok()) {
|
385
|
+
ReportTransientFailure(aggregate_cluster_config.status());
|
386
|
+
return aggregate_cluster_config.status();
|
387
|
+
}
|
388
|
+
GPR_ASSERT(aggregate_cluster_config->cluster != nullptr);
|
389
|
+
aggregate_cluster_resource = aggregate_cluster_config->cluster.get();
|
390
|
+
}
|
391
|
+
} else {
|
392
|
+
args.args = args.args.Set(kArgXdsAggregateClusterName, cluster_name_);
|
393
|
+
}
|
316
394
|
}
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
395
|
+
// Construct child policy config and update state based on the cluster type.
|
396
|
+
Json child_policy_config_json;
|
397
|
+
UpdateArgs update_args;
|
398
|
+
Match(
|
399
|
+
new_cluster_config->children,
|
400
|
+
// Leaf cluster.
|
401
|
+
[&](const XdsConfig::ClusterConfig::EndpointConfig& endpoint_config) {
|
402
|
+
// Compute new child numbers.
|
403
|
+
child_name_state_ = ComputeChildNames(
|
404
|
+
old_cluster_config, *new_cluster_config, endpoint_config);
|
405
|
+
// Populate addresses and resolution_note for child policy.
|
406
|
+
update_args.addresses = std::make_shared<PriorityEndpointIterator>(
|
407
|
+
cluster_name_, endpoint_config.endpoints,
|
408
|
+
child_name_state_.priority_child_numbers);
|
409
|
+
update_args.resolution_note = endpoint_config.resolution_note;
|
410
|
+
// Construct child policy config.
|
411
|
+
child_policy_config_json = CreateChildPolicyConfigForLeafCluster(
|
412
|
+
*new_cluster_config, endpoint_config, aggregate_cluster_resource);
|
413
|
+
},
|
414
|
+
// Aggregate cluster.
|
415
|
+
[&](const XdsConfig::ClusterConfig::AggregateConfig& aggregate_config) {
|
416
|
+
child_name_state_.Reset();
|
417
|
+
// Construct child policy config.
|
418
|
+
child_policy_config_json =
|
419
|
+
CreateChildPolicyConfigForAggregateCluster(aggregate_config);
|
420
|
+
});
|
421
|
+
// Swap in new xDS config, now that we're done with the old one.
|
422
|
+
xds_config_ = std::move(new_xds_config);
|
423
|
+
// Validate child policy config.
|
424
|
+
auto child_config =
|
425
|
+
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
|
426
|
+
child_policy_config_json);
|
427
|
+
if (!child_config.ok()) {
|
428
|
+
// Should never happen.
|
429
|
+
absl::Status status = absl::InternalError(
|
430
|
+
absl::StrCat(cluster_name_, ": error parsing child policy config: ",
|
431
|
+
child_config.status().message()));
|
432
|
+
ReportTransientFailure(status);
|
433
|
+
return status;
|
434
|
+
}
|
435
|
+
// Create child policy if not already present.
|
436
|
+
if (child_policy_ == nullptr) {
|
437
|
+
LoadBalancingPolicy::Args lb_args;
|
438
|
+
lb_args.work_serializer = work_serializer();
|
439
|
+
lb_args.args = args.args;
|
440
|
+
lb_args.channel_control_helper =
|
441
|
+
std::make_unique<Helper>(RefAsSubclass<CdsLb>());
|
442
|
+
child_policy_ =
|
443
|
+
CoreConfiguration::Get().lb_policy_registry().CreateLoadBalancingPolicy(
|
444
|
+
(*child_config)->name(), std::move(lb_args));
|
445
|
+
if (child_policy_ == nullptr) {
|
446
|
+
// Should never happen.
|
447
|
+
absl::Status status = absl::UnavailableError(
|
448
|
+
absl::StrCat(cluster_name_, ": failed to create child policy"));
|
449
|
+
ReportTransientFailure(status);
|
450
|
+
return status;
|
451
|
+
}
|
452
|
+
grpc_pollset_set_add_pollset_set(child_policy_->interested_parties(),
|
453
|
+
interested_parties());
|
321
454
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
322
|
-
gpr_log(GPR_INFO, "[cdslb %p]
|
323
|
-
name.c_str()
|
455
|
+
gpr_log(GPR_INFO, "[cdslb %p] created child policy %s (%p)", this,
|
456
|
+
std::string((*child_config)->name()).c_str(),
|
457
|
+
child_policy_.get());
|
458
|
+
}
|
459
|
+
}
|
460
|
+
// Update child policy.
|
461
|
+
update_args.config = std::move(*child_config);
|
462
|
+
update_args.args = args.args;
|
463
|
+
return child_policy_->UpdateLocked(std::move(update_args));
|
464
|
+
}
|
465
|
+
|
466
|
+
CdsLb::ChildNameState CdsLb::ComputeChildNames(
|
467
|
+
const XdsConfig::ClusterConfig* old_cluster,
|
468
|
+
const XdsConfig::ClusterConfig& new_cluster,
|
469
|
+
const XdsConfig::ClusterConfig::EndpointConfig& endpoint_config) const {
|
470
|
+
GPR_ASSERT(
|
471
|
+
!absl::holds_alternative<XdsConfig::ClusterConfig::AggregateConfig>(
|
472
|
+
new_cluster.children));
|
473
|
+
// First, build some maps from locality to child number and the reverse
|
474
|
+
// from old_cluster and child_name_state_.
|
475
|
+
std::map<XdsLocalityName*, size_t /*child_number*/, XdsLocalityName::Less>
|
476
|
+
locality_child_map;
|
477
|
+
std::map<size_t, std::set<XdsLocalityName*, XdsLocalityName::Less>>
|
478
|
+
child_locality_map;
|
479
|
+
if (old_cluster != nullptr) {
|
480
|
+
auto* old_endpoint_config =
|
481
|
+
absl::get_if<XdsConfig::ClusterConfig::EndpointConfig>(
|
482
|
+
&old_cluster->children);
|
483
|
+
if (old_endpoint_config != nullptr) {
|
484
|
+
const auto& prev_priority_list =
|
485
|
+
GetUpdatePriorityList(old_endpoint_config->endpoints.get());
|
486
|
+
for (size_t priority = 0; priority < prev_priority_list.size();
|
487
|
+
++priority) {
|
488
|
+
size_t child_number =
|
489
|
+
child_name_state_.priority_child_numbers[priority];
|
490
|
+
const auto& localities = prev_priority_list[priority].localities;
|
491
|
+
for (const auto& p : localities) {
|
492
|
+
XdsLocalityName* locality_name = p.first;
|
493
|
+
locality_child_map[locality_name] = child_number;
|
494
|
+
child_locality_map[child_number].insert(locality_name);
|
495
|
+
}
|
496
|
+
}
|
497
|
+
}
|
498
|
+
}
|
499
|
+
// Now construct new state containing priority child numbers for the new
|
500
|
+
// cluster based on the maps constructed above.
|
501
|
+
ChildNameState new_child_name_state;
|
502
|
+
new_child_name_state.next_available_child_number =
|
503
|
+
child_name_state_.next_available_child_number;
|
504
|
+
const XdsEndpointResource::PriorityList& priority_list =
|
505
|
+
GetUpdatePriorityList(endpoint_config.endpoints.get());
|
506
|
+
for (size_t priority = 0; priority < priority_list.size(); ++priority) {
|
507
|
+
const auto& localities = priority_list[priority].localities;
|
508
|
+
absl::optional<size_t> child_number;
|
509
|
+
// If one of the localities in this priority already existed, reuse its
|
510
|
+
// child number.
|
511
|
+
for (const auto& p : localities) {
|
512
|
+
XdsLocalityName* locality_name = p.first;
|
513
|
+
if (!child_number.has_value()) {
|
514
|
+
auto it = locality_child_map.find(locality_name);
|
515
|
+
if (it != locality_child_map.end()) {
|
516
|
+
child_number = it->second;
|
517
|
+
locality_child_map.erase(it);
|
518
|
+
// Remove localities that *used* to be in this child number, so
|
519
|
+
// that we don't incorrectly reuse this child number for a
|
520
|
+
// subsequent priority.
|
521
|
+
for (XdsLocalityName* old_locality :
|
522
|
+
child_locality_map[*child_number]) {
|
523
|
+
locality_child_map.erase(old_locality);
|
524
|
+
}
|
525
|
+
}
|
526
|
+
} else {
|
527
|
+
// Remove all localities that are now in this child number, so
|
528
|
+
// that we don't accidentally reuse this child number for a
|
529
|
+
// subsequent priority.
|
530
|
+
locality_child_map.erase(locality_name);
|
531
|
+
}
|
532
|
+
}
|
533
|
+
// If we didn't find an existing child number, assign a new one.
|
534
|
+
if (!child_number.has_value()) {
|
535
|
+
for (child_number = new_child_name_state.next_available_child_number;
|
536
|
+
child_locality_map.find(*child_number) != child_locality_map.end();
|
537
|
+
++(*child_number)) {
|
538
|
+
}
|
539
|
+
new_child_name_state.next_available_child_number = *child_number + 1;
|
540
|
+
// Add entry so we know that the child number is in use.
|
541
|
+
// (Don't need to add the list of localities, since we won't use them.)
|
542
|
+
child_locality_map[*child_number];
|
324
543
|
}
|
325
|
-
|
326
|
-
XdsClusterResourceType::StartWatch(xds_client_.get(), name,
|
327
|
-
std::move(watcher));
|
328
|
-
return false;
|
544
|
+
new_child_name_state.priority_child_numbers.push_back(*child_number);
|
329
545
|
}
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
546
|
+
return new_child_name_state;
|
547
|
+
}
|
548
|
+
|
549
|
+
Json CdsLb::CreateChildPolicyConfigForLeafCluster(
|
550
|
+
const XdsConfig::ClusterConfig& new_cluster,
|
551
|
+
const XdsConfig::ClusterConfig::EndpointConfig& endpoint_config,
|
552
|
+
const XdsClusterResource* aggregate_cluster_resource) {
|
553
|
+
const auto& cluster_resource = *new_cluster.cluster;
|
554
|
+
const bool is_logical_dns =
|
555
|
+
absl::holds_alternative<XdsClusterResource::LogicalDns>(
|
556
|
+
cluster_resource.type);
|
557
|
+
// Determine what xDS LB policy to use.
|
558
|
+
Json xds_lb_policy;
|
559
|
+
if (is_logical_dns) {
|
560
|
+
xds_lb_policy = Json::FromArray({
|
561
|
+
Json::FromObject({
|
562
|
+
{"pick_first", Json::FromObject({})},
|
563
|
+
}),
|
564
|
+
});
|
565
|
+
}
|
566
|
+
// TODO(roth): Remove this "else if" block after the 1.63 release.
|
567
|
+
else if (XdsAggregateClusterBackwardCompatibilityEnabled() &&
|
568
|
+
aggregate_cluster_resource != nullptr) {
|
569
|
+
xds_lb_policy =
|
570
|
+
Json::FromArray(aggregate_cluster_resource->lb_policy_config);
|
571
|
+
} else {
|
572
|
+
xds_lb_policy = Json::FromArray(new_cluster.cluster->lb_policy_config);
|
573
|
+
}
|
574
|
+
// Wrap it in the priority policy.
|
575
|
+
Json::Object priority_children;
|
576
|
+
Json::Array priority_priorities;
|
577
|
+
const auto& priority_list =
|
578
|
+
GetUpdatePriorityList(endpoint_config.endpoints.get());
|
579
|
+
for (size_t priority = 0; priority < priority_list.size(); ++priority) {
|
580
|
+
// Add priority entry, with the appropriate child name.
|
581
|
+
std::string child_name = MakeChildPolicyName(
|
582
|
+
cluster_name_, child_name_state_.priority_child_numbers[priority]);
|
583
|
+
priority_priorities.emplace_back(Json::FromString(child_name));
|
584
|
+
Json::Object child_config = {{"config", xds_lb_policy}};
|
585
|
+
if (!is_logical_dns) {
|
586
|
+
child_config["ignore_reresolution_requests"] = Json::FromBool(true);
|
342
587
|
}
|
343
|
-
|
588
|
+
priority_children[child_name] = Json::FromObject(std::move(child_config));
|
344
589
|
}
|
345
|
-
Json
|
346
|
-
{"
|
347
|
-
|
348
|
-
|
590
|
+
Json priority_policy = Json::FromArray({Json::FromObject({
|
591
|
+
{"priority_experimental",
|
592
|
+
Json::FromObject({
|
593
|
+
{"children", Json::FromObject(std::move(priority_children))},
|
594
|
+
{"priorities", Json::FromArray(std::move(priority_priorities))},
|
595
|
+
})},
|
596
|
+
})});
|
597
|
+
// Wrap the priority policy in the xds_override_host policy.
|
598
|
+
Json xds_override_host_policy = Json::FromArray({Json::FromObject({
|
599
|
+
{"xds_override_host_experimental",
|
600
|
+
Json::FromObject({
|
601
|
+
{"clusterName", Json::FromString(cluster_name_)},
|
602
|
+
{"childPolicy", std::move(priority_policy)},
|
603
|
+
})},
|
604
|
+
})});
|
605
|
+
// Wrap the xds_override_host policy in the xds_cluster_impl policy.
|
606
|
+
Json xds_cluster_impl_policy = Json::FromArray({Json::FromObject({
|
607
|
+
{"xds_cluster_impl_experimental",
|
608
|
+
Json::FromObject({
|
609
|
+
{"clusterName", Json::FromString(cluster_name_)},
|
610
|
+
{"childPolicy", std::move(xds_override_host_policy)},
|
611
|
+
})},
|
612
|
+
})});
|
613
|
+
// Wrap the xds_cluster_impl policy in the outlier_detection policy.
|
614
|
+
Json::Object outlier_detection_config = {
|
615
|
+
{"childPolicy", std::move(xds_cluster_impl_policy)},
|
349
616
|
};
|
350
|
-
if (
|
351
|
-
auto& outlier_detection_update =
|
352
|
-
|
353
|
-
outlier_detection["interval"] =
|
617
|
+
if (cluster_resource.outlier_detection.has_value()) {
|
618
|
+
auto& outlier_detection_update = *cluster_resource.outlier_detection;
|
619
|
+
outlier_detection_config["interval"] =
|
354
620
|
Json::FromString(outlier_detection_update.interval.ToJsonString());
|
355
|
-
|
621
|
+
outlier_detection_config["baseEjectionTime"] = Json::FromString(
|
356
622
|
outlier_detection_update.base_ejection_time.ToJsonString());
|
357
|
-
|
623
|
+
outlier_detection_config["maxEjectionTime"] = Json::FromString(
|
358
624
|
outlier_detection_update.max_ejection_time.ToJsonString());
|
359
|
-
|
625
|
+
outlier_detection_config["maxEjectionPercent"] =
|
360
626
|
Json::FromNumber(outlier_detection_update.max_ejection_percent);
|
361
627
|
if (outlier_detection_update.success_rate_ejection.has_value()) {
|
362
|
-
|
628
|
+
outlier_detection_config["successRateEjection"] = Json::FromObject({
|
363
629
|
{"stdevFactor",
|
364
630
|
Json::FromNumber(
|
365
631
|
outlier_detection_update.success_rate_ejection->stdev_factor)},
|
@@ -375,7 +641,7 @@ absl::StatusOr<bool> CdsLb::GenerateDiscoveryMechanismForCluster(
|
|
375
641
|
});
|
376
642
|
}
|
377
643
|
if (outlier_detection_update.failure_percentage_ejection.has_value()) {
|
378
|
-
|
644
|
+
outlier_detection_config["failurePercentageEjection"] = Json::FromObject({
|
379
645
|
{"threshold",
|
380
646
|
Json::FromNumber(outlier_detection_update
|
381
647
|
.failure_percentage_ejection->threshold)},
|
@@ -391,288 +657,73 @@ absl::StatusOr<bool> CdsLb::GenerateDiscoveryMechanismForCluster(
|
|
391
657
|
.failure_percentage_ejection->request_volume)},
|
392
658
|
});
|
393
659
|
}
|
394
|
-
mechanism["outlierDetection"] =
|
395
|
-
Json::FromObject(std::move(outlier_detection));
|
396
660
|
}
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
},
|
405
|
-
[&](const XdsClusterResource::LogicalDns& logical_dns) {
|
406
|
-
mechanism["type"] = Json::FromString("LOGICAL_DNS");
|
407
|
-
mechanism["dnsHostname"] = Json::FromString(logical_dns.hostname);
|
408
|
-
},
|
409
|
-
[&](const XdsClusterResource::Aggregate&) { GPR_ASSERT(0); });
|
410
|
-
if (state.update->lrs_load_reporting_server.has_value()) {
|
411
|
-
mechanism["lrsLoadReportingServer"] =
|
412
|
-
state.update->lrs_load_reporting_server->ToJson();
|
413
|
-
}
|
414
|
-
if (!state.update->override_host_statuses.empty()) {
|
415
|
-
Json::Array status_list;
|
416
|
-
for (const auto& status : state.update->override_host_statuses) {
|
417
|
-
status_list.emplace_back(Json::FromString(status.ToString()));
|
418
|
-
}
|
419
|
-
mechanism["overrideHostStatus"] = Json::FromArray(std::move(status_list));
|
661
|
+
Json outlier_detection_policy = Json::FromArray({Json::FromObject({
|
662
|
+
{"outlier_detection_experimental",
|
663
|
+
Json::FromObject(std::move(outlier_detection_config))},
|
664
|
+
})});
|
665
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
666
|
+
gpr_log(GPR_INFO, "[cdslb %p] generated config for child policy: %s", this,
|
667
|
+
JsonDump(outlier_detection_policy, /*indent=*/1).c_str());
|
420
668
|
}
|
421
|
-
|
422
|
-
return true;
|
669
|
+
return outlier_detection_policy;
|
423
670
|
}
|
424
671
|
|
425
|
-
|
426
|
-
const
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
"
|
432
|
-
|
433
|
-
cluster_data->ToString().c_str());
|
434
|
-
}
|
435
|
-
// Store the update in the map if we are still interested in watching this
|
436
|
-
// cluster (i.e., it is not cancelled already).
|
437
|
-
// If we've already deleted this entry, then this is an update notification
|
438
|
-
// that was scheduled before the deletion, so we can just ignore it.
|
439
|
-
auto it = watchers_.find(name);
|
440
|
-
if (it == watchers_.end()) return;
|
441
|
-
it->second.update = std::move(cluster_data);
|
442
|
-
// Take care of integration with new certificate code.
|
443
|
-
absl::Status status = UpdateXdsCertificateProvider(name, *it->second.update);
|
444
|
-
if (!status.ok()) {
|
445
|
-
return OnError(name, status);
|
446
|
-
}
|
447
|
-
// Scan the map starting from the root cluster to generate the list of
|
448
|
-
// discovery mechanisms. If we don't have some of the data we need (i.e., we
|
449
|
-
// just started up and not all watchers have returned data yet), then don't
|
450
|
-
// update the child policy at all.
|
451
|
-
Json::Array discovery_mechanisms;
|
452
|
-
std::set<std::string> clusters_added;
|
453
|
-
auto result = GenerateDiscoveryMechanismForCluster(
|
454
|
-
config_->cluster(), /*depth=*/0, &discovery_mechanisms, &clusters_added);
|
455
|
-
if (!result.ok()) {
|
456
|
-
return OnError(name, result.status());
|
457
|
-
}
|
458
|
-
if (*result) {
|
459
|
-
if (discovery_mechanisms.empty()) {
|
460
|
-
return OnError(name, absl::FailedPreconditionError(
|
461
|
-
"aggregate cluster graph has no leaf clusters"));
|
462
|
-
}
|
463
|
-
// LB policy is configured by aggregate cluster, not by the individual
|
464
|
-
// underlying cluster that we may be processing an update for.
|
465
|
-
auto it = watchers_.find(config_->cluster());
|
466
|
-
GPR_ASSERT(it != watchers_.end());
|
467
|
-
// Construct config for child policy.
|
468
|
-
Json json = Json::FromArray({
|
469
|
-
Json::FromObject({
|
470
|
-
{"xds_cluster_resolver_experimental",
|
672
|
+
Json CdsLb::CreateChildPolicyConfigForAggregateCluster(
|
673
|
+
const XdsConfig::ClusterConfig::AggregateConfig& aggregate_config) {
|
674
|
+
Json::Object priority_children;
|
675
|
+
Json::Array priority_priorities;
|
676
|
+
for (const absl::string_view& leaf_cluster : aggregate_config.leaf_clusters) {
|
677
|
+
priority_children[std::string(leaf_cluster)] = Json::FromObject({
|
678
|
+
{"config",
|
679
|
+
Json::FromArray({
|
471
680
|
Json::FromObject({
|
472
|
-
{"
|
473
|
-
Json::
|
474
|
-
|
475
|
-
|
476
|
-
})
|
477
|
-
|
681
|
+
{"cds_experimental",
|
682
|
+
Json::FromObject({
|
683
|
+
{"cluster", Json::FromString(std::string(leaf_cluster))},
|
684
|
+
})},
|
685
|
+
}),
|
686
|
+
})},
|
478
687
|
});
|
479
|
-
|
480
|
-
|
481
|
-
this, JsonDump(json, /*indent=*/1).c_str());
|
482
|
-
}
|
483
|
-
auto config =
|
484
|
-
CoreConfiguration::Get().lb_policy_registry().ParseLoadBalancingConfig(
|
485
|
-
json);
|
486
|
-
if (!config.ok()) {
|
487
|
-
OnError(name, absl::UnavailableError(config.status().message()));
|
488
|
-
return;
|
489
|
-
}
|
490
|
-
// Create child policy if not already present.
|
491
|
-
if (child_policy_ == nullptr) {
|
492
|
-
LoadBalancingPolicy::Args args;
|
493
|
-
args.work_serializer = work_serializer();
|
494
|
-
args.args = args_;
|
495
|
-
args.channel_control_helper = std::make_unique<Helper>(Ref());
|
496
|
-
child_policy_ =
|
497
|
-
CoreConfiguration::Get()
|
498
|
-
.lb_policy_registry()
|
499
|
-
.CreateLoadBalancingPolicy((*config)->name(), std::move(args));
|
500
|
-
if (child_policy_ == nullptr) {
|
501
|
-
OnError(name, absl::UnavailableError("failed to create child policy"));
|
502
|
-
return;
|
503
|
-
}
|
504
|
-
grpc_pollset_set_add_pollset_set(child_policy_->interested_parties(),
|
505
|
-
interested_parties());
|
506
|
-
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
507
|
-
gpr_log(GPR_INFO, "[cdslb %p] created child policy %s (%p)", this,
|
508
|
-
std::string((*config)->name()).c_str(), child_policy_.get());
|
509
|
-
}
|
510
|
-
}
|
511
|
-
// Update child policy.
|
512
|
-
UpdateArgs args;
|
513
|
-
args.config = std::move(*config);
|
514
|
-
if (xds_certificate_provider_ != nullptr) {
|
515
|
-
args.args = args_.SetObject(xds_certificate_provider_);
|
516
|
-
} else {
|
517
|
-
args.args = args_;
|
518
|
-
}
|
519
|
-
// TODO(roth): If the child policy reports an error with the update,
|
520
|
-
// we need to propagate the error to the resolver somehow.
|
521
|
-
(void)child_policy_->UpdateLocked(std::move(args));
|
688
|
+
priority_priorities.emplace_back(
|
689
|
+
Json::FromString(std::string(leaf_cluster)));
|
522
690
|
}
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
}
|
534
|
-
CancelClusterDataWatch(cluster_name, it->second.watcher,
|
535
|
-
/*delay_unsubscription=*/false);
|
536
|
-
it = watchers_.erase(it);
|
691
|
+
Json json = Json::FromArray({Json::FromObject({
|
692
|
+
{"priority_experimental",
|
693
|
+
Json::FromObject({
|
694
|
+
{"children", Json::FromObject(std::move(priority_children))},
|
695
|
+
{"priorities", Json::FromArray(std::move(priority_priorities))},
|
696
|
+
})},
|
697
|
+
})});
|
698
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
699
|
+
gpr_log(GPR_INFO, "[cdslb %p] generated config for child policy: %s", this,
|
700
|
+
JsonDump(json, /*indent=*/1).c_str());
|
537
701
|
}
|
702
|
+
return json;
|
538
703
|
}
|
539
704
|
|
540
|
-
void CdsLb::
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
GRPC_CHANNEL_TRANSIENT_FAILURE, status,
|
549
|
-
MakeRefCounted<TransientFailurePicker>(absl::UnavailableError(
|
550
|
-
absl::StrCat(name, ": ", status.ToString()))));
|
705
|
+
void CdsLb::ResetState() {
|
706
|
+
cluster_name_.clear();
|
707
|
+
xds_config_.reset();
|
708
|
+
child_name_state_.Reset();
|
709
|
+
if (child_policy_ != nullptr) {
|
710
|
+
grpc_pollset_set_del_pollset_set(child_policy_->interested_parties(),
|
711
|
+
interested_parties());
|
712
|
+
child_policy_.reset();
|
551
713
|
}
|
552
714
|
}
|
553
715
|
|
554
|
-
void CdsLb::
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
absl::StrCat("CDS resource \"", config_->cluster(), "\" does not exist"));
|
716
|
+
void CdsLb::ReportTransientFailure(absl::Status status) {
|
717
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_cds_lb_trace)) {
|
718
|
+
gpr_log(GPR_INFO, "[cdslb %p] reporting TRANSIENT_FAILURE: %s", this,
|
719
|
+
status.ToString().c_str());
|
720
|
+
}
|
721
|
+
ResetState();
|
561
722
|
channel_control_helper()->UpdateState(
|
562
723
|
GRPC_CHANNEL_TRANSIENT_FAILURE, status,
|
563
724
|
MakeRefCounted<TransientFailurePicker>(status));
|
564
|
-
MaybeDestroyChildPolicyLocked();
|
565
725
|
}
|
566
726
|
|
567
|
-
absl::Status CdsLb::UpdateXdsCertificateProvider(
|
568
|
-
const std::string& cluster_name, const XdsClusterResource& cluster_data) {
|
569
|
-
// Early out if channel is not configured to use xds security.
|
570
|
-
auto channel_credentials = channel_control_helper()->GetChannelCredentials();
|
571
|
-
if (channel_credentials == nullptr ||
|
572
|
-
channel_credentials->type() != XdsCredentials::Type()) {
|
573
|
-
xds_certificate_provider_ = nullptr;
|
574
|
-
return absl::OkStatus();
|
575
|
-
}
|
576
|
-
if (xds_certificate_provider_ == nullptr) {
|
577
|
-
xds_certificate_provider_ = MakeRefCounted<XdsCertificateProvider>();
|
578
|
-
}
|
579
|
-
// Configure root cert.
|
580
|
-
absl::string_view root_provider_instance_name =
|
581
|
-
cluster_data.common_tls_context.certificate_validation_context
|
582
|
-
.ca_certificate_provider_instance.instance_name;
|
583
|
-
absl::string_view root_provider_cert_name =
|
584
|
-
cluster_data.common_tls_context.certificate_validation_context
|
585
|
-
.ca_certificate_provider_instance.certificate_name;
|
586
|
-
RefCountedPtr<XdsCertificateProvider> new_root_provider;
|
587
|
-
if (!root_provider_instance_name.empty()) {
|
588
|
-
new_root_provider =
|
589
|
-
xds_client_->certificate_provider_store()
|
590
|
-
.CreateOrGetCertificateProvider(root_provider_instance_name);
|
591
|
-
if (new_root_provider == nullptr) {
|
592
|
-
return absl::UnavailableError(
|
593
|
-
absl::StrCat("Certificate provider instance name: \"",
|
594
|
-
root_provider_instance_name, "\" not recognized."));
|
595
|
-
}
|
596
|
-
}
|
597
|
-
if (root_certificate_provider_ != new_root_provider) {
|
598
|
-
if (root_certificate_provider_ != nullptr &&
|
599
|
-
root_certificate_provider_->interested_parties() != nullptr) {
|
600
|
-
grpc_pollset_set_del_pollset_set(
|
601
|
-
interested_parties(),
|
602
|
-
root_certificate_provider_->interested_parties());
|
603
|
-
}
|
604
|
-
if (new_root_provider != nullptr &&
|
605
|
-
new_root_provider->interested_parties() != nullptr) {
|
606
|
-
grpc_pollset_set_add_pollset_set(interested_parties(),
|
607
|
-
new_root_provider->interested_parties());
|
608
|
-
}
|
609
|
-
root_certificate_provider_ = std::move(new_root_provider);
|
610
|
-
}
|
611
|
-
xds_certificate_provider_->UpdateRootCertNameAndDistributor(
|
612
|
-
cluster_name, root_provider_cert_name,
|
613
|
-
root_certificate_provider_ == nullptr
|
614
|
-
? nullptr
|
615
|
-
: root_certificate_provider_->distributor());
|
616
|
-
// Configure identity cert.
|
617
|
-
absl::string_view identity_provider_instance_name =
|
618
|
-
cluster_data.common_tls_context.tls_certificate_provider_instance
|
619
|
-
.instance_name;
|
620
|
-
absl::string_view identity_provider_cert_name =
|
621
|
-
cluster_data.common_tls_context.tls_certificate_provider_instance
|
622
|
-
.certificate_name;
|
623
|
-
RefCountedPtr<XdsCertificateProvider> new_identity_provider;
|
624
|
-
if (!identity_provider_instance_name.empty()) {
|
625
|
-
new_identity_provider =
|
626
|
-
xds_client_->certificate_provider_store()
|
627
|
-
.CreateOrGetCertificateProvider(identity_provider_instance_name);
|
628
|
-
if (new_identity_provider == nullptr) {
|
629
|
-
return absl::UnavailableError(
|
630
|
-
absl::StrCat("Certificate provider instance name: \"",
|
631
|
-
identity_provider_instance_name, "\" not recognized."));
|
632
|
-
}
|
633
|
-
}
|
634
|
-
if (identity_certificate_provider_ != new_identity_provider) {
|
635
|
-
if (identity_certificate_provider_ != nullptr &&
|
636
|
-
identity_certificate_provider_->interested_parties() != nullptr) {
|
637
|
-
grpc_pollset_set_del_pollset_set(
|
638
|
-
interested_parties(),
|
639
|
-
identity_certificate_provider_->interested_parties());
|
640
|
-
}
|
641
|
-
if (new_identity_provider != nullptr &&
|
642
|
-
new_identity_provider->interested_parties() != nullptr) {
|
643
|
-
grpc_pollset_set_add_pollset_set(
|
644
|
-
interested_parties(), new_identity_provider->interested_parties());
|
645
|
-
}
|
646
|
-
identity_certificate_provider_ = std::move(new_identity_provider);
|
647
|
-
}
|
648
|
-
xds_certificate_provider_->UpdateIdentityCertNameAndDistributor(
|
649
|
-
cluster_name, identity_provider_cert_name,
|
650
|
-
identity_certificate_provider_ == nullptr
|
651
|
-
? nullptr
|
652
|
-
: identity_certificate_provider_->distributor());
|
653
|
-
// Configure SAN matchers.
|
654
|
-
const std::vector<StringMatcher>& match_subject_alt_names =
|
655
|
-
cluster_data.common_tls_context.certificate_validation_context
|
656
|
-
.match_subject_alt_names;
|
657
|
-
xds_certificate_provider_->UpdateSubjectAlternativeNameMatchers(
|
658
|
-
cluster_name, match_subject_alt_names);
|
659
|
-
return absl::OkStatus();
|
660
|
-
}
|
661
|
-
|
662
|
-
void CdsLb::CancelClusterDataWatch(absl::string_view cluster_name,
|
663
|
-
ClusterWatcher* watcher,
|
664
|
-
bool delay_unsubscription) {
|
665
|
-
if (xds_certificate_provider_ != nullptr) {
|
666
|
-
std::string name(cluster_name);
|
667
|
-
xds_certificate_provider_->UpdateRootCertNameAndDistributor(name, "",
|
668
|
-
nullptr);
|
669
|
-
xds_certificate_provider_->UpdateIdentityCertNameAndDistributor(name, "",
|
670
|
-
nullptr);
|
671
|
-
xds_certificate_provider_->UpdateSubjectAlternativeNameMatchers(name, {});
|
672
|
-
}
|
673
|
-
XdsClusterResourceType::CancelWatch(xds_client_.get(), cluster_name, watcher,
|
674
|
-
delay_unsubscription);
|
675
|
-
}
|
676
727
|
//
|
677
728
|
// factory
|
678
729
|
//
|
@@ -681,15 +732,7 @@ class CdsLbFactory : public LoadBalancingPolicyFactory {
|
|
681
732
|
public:
|
682
733
|
OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
|
683
734
|
LoadBalancingPolicy::Args args) const override {
|
684
|
-
|
685
|
-
args.args.GetObjectRef<GrpcXdsClient>(DEBUG_LOCATION, "CdsLb");
|
686
|
-
if (xds_client == nullptr) {
|
687
|
-
gpr_log(GPR_ERROR,
|
688
|
-
"XdsClient not present in channel args -- cannot instantiate "
|
689
|
-
"cds LB policy");
|
690
|
-
return nullptr;
|
691
|
-
}
|
692
|
-
return MakeOrphanable<CdsLb>(std::move(xds_client), std::move(args));
|
735
|
+
return MakeOrphanable<CdsLb>(std::move(args));
|
693
736
|
}
|
694
737
|
|
695
738
|
absl::string_view name() const override { return kCds; }
|