grpc 1.23.1 → 1.24.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.
- checksums.yaml +4 -4
- data/Makefile +757 -477
- data/include/grpc/grpc.h +3 -1
- data/include/grpc/grpc_security.h +20 -4
- data/include/grpc/impl/codegen/grpc_types.h +6 -5
- data/include/grpc/impl/codegen/port_platform.h +25 -0
- data/src/core/ext/filters/client_channel/backend_metric.cc +78 -0
- data/src/core/ext/filters/client_channel/backend_metric.h +36 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +16 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +325 -267
- data/src/core/ext/filters/client_channel/client_channel_factory.h +0 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +23 -32
- data/src/core/ext/filters/client_channel/http_proxy.cc +7 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +58 -34
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +46 -50
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +9 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +35 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +130 -215
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +34 -21
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1120 -802
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +8 -2
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +33 -12
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc +151 -40
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h +184 -26
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +389 -245
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +98 -60
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +6 -1
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +89 -0
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +3 -8
- data/src/core/ext/filters/client_channel/server_address.cc +1 -3
- data/src/core/ext/filters/client_channel/server_address.h +1 -1
- data/src/core/ext/filters/client_channel/subchannel.h +2 -1
- data/src/core/ext/filters/client_idle/client_idle_filter.cc +207 -29
- data/src/core/ext/filters/http/client/http_client_filter.cc +10 -8
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +10 -7
- data/src/core/ext/filters/http/server/http_server_filter.cc +52 -26
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +23 -20
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +24 -21
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +37 -24
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +237 -191
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +29 -27
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +19 -4
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +13 -4
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/internal.h +0 -2
- data/src/core/ext/transport/chttp2/transport/parsing.cc +99 -71
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +222 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +818 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +314 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1142 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +53 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +158 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +69 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +49 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +240 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +110 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +324 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +235 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +661 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +84 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +274 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +175 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +572 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +150 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +596 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +35 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +80 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +95 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +308 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +128 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +392 -0
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +91 -0
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +236 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +88 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +258 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +111 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +324 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +23 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +50 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +52 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +130 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.c +39 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.h +87 -0
- data/src/core/ext/upb-generated/envoy/type/range.upb.c +39 -0
- data/src/core/ext/upb-generated/envoy/type/range.upb.h +85 -0
- data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +17 -0
- data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +30 -0
- data/src/core/ext/upb-generated/google/api/annotations.upb.c +18 -0
- data/src/core/ext/upb-generated/google/api/annotations.upb.h +30 -0
- data/src/core/ext/upb-generated/google/api/http.upb.c +66 -0
- data/src/core/ext/upb-generated/google/api/http.upb.h +190 -0
- data/src/core/ext/upb-generated/google/protobuf/any.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/any.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +485 -0
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +1690 -0
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +22 -0
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +50 -0
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +79 -0
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +215 -0
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +106 -0
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +238 -0
- data/src/core/ext/upb-generated/google/rpc/status.upb.c +33 -0
- data/src/core/ext/upb-generated/google/rpc/status.upb.h +74 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +49 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +126 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +209 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +681 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +42 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +109 -0
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +36 -0
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +84 -0
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +133 -0
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +359 -0
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +58 -0
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +144 -0
- data/src/core/ext/upb-generated/validate/validate.upb.c +443 -0
- data/src/core/ext/upb-generated/validate/validate.upb.h +2037 -0
- data/src/core/lib/channel/channel_args.cc +21 -0
- data/src/core/lib/channel/channel_args.h +16 -2
- data/src/core/lib/channel/channel_stack.h +2 -1
- data/src/core/lib/channel/channelz.cc +54 -56
- data/src/core/lib/channel/channelz.h +29 -12
- data/src/core/lib/compression/compression.cc +2 -1
- data/src/core/lib/compression/compression_internal.h +8 -0
- data/src/core/lib/gpr/log_linux.cc +2 -2
- data/src/core/lib/gpr/log_posix.cc +2 -2
- data/src/core/lib/gpr/time_precise.cc +123 -36
- data/src/core/lib/gpr/time_precise.h +37 -0
- data/src/core/lib/gprpp/abstract.h +10 -0
- data/src/core/lib/gprpp/atomic.h +4 -0
- data/src/core/lib/gprpp/inlined_vector.h +20 -4
- data/src/core/lib/gprpp/map.h +109 -6
- data/src/core/lib/gprpp/memory.h +6 -0
- data/src/core/lib/gprpp/ref_counted_ptr.h +2 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +29 -54
- data/src/core/lib/iomgr/exec_ctx.cc +27 -17
- data/src/core/lib/iomgr/exec_ctx.h +3 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -3
- data/src/core/lib/iomgr/tcp_posix.cc +16 -25
- data/src/core/lib/iomgr/tcp_server_custom.cc +1 -1
- data/src/core/lib/iomgr/timer_manager.cc +8 -1
- data/src/core/lib/iomgr/timer_manager.h +2 -0
- data/src/core/lib/security/credentials/credentials.h +8 -2
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +3 -0
- data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +3 -3
- data/src/core/lib/security/security_connector/ssl_utils.cc +1 -12
- data/src/core/lib/security/security_connector/ssl_utils.h +10 -6
- data/src/core/lib/security/security_connector/ssl_utils_config.cc +32 -0
- data/src/core/lib/security/security_connector/ssl_utils_config.h +30 -0
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +161 -49
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +34 -1
- data/src/core/lib/slice/slice_intern.cc +17 -9
- data/src/core/lib/slice/slice_internal.h +34 -7
- data/src/core/lib/slice/slice_utils.h +7 -3
- data/src/core/lib/surface/call.cc +97 -57
- data/src/core/lib/surface/channel.cc +2 -2
- data/src/core/lib/surface/completion_queue.cc +10 -16
- data/src/core/lib/surface/init.cc +3 -0
- data/src/core/lib/surface/server.cc +11 -14
- data/src/core/lib/surface/validate_metadata.cc +4 -0
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +4 -4
- data/src/core/lib/transport/metadata_batch.cc +72 -16
- data/src/core/lib/transport/metadata_batch.h +38 -0
- data/src/core/lib/transport/static_metadata.cc +814 -1023
- data/src/core/lib/transport/static_metadata.h +271 -213
- data/src/core/lib/transport/transport.h +12 -0
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +104 -76
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +34 -16
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +2 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +10 -6
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.h +4 -3
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +74 -48
- data/src/core/tsi/alts/handshaker/transport_security_common_api.h +34 -26
- data/src/core/tsi/ssl_transport_security.cc +14 -6
- data/src/core/tsi/ssl_transport_security.h +4 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +5 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +1 -42
- 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.rb +2 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/errors.rb +4 -7
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +9 -4
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/errors_spec.rb +1 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +34 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -29
- data/third_party/upb/upb/decode.c +604 -0
- data/third_party/upb/upb/decode.h +21 -0
- data/third_party/upb/upb/encode.c +378 -0
- data/third_party/upb/upb/encode.h +21 -0
- data/third_party/upb/upb/generated_util.h +105 -0
- data/third_party/upb/upb/msg.c +111 -0
- data/third_party/upb/upb/msg.h +69 -0
- data/third_party/upb/upb/port.c +27 -0
- data/third_party/upb/upb/port_def.inc +152 -0
- data/third_party/upb/upb/port_undef.inc +21 -0
- data/third_party/upb/upb/table.c +911 -0
- data/third_party/upb/upb/table.int.h +507 -0
- data/third_party/upb/upb/upb.c +261 -0
- data/third_party/upb/upb/upb.h +364 -0
- metadata +134 -55
- data/src/core/ext/filters/client_channel/health/health.pb.c +0 -23
- data/src/core/ext/filters/client_channel/health/health.pb.h +0 -73
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c +0 -19
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h +0 -54
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c +0 -19
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h +0 -54
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +0 -89
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -164
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc +0 -520
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h +0 -323
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +0 -145
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +0 -149
- data/src/core/tsi/alts/handshaker/altscontext.pb.c +0 -47
- data/src/core/tsi/alts/handshaker/altscontext.pb.h +0 -63
- data/src/core/tsi/alts/handshaker/handshaker.pb.c +0 -122
- data/src/core/tsi/alts/handshaker/handshaker.pb.h +0 -254
- data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +0 -49
- data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +0 -78
- data/third_party/nanopb/pb.h +0 -579
- data/third_party/nanopb/pb_common.c +0 -97
- data/third_party/nanopb/pb_common.h +0 -42
- data/third_party/nanopb/pb_decode.c +0 -1347
- data/third_party/nanopb/pb_decode.h +0 -149
- data/third_party/nanopb/pb_encode.c +0 -696
- data/third_party/nanopb/pb_encode.h +0 -154
@@ -23,14 +23,20 @@
|
|
23
23
|
|
24
24
|
#include <grpc/impl/codegen/grpc_types.h>
|
25
25
|
|
26
|
+
namespace grpc_core {
|
27
|
+
|
26
28
|
/// Makes any necessary modifications to \a args for use in the xds
|
27
29
|
/// balancer channel.
|
28
30
|
///
|
29
31
|
/// Takes ownership of \a args.
|
30
32
|
///
|
31
33
|
/// Caller takes ownership of the returned args.
|
32
|
-
grpc_channel_args*
|
33
|
-
|
34
|
+
grpc_channel_args* ModifyXdsBalancerChannelArgs(grpc_channel_args* args);
|
35
|
+
|
36
|
+
grpc_channel* CreateXdsBalancerChannel(const char* target_uri,
|
37
|
+
const grpc_channel_args& args);
|
38
|
+
|
39
|
+
} // namespace grpc_core
|
34
40
|
|
35
41
|
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_CHANNEL_H \
|
36
42
|
*/
|
@@ -20,9 +20,11 @@
|
|
20
20
|
|
21
21
|
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h"
|
22
22
|
|
23
|
+
#include <string.h>
|
24
|
+
|
25
|
+
#include <grpc/grpc_security.h>
|
23
26
|
#include <grpc/support/alloc.h>
|
24
27
|
#include <grpc/support/string_util.h>
|
25
|
-
#include <string.h>
|
26
28
|
|
27
29
|
#include "src/core/ext/filters/client_channel/client_channel.h"
|
28
30
|
#include "src/core/ext/filters/client_channel/server_address.h"
|
@@ -33,29 +35,48 @@
|
|
33
35
|
#include "src/core/lib/security/transport/target_authority_table.h"
|
34
36
|
#include "src/core/lib/slice/slice_internal.h"
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
grpc_arg args_to_add
|
41
|
-
size_t num_args_to_add = 0;
|
38
|
+
namespace grpc_core {
|
39
|
+
|
40
|
+
grpc_channel_args* ModifyXdsBalancerChannelArgs(grpc_channel_args* args) {
|
41
|
+
InlinedVector<const char*, 1> args_to_remove;
|
42
|
+
InlinedVector<grpc_arg, 2> args_to_add;
|
42
43
|
// Substitute the channel credentials with a version without call
|
43
44
|
// credentials: the load balancer is not necessarily trusted to handle
|
44
45
|
// bearer token credentials.
|
45
46
|
grpc_channel_credentials* channel_credentials =
|
46
47
|
grpc_channel_credentials_find_in_args(args);
|
47
|
-
|
48
|
+
RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds;
|
48
49
|
if (channel_credentials != nullptr) {
|
49
50
|
creds_sans_call_creds =
|
50
51
|
channel_credentials->duplicate_without_call_credentials();
|
51
52
|
GPR_ASSERT(creds_sans_call_creds != nullptr);
|
52
|
-
args_to_remove
|
53
|
-
args_to_add
|
54
|
-
grpc_channel_credentials_to_arg(creds_sans_call_creds.get());
|
53
|
+
args_to_remove.emplace_back(GRPC_ARG_CHANNEL_CREDENTIALS);
|
54
|
+
args_to_add.emplace_back(
|
55
|
+
grpc_channel_credentials_to_arg(creds_sans_call_creds.get()));
|
55
56
|
}
|
56
57
|
grpc_channel_args* result = grpc_channel_args_copy_and_add_and_remove(
|
57
|
-
args, args_to_remove,
|
58
|
+
args, args_to_remove.data(), args_to_remove.size(), args_to_add.data(),
|
59
|
+
args_to_add.size());
|
58
60
|
// Clean up.
|
59
61
|
grpc_channel_args_destroy(args);
|
60
62
|
return result;
|
61
63
|
}
|
64
|
+
|
65
|
+
grpc_channel* CreateXdsBalancerChannel(const char* target_uri,
|
66
|
+
const grpc_channel_args& args) {
|
67
|
+
grpc_channel_credentials* creds =
|
68
|
+
grpc_channel_credentials_find_in_args(&args);
|
69
|
+
if (creds == nullptr) {
|
70
|
+
// Build with security but parent channel is insecure.
|
71
|
+
return grpc_insecure_channel_create(target_uri, &args, nullptr);
|
72
|
+
}
|
73
|
+
const char* arg_to_remove = GRPC_ARG_CHANNEL_CREDENTIALS;
|
74
|
+
grpc_channel_args* new_args =
|
75
|
+
grpc_channel_args_copy_and_remove(&args, &arg_to_remove, 1);
|
76
|
+
grpc_channel* channel =
|
77
|
+
grpc_secure_channel_create(creds, target_uri, new_args, nullptr);
|
78
|
+
grpc_channel_args_destroy(new_args);
|
79
|
+
return channel;
|
80
|
+
}
|
81
|
+
|
82
|
+
} // namespace grpc_core
|
@@ -26,60 +26,171 @@
|
|
26
26
|
|
27
27
|
namespace grpc_core {
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
namespace {
|
30
|
+
|
31
|
+
template <typename T>
|
32
|
+
T GetAndResetCounter(Atomic<T>* from) {
|
33
|
+
return from->Exchange(0, MemoryOrder::RELAXED);
|
34
|
+
}
|
35
|
+
|
36
|
+
} // namespace
|
37
|
+
|
38
|
+
//
|
39
|
+
// XdsClientStats::LocalityStats::LoadMetric::Snapshot
|
40
|
+
//
|
41
|
+
|
42
|
+
bool XdsClientStats::LocalityStats::LoadMetric::Snapshot::IsAllZero() const {
|
43
|
+
return total_metric_value == 0 && num_requests_finished_with_metric == 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
//
|
47
|
+
// XdsClientStats::LocalityStats::LoadMetric
|
48
|
+
//
|
49
|
+
|
50
|
+
XdsClientStats::LocalityStats::LoadMetric::Snapshot
|
51
|
+
XdsClientStats::LocalityStats::LoadMetric::GetSnapshotAndReset() {
|
52
|
+
Snapshot metric = {num_requests_finished_with_metric_, total_metric_value_};
|
53
|
+
num_requests_finished_with_metric_ = 0;
|
54
|
+
total_metric_value_ = 0;
|
55
|
+
return metric;
|
31
56
|
}
|
32
57
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
58
|
+
//
|
59
|
+
// XdsClientStats::LocalityStats::Snapshot
|
60
|
+
//
|
61
|
+
|
62
|
+
bool XdsClientStats::LocalityStats::Snapshot::IsAllZero() {
|
63
|
+
if (total_successful_requests != 0 || total_requests_in_progress != 0 ||
|
64
|
+
total_error_requests != 0 || total_issued_requests != 0) {
|
65
|
+
return false;
|
39
66
|
}
|
40
|
-
|
41
|
-
|
67
|
+
for (auto& p : load_metric_stats) {
|
68
|
+
const LoadMetric::Snapshot& metric_value = p.second;
|
69
|
+
if (!metric_value.IsAllZero()) return false;
|
42
70
|
}
|
71
|
+
return true;
|
43
72
|
}
|
44
73
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
74
|
+
//
|
75
|
+
// XdsClientStats::LocalityStats
|
76
|
+
//
|
77
|
+
|
78
|
+
XdsClientStats::LocalityStats::Snapshot
|
79
|
+
XdsClientStats::LocalityStats::GetSnapshotAndReset() {
|
80
|
+
Snapshot snapshot = {
|
81
|
+
GetAndResetCounter(&total_successful_requests_),
|
82
|
+
// Don't reset total_requests_in_progress because it's not
|
83
|
+
// related to a single reporting interval.
|
84
|
+
total_requests_in_progress_.Load(MemoryOrder::RELAXED),
|
85
|
+
GetAndResetCounter(&total_error_requests_),
|
86
|
+
GetAndResetCounter(&total_issued_requests_)};
|
87
|
+
{
|
88
|
+
MutexLock lock(&load_metric_stats_mu_);
|
89
|
+
for (auto& p : load_metric_stats_) {
|
90
|
+
const char* metric_name = p.first.get();
|
91
|
+
LoadMetric& metric_value = p.second;
|
92
|
+
snapshot.load_metric_stats.emplace(
|
93
|
+
UniquePtr<char>(gpr_strdup(metric_name)),
|
94
|
+
metric_value.GetSnapshotAndReset());
|
57
95
|
}
|
58
96
|
}
|
59
|
-
|
60
|
-
drop_token_counts_->emplace_back(UniquePtr<char>(gpr_strdup(token)), 1);
|
97
|
+
return snapshot;
|
61
98
|
}
|
62
99
|
|
63
|
-
|
100
|
+
void XdsClientStats::LocalityStats::AddCallStarted() {
|
101
|
+
total_issued_requests_.FetchAdd(1, MemoryOrder::RELAXED);
|
102
|
+
total_requests_in_progress_.FetchAdd(1, MemoryOrder::RELAXED);
|
103
|
+
}
|
64
104
|
|
65
|
-
void
|
66
|
-
|
105
|
+
void XdsClientStats::LocalityStats::AddCallFinished(bool fail) {
|
106
|
+
Atomic<uint64_t>& to_increment =
|
107
|
+
fail ? total_error_requests_ : total_successful_requests_;
|
108
|
+
to_increment.FetchAdd(1, MemoryOrder::RELAXED);
|
109
|
+
total_requests_in_progress_.FetchAdd(-1, MemoryOrder::ACQ_REL);
|
67
110
|
}
|
68
111
|
|
69
|
-
|
112
|
+
//
|
113
|
+
// XdsClientStats::Snapshot
|
114
|
+
//
|
70
115
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
116
|
+
bool XdsClientStats::Snapshot::IsAllZero() {
|
117
|
+
for (auto& p : upstream_locality_stats) {
|
118
|
+
if (!p.second.IsAllZero()) return false;
|
119
|
+
}
|
120
|
+
for (auto& p : dropped_requests) {
|
121
|
+
if (p.second != 0) return false;
|
122
|
+
}
|
123
|
+
return total_dropped_requests == 0;
|
124
|
+
}
|
125
|
+
|
126
|
+
//
|
127
|
+
// XdsClientStats
|
128
|
+
//
|
129
|
+
|
130
|
+
XdsClientStats::Snapshot XdsClientStats::GetSnapshotAndReset() {
|
131
|
+
grpc_millis now = ExecCtx::Get()->Now();
|
132
|
+
// Record total_dropped_requests and reporting interval in the snapshot.
|
133
|
+
Snapshot snapshot;
|
134
|
+
snapshot.total_dropped_requests =
|
135
|
+
GetAndResetCounter(&total_dropped_requests_);
|
136
|
+
snapshot.load_report_interval = now - last_report_time_;
|
137
|
+
// Update last report time.
|
138
|
+
last_report_time_ = now;
|
139
|
+
// Snapshot all the other stats.
|
140
|
+
for (auto& p : upstream_locality_stats_) {
|
141
|
+
snapshot.upstream_locality_stats.emplace(p.first,
|
142
|
+
p.second->GetSnapshotAndReset());
|
143
|
+
}
|
144
|
+
{
|
145
|
+
MutexLock lock(&dropped_requests_mu_);
|
146
|
+
#if GRPC_USE_CPP_STD_LIB
|
147
|
+
// This is a workaround for the case where some compilers cannot build
|
148
|
+
// move-assignment of map with non-copyable but movable key.
|
149
|
+
// https://stackoverflow.com/questions/36475497
|
150
|
+
std::swap(snapshot.dropped_requests, dropped_requests_);
|
151
|
+
dropped_requests_.clear();
|
152
|
+
#else
|
153
|
+
snapshot.dropped_requests = std::move(dropped_requests_);
|
154
|
+
#endif
|
155
|
+
}
|
156
|
+
return snapshot;
|
157
|
+
}
|
158
|
+
|
159
|
+
void XdsClientStats::MaybeInitLastReportTime() {
|
160
|
+
if (last_report_time_ == -1) last_report_time_ = ExecCtx::Get()->Now();
|
161
|
+
}
|
162
|
+
|
163
|
+
RefCountedPtr<XdsClientStats::LocalityStats> XdsClientStats::FindLocalityStats(
|
164
|
+
const RefCountedPtr<XdsLocalityName>& locality_name) {
|
165
|
+
auto iter = upstream_locality_stats_.find(locality_name);
|
166
|
+
if (iter == upstream_locality_stats_.end()) {
|
167
|
+
iter = upstream_locality_stats_
|
168
|
+
.emplace(locality_name, MakeRefCounted<LocalityStats>())
|
169
|
+
.first;
|
170
|
+
}
|
171
|
+
return iter->second;
|
172
|
+
}
|
173
|
+
|
174
|
+
void XdsClientStats::PruneLocalityStats() {
|
175
|
+
auto iter = upstream_locality_stats_.begin();
|
176
|
+
while (iter != upstream_locality_stats_.end()) {
|
177
|
+
if (iter->second->IsSafeToDelete()) {
|
178
|
+
iter = upstream_locality_stats_.erase(iter);
|
179
|
+
} else {
|
180
|
+
++iter;
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
void XdsClientStats::AddCallDropped(const UniquePtr<char>& category) {
|
186
|
+
total_dropped_requests_.FetchAdd(1, MemoryOrder::RELAXED);
|
187
|
+
MutexLock lock(&dropped_requests_mu_);
|
188
|
+
auto iter = dropped_requests_.find(category);
|
189
|
+
if (iter == dropped_requests_.end()) {
|
190
|
+
dropped_requests_.emplace(UniquePtr<char>(gpr_strdup(category.get())), 1);
|
191
|
+
} else {
|
192
|
+
++iter->second;
|
193
|
+
}
|
83
194
|
}
|
84
195
|
|
85
196
|
} // namespace grpc_core
|
@@ -21,49 +21,207 @@
|
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
-
#include <grpc/support/
|
24
|
+
#include <grpc/support/string_util.h>
|
25
25
|
|
26
|
+
#include "src/core/lib/gprpp/atomic.h"
|
26
27
|
#include "src/core/lib/gprpp/inlined_vector.h"
|
28
|
+
#include "src/core/lib/gprpp/map.h"
|
27
29
|
#include "src/core/lib/gprpp/memory.h"
|
28
30
|
#include "src/core/lib/gprpp/ref_counted.h"
|
31
|
+
#include "src/core/lib/gprpp/sync.h"
|
32
|
+
#include "src/core/lib/iomgr/exec_ctx.h"
|
29
33
|
|
30
34
|
namespace grpc_core {
|
31
35
|
|
32
|
-
class
|
36
|
+
class XdsLocalityName : public RefCounted<XdsLocalityName> {
|
33
37
|
public:
|
34
|
-
struct
|
35
|
-
|
36
|
-
|
38
|
+
struct Less {
|
39
|
+
bool operator()(const RefCountedPtr<XdsLocalityName>& lhs,
|
40
|
+
const RefCountedPtr<XdsLocalityName>& rhs) const {
|
41
|
+
int cmp_result = strcmp(lhs->region_.get(), rhs->region_.get());
|
42
|
+
if (cmp_result != 0) return cmp_result < 0;
|
43
|
+
cmp_result = strcmp(lhs->zone_.get(), rhs->zone_.get());
|
44
|
+
if (cmp_result != 0) return cmp_result < 0;
|
45
|
+
return strcmp(lhs->sub_zone_.get(), rhs->sub_zone_.get()) < 0;
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
XdsLocalityName(UniquePtr<char> region, UniquePtr<char> zone,
|
50
|
+
UniquePtr<char> subzone)
|
51
|
+
: region_(std::move(region)),
|
52
|
+
zone_(std::move(zone)),
|
53
|
+
sub_zone_(std::move(subzone)) {}
|
54
|
+
|
55
|
+
bool operator==(const XdsLocalityName& other) const {
|
56
|
+
return strcmp(region_.get(), other.region_.get()) == 0 &&
|
57
|
+
strcmp(zone_.get(), other.zone_.get()) == 0 &&
|
58
|
+
strcmp(sub_zone_.get(), other.sub_zone_.get()) == 0;
|
59
|
+
}
|
60
|
+
|
61
|
+
const char* region() const { return region_.get(); }
|
62
|
+
const char* zone() const { return zone_.get(); }
|
63
|
+
const char* sub_zone() const { return sub_zone_.get(); }
|
64
|
+
|
65
|
+
const char* AsHumanReadableString() {
|
66
|
+
if (human_readable_string_ == nullptr) {
|
67
|
+
char* tmp;
|
68
|
+
gpr_asprintf(&tmp, "{region=\"%s\", zone=\"%s\", sub_zone=\"%s\"}",
|
69
|
+
region_.get(), zone_.get(), sub_zone_.get());
|
70
|
+
human_readable_string_.reset(tmp);
|
71
|
+
}
|
72
|
+
return human_readable_string_.get();
|
73
|
+
}
|
74
|
+
|
75
|
+
private:
|
76
|
+
UniquePtr<char> region_;
|
77
|
+
UniquePtr<char> zone_;
|
78
|
+
UniquePtr<char> sub_zone_;
|
79
|
+
UniquePtr<char> human_readable_string_;
|
80
|
+
};
|
81
|
+
|
82
|
+
// The stats classes (i.e., XdsClientStats, LocalityStats, and LoadMetric) can
|
83
|
+
// be taken a snapshot (and reset) to populate the load report. The snapshots
|
84
|
+
// are contained in the respective Snapshot structs. The Snapshot structs have
|
85
|
+
// no synchronization. The stats classes use several different synchronization
|
86
|
+
// methods. 1. Most of the counters are Atomic<>s for performance. 2. Some of
|
87
|
+
// the Map<>s are protected by Mutex if we are not guaranteed that the accesses
|
88
|
+
// to them are synchronized by the callers. 3. The Map<>s to which the accesses
|
89
|
+
// are already synchronized by the callers do not have additional
|
90
|
+
// synchronization here. Note that the Map<>s we mentioned in 2 and 3 refer to
|
91
|
+
// the map's tree structure rather than the content in each tree node.
|
92
|
+
class XdsClientStats {
|
93
|
+
public:
|
94
|
+
class LocalityStats : public RefCounted<LocalityStats> {
|
95
|
+
public:
|
96
|
+
class LoadMetric {
|
97
|
+
public:
|
98
|
+
struct Snapshot {
|
99
|
+
bool IsAllZero() const;
|
37
100
|
|
38
|
-
|
39
|
-
|
101
|
+
uint64_t num_requests_finished_with_metric;
|
102
|
+
double total_metric_value;
|
103
|
+
};
|
104
|
+
|
105
|
+
// Returns a snapshot of this instance and reset all the accumulative
|
106
|
+
// counters.
|
107
|
+
Snapshot GetSnapshotAndReset();
|
108
|
+
|
109
|
+
private:
|
110
|
+
uint64_t num_requests_finished_with_metric_{0};
|
111
|
+
double total_metric_value_{0};
|
112
|
+
};
|
113
|
+
|
114
|
+
using LoadMetricMap = Map<UniquePtr<char>, LoadMetric, StringLess>;
|
115
|
+
using LoadMetricSnapshotMap =
|
116
|
+
Map<UniquePtr<char>, LoadMetric::Snapshot, StringLess>;
|
117
|
+
|
118
|
+
struct Snapshot {
|
119
|
+
// TODO(juanlishen): Change this to const method when const_iterator is
|
120
|
+
// added to Map<>.
|
121
|
+
bool IsAllZero();
|
122
|
+
|
123
|
+
uint64_t total_successful_requests;
|
124
|
+
uint64_t total_requests_in_progress;
|
125
|
+
uint64_t total_error_requests;
|
126
|
+
uint64_t total_issued_requests;
|
127
|
+
LoadMetricSnapshotMap load_metric_stats;
|
128
|
+
};
|
129
|
+
|
130
|
+
// Returns a snapshot of this instance and reset all the accumulative
|
131
|
+
// counters.
|
132
|
+
Snapshot GetSnapshotAndReset();
|
133
|
+
|
134
|
+
// Each XdsLb::PickerWrapper holds a ref to the perspective LocalityStats.
|
135
|
+
// If the refcount is 0, there won't be new calls recorded to the
|
136
|
+
// LocalityStats, so the LocalityStats can be safely deleted when all the
|
137
|
+
// in-progress calls have finished.
|
138
|
+
// Only be called from the control plane combiner.
|
139
|
+
void RefByPicker() { picker_refcount_.FetchAdd(1, MemoryOrder::ACQ_REL); }
|
140
|
+
// Might be called from the control plane combiner or the data plane
|
141
|
+
// combiner.
|
142
|
+
// TODO(juanlishen): Once https://github.com/grpc/grpc/pull/19390 is merged,
|
143
|
+
// this method will also only be invoked in the control plane combiner.
|
144
|
+
// We may then be able to simplify the LocalityStats' lifetime by making it
|
145
|
+
// RefCounted<> and populating the protobuf in its dtor.
|
146
|
+
void UnrefByPicker() { picker_refcount_.FetchSub(1, MemoryOrder::ACQ_REL); }
|
147
|
+
// Only be called from the control plane combiner.
|
148
|
+
// The only place where the picker_refcount_ can be increased is
|
149
|
+
// RefByPicker(), which also can only be called from the control plane
|
150
|
+
// combiner. Also, if the picker_refcount_ is 0, total_requests_in_progress_
|
151
|
+
// can't be increased from 0. So it's safe to delete the LocalityStats right
|
152
|
+
// after this method returns true.
|
153
|
+
bool IsSafeToDelete() {
|
154
|
+
return picker_refcount_.FetchAdd(0, MemoryOrder::ACQ_REL) == 0 &&
|
155
|
+
total_requests_in_progress_.FetchAdd(0, MemoryOrder::ACQ_REL) == 0;
|
156
|
+
}
|
157
|
+
|
158
|
+
void AddCallStarted();
|
159
|
+
void AddCallFinished(bool fail = false);
|
160
|
+
|
161
|
+
private:
|
162
|
+
Atomic<uint64_t> total_successful_requests_{0};
|
163
|
+
Atomic<uint64_t> total_requests_in_progress_{0};
|
164
|
+
// Requests that were issued (not dropped) but failed.
|
165
|
+
Atomic<uint64_t> total_error_requests_{0};
|
166
|
+
Atomic<uint64_t> total_issued_requests_{0};
|
167
|
+
// Protects load_metric_stats_. A mutex is necessary because the length of
|
168
|
+
// load_metric_stats_ can be accessed by both the callback intercepting the
|
169
|
+
// call's recv_trailing_metadata (not from any combiner) and the load
|
170
|
+
// reporting thread (from the control plane combiner).
|
171
|
+
Mutex load_metric_stats_mu_;
|
172
|
+
LoadMetricMap load_metric_stats_;
|
173
|
+
// Can be accessed from either the control plane combiner or the data plane
|
174
|
+
// combiner.
|
175
|
+
Atomic<uint8_t> picker_refcount_{0};
|
40
176
|
};
|
41
177
|
|
42
|
-
|
178
|
+
// TODO(juanlishen): The value type of Map<> must be movable in current
|
179
|
+
// implementation. To avoid making LocalityStats movable, we wrap it by
|
180
|
+
// UniquePtr<>. We should remove this wrapper if the value type of Map<>
|
181
|
+
// doesn't have to be movable.
|
182
|
+
using LocalityStatsMap =
|
183
|
+
Map<RefCountedPtr<XdsLocalityName>, RefCountedPtr<LocalityStats>,
|
184
|
+
XdsLocalityName::Less>;
|
185
|
+
using LocalityStatsSnapshotMap =
|
186
|
+
Map<RefCountedPtr<XdsLocalityName>, LocalityStats::Snapshot,
|
187
|
+
XdsLocalityName::Less>;
|
188
|
+
using DroppedRequestsMap = Map<UniquePtr<char>, uint64_t, StringLess>;
|
189
|
+
using DroppedRequestsSnapshotMap = DroppedRequestsMap;
|
43
190
|
|
44
|
-
|
191
|
+
struct Snapshot {
|
192
|
+
// TODO(juanlishen): Change this to const method when const_iterator is
|
193
|
+
// added to Map<>.
|
194
|
+
bool IsAllZero();
|
45
195
|
|
46
|
-
|
47
|
-
|
48
|
-
|
196
|
+
LocalityStatsSnapshotMap upstream_locality_stats;
|
197
|
+
uint64_t total_dropped_requests;
|
198
|
+
DroppedRequestsSnapshotMap dropped_requests;
|
199
|
+
// The actual load report interval.
|
200
|
+
grpc_millis load_report_interval;
|
201
|
+
};
|
49
202
|
|
50
|
-
//
|
51
|
-
|
203
|
+
// Returns a snapshot of this instance and reset all the accumulative
|
204
|
+
// counters.
|
205
|
+
Snapshot GetSnapshotAndReset();
|
52
206
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
207
|
+
void MaybeInitLastReportTime();
|
208
|
+
RefCountedPtr<LocalityStats> FindLocalityStats(
|
209
|
+
const RefCountedPtr<XdsLocalityName>& locality_name);
|
210
|
+
void PruneLocalityStats();
|
211
|
+
void AddCallDropped(const UniquePtr<char>& category);
|
58
212
|
|
59
213
|
private:
|
60
|
-
//
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
214
|
+
// The stats for each locality.
|
215
|
+
LocalityStatsMap upstream_locality_stats_;
|
216
|
+
Atomic<uint64_t> total_dropped_requests_{0};
|
217
|
+
// Protects dropped_requests_. A mutex is necessary because the length of
|
218
|
+
// dropped_requests_ can be accessed by both the picker (from data plane
|
219
|
+
// combiner) and the load reporting thread (from the control plane combiner).
|
220
|
+
Mutex dropped_requests_mu_;
|
221
|
+
DroppedRequestsMap dropped_requests_;
|
222
|
+
// The timestamp of last reporting. For the LB-policy-wide first report, the
|
223
|
+
// last_report_time is the time we scheduled the first reporting timer.
|
224
|
+
grpc_millis last_report_time_ = -1;
|
67
225
|
};
|
68
226
|
|
69
227
|
} // namespace grpc_core
|