grpc 1.30.2 → 1.32.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +723 -15910
- data/include/grpc/grpc_security.h +31 -14
- data/include/grpc/grpc_security_constants.h +3 -0
- data/include/grpc/impl/codegen/README.md +22 -0
- data/include/grpc/impl/codegen/grpc_types.h +7 -5
- data/include/grpc/impl/codegen/port_platform.h +6 -33
- data/src/core/ext/filters/client_channel/backend_metric.cc +12 -9
- data/src/core/ext/filters/client_channel/backup_poller.cc +3 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +470 -285
- data/src/core/ext/filters/client_channel/client_channel.h +1 -1
- data/src/core/ext/filters/client_channel/client_channel_channelz.h +0 -3
- data/src/core/ext/filters/client_channel/config_selector.cc +62 -0
- data/src/core/ext/filters/client_channel/config_selector.h +93 -0
- data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +24 -2
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +8 -1
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +8 -8
- data/src/core/ext/filters/client_channel/http_proxy.cc +6 -4
- data/src/core/ext/filters/client_channel/lb_policy.h +4 -0
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +59 -36
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +0 -13
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +0 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -37
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +19 -13
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +29 -10
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -4
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +4 -6
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +23 -13
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +18 -12
- data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +22 -14
- data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +18 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +385 -78
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +4 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +5 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +6 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +8 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +9 -7
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +7 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +36 -51
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +6 -2
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +383 -31
- data/src/core/ext/filters/client_channel/resolver_registry.cc +13 -14
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +6 -7
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +0 -1
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +38 -32
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +39 -20
- data/src/core/ext/filters/client_channel/server_address.cc +40 -7
- data/src/core/ext/filters/client_channel/server_address.h +42 -4
- data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +142 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +65 -24
- data/src/core/ext/filters/client_channel/subchannel.h +16 -4
- data/src/core/ext/filters/http/client/http_client_filter.cc +5 -5
- data/src/core/ext/filters/http/http_filters_plugin.cc +2 -1
- data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +74 -33
- data/src/core/ext/filters/http/message_compress/message_decompress_filter.h +3 -1
- data/src/core/ext/filters/max_age/max_age_filter.cc +2 -1
- data/src/core/ext/filters/message_size/message_size_filter.cc +56 -80
- data/src/core/ext/filters/message_size/message_size_filter.h +6 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +87 -31
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +18 -1
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +10 -35
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +378 -348
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +7 -2
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +3 -3
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +10 -16
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +9 -9
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +256 -279
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +23 -28
- data/src/core/ext/transport/chttp2/transport/flow_control.h +14 -16
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +9 -12
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +4 -6
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -6
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +12 -13
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +8 -9
- data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +9 -12
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +25 -29
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +13 -17
- data/src/core/ext/transport/chttp2/transport/internal.h +18 -1
- data/src/core/ext/transport/chttp2/transport/parsing.cc +34 -71
- data/src/core/ext/transport/chttp2/transport/writing.cc +15 -19
- data/src/core/ext/transport/inproc/inproc_transport.cc +47 -27
- data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +0 -1
- data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +3 -4
- data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +224 -0
- data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +700 -0
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +74 -0
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +226 -0
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +380 -0
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +1378 -0
- data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/filter.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +69 -0
- data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/outlier_detection.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +323 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +112 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +334 -0
- data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/backoff.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +79 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +309 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +869 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +96 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +328 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +71 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +195 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +634 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +170 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +684 -0
- data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/http_uri.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +80 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +152 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +536 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +28 -0
- data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +58 -0
- data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/socket_option.upb.c +6 -6
- data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +88 -0
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +91 -0
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +220 -0
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +91 -0
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +273 -0
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +112 -0
- data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +332 -0
- data/src/core/ext/upb-generated/envoy/config/listener/{v2 → v3}/api_listener.upb.c +8 -8
- data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +65 -0
- data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +108 -0
- data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +401 -0
- data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +138 -0
- data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +490 -0
- data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +41 -0
- data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +94 -0
- data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +174 -0
- data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +599 -0
- data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +63 -0
- data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +204 -0
- data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +773 -0
- data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +2855 -0
- data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +59 -0
- data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +135 -0
- data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +50 -0
- data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +108 -0
- data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +312 -0
- data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +1125 -0
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +20 -0
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +34 -0
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +111 -0
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +401 -0
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +72 -0
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +198 -0
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +105 -0
- data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +388 -0
- data/src/core/ext/upb-generated/envoy/{api/v2 → service/cluster/v3}/cds.upb.c +5 -6
- data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +49 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/{v2 → v3}/ads.upb.c +5 -4
- data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +49 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +129 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +386 -0
- data/src/core/ext/upb-generated/envoy/{api/v2 → service/endpoint/v3}/eds.upb.c +5 -6
- data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +49 -0
- data/src/core/ext/upb-generated/envoy/{api/v2 → service/listener/v3}/lds.upb.c +5 -6
- data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +49 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +55 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +136 -0
- data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/rds.upb.c +5 -6
- data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +49 -0
- data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/srds.upb.c +5 -6
- data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +49 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +47 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +114 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +35 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +77 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +71 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +64 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +145 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +53 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +127 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +63 -0
- data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +188 -0
- data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +88 -0
- data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +258 -0
- data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +90 -0
- data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +250 -0
- data/src/core/ext/upb-generated/envoy/type/{http.upb.c → v3/http.upb.c} +2 -2
- data/src/core/ext/upb-generated/envoy/type/{http.upb.h → v3/http.upb.h} +8 -9
- data/src/core/ext/upb-generated/envoy/type/{percent.upb.c → v3/percent.upb.c} +9 -8
- data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +86 -0
- data/src/core/ext/upb-generated/envoy/type/{range.upb.c → v3/range.upb.c} +12 -11
- data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +111 -0
- data/src/core/ext/upb-generated/envoy/type/{semantic_version.upb.c → v3/semantic_version.upb.c} +6 -5
- data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +61 -0
- data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -1
- data/src/core/ext/upb-generated/google/api/annotations.upb.h +0 -1
- data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +234 -0
- data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +759 -0
- data/src/core/ext/upb-generated/google/api/http.upb.h +29 -28
- data/src/core/ext/upb-generated/google/protobuf/any.upb.h +5 -6
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +39 -39
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +412 -386
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +5 -6
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +1 -2
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +1 -1
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +34 -55
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +5 -6
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +27 -28
- data/src/core/ext/upb-generated/google/rpc/status.upb.h +8 -8
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +1 -1
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +32 -45
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +4 -4
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +157 -178
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +14 -13
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +6 -7
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +59 -56
- data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +11 -12
- data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +0 -1
- data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +5 -6
- data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +27 -0
- data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +53 -0
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +6 -6
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +41 -68
- data/src/core/ext/upb-generated/validate/validate.upb.c +11 -11
- data/src/core/ext/upb-generated/validate/validate.upb.h +537 -536
- data/src/core/ext/xds/xds_api.cc +2388 -0
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_api.h +120 -40
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.cc +56 -25
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.h +8 -3
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel.h +4 -4
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_args.h +3 -3
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_secure.cc +2 -5
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.cc +94 -347
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.h +12 -45
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.cc +2 -2
- data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.h +13 -13
- data/src/core/lib/channel/channel_trace.cc +2 -6
- data/src/core/lib/channel/channelz.cc +19 -30
- data/src/core/lib/channel/channelz.h +1 -1
- data/src/core/lib/channel/channelz_registry.cc +3 -1
- data/src/core/lib/gpr/log_linux.cc +6 -8
- data/src/core/lib/gpr/log_posix.cc +6 -8
- data/src/core/lib/gpr/string.cc +10 -9
- data/src/core/lib/gpr/string.h +4 -2
- data/src/core/lib/gpr/sync_posix.cc +2 -8
- data/src/core/lib/gprpp/global_config_env.cc +8 -6
- data/src/core/lib/http/httpcli.cc +13 -10
- data/src/core/lib/http/httpcli_security_connector.cc +5 -5
- data/src/core/lib/iomgr/cfstream_handle.cc +1 -0
- data/src/core/lib/iomgr/endpoint.cc +5 -1
- data/src/core/lib/iomgr/endpoint.h +7 -3
- data/src/core/lib/iomgr/endpoint_cfstream.cc +32 -11
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +10 -10
- data/src/core/lib/iomgr/error_cfstream.cc +9 -8
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +5 -6
- data/src/core/lib/iomgr/ev_epollex_linux.cc +15 -21
- data/src/core/lib/iomgr/ev_poll_posix.cc +6 -5
- data/src/core/lib/iomgr/is_epollexclusive_available.cc +14 -0
- data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.cc +1 -1
- data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.h +3 -3
- data/src/core/lib/iomgr/port.h +1 -21
- data/src/core/lib/iomgr/resolve_address_custom.cc +13 -18
- data/src/core/lib/iomgr/resolve_address_windows.cc +8 -8
- data/src/core/lib/iomgr/resource_quota.cc +34 -31
- data/src/core/lib/iomgr/sockaddr_utils.cc +9 -6
- data/src/core/lib/iomgr/sockaddr_utils.h +3 -2
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +95 -55
- data/src/core/lib/iomgr/socket_windows.cc +4 -5
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +9 -11
- data/src/core/lib/iomgr/tcp_client_custom.cc +6 -9
- data/src/core/lib/iomgr/tcp_client_posix.cc +27 -36
- data/src/core/lib/iomgr/tcp_client_windows.cc +9 -9
- data/src/core/lib/iomgr/tcp_custom.cc +33 -17
- data/src/core/lib/iomgr/tcp_custom.h +1 -1
- data/src/core/lib/iomgr/tcp_posix.cc +31 -13
- data/src/core/lib/iomgr/tcp_server.cc +3 -4
- data/src/core/lib/iomgr/tcp_server.h +7 -5
- data/src/core/lib/iomgr/tcp_server_custom.cc +6 -14
- data/src/core/lib/iomgr/tcp_server_posix.cc +34 -41
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -4
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +5 -7
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +4 -9
- data/src/core/lib/iomgr/tcp_server_windows.cc +16 -16
- data/src/core/lib/iomgr/tcp_windows.cc +26 -10
- data/src/core/lib/iomgr/timer_generic.cc +13 -12
- data/src/core/lib/iomgr/udp_server.cc +24 -23
- data/src/core/lib/iomgr/udp_server.h +5 -2
- data/src/core/lib/iomgr/unix_sockets_posix.cc +9 -14
- data/src/core/lib/iomgr/unix_sockets_posix.h +3 -1
- data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +5 -2
- data/src/core/lib/json/json_reader.cc +20 -21
- data/src/core/lib/security/authorization/authorization_engine.cc +177 -0
- data/src/core/lib/security/authorization/authorization_engine.h +84 -0
- data/src/core/lib/security/authorization/evaluate_args.cc +153 -0
- data/src/core/lib/security/authorization/evaluate_args.h +59 -0
- data/src/core/lib/security/authorization/mock_cel/activation.h +57 -0
- data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +42 -0
- data/src/core/lib/security/authorization/mock_cel/cel_expression.h +68 -0
- data/src/core/lib/security/authorization/mock_cel/cel_value.h +93 -0
- data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +67 -0
- data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +56 -0
- data/src/core/lib/security/authorization/mock_cel/statusor.h +50 -0
- data/src/core/lib/security/credentials/credentials.h +5 -3
- data/src/core/lib/security/credentials/google_default/credentials_generic.cc +8 -6
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +64 -43
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +7 -4
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +19 -28
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -6
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +10 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +10 -0
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +11 -12
- data/src/core/lib/security/security_connector/security_connector.cc +2 -0
- data/src/core/lib/security/security_connector/security_connector.h +1 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +18 -11
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +5 -0
- data/src/core/lib/security/security_connector/ssl_utils.cc +44 -23
- data/src/core/lib/security/security_connector/ssl_utils.h +6 -2
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +27 -24
- data/src/core/lib/security/transport/client_auth_filter.cc +10 -9
- data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
- data/src/core/lib/security/util/json_util.cc +12 -13
- data/src/core/lib/slice/slice.cc +38 -1
- data/src/core/lib/slice/slice_internal.h +1 -0
- data/src/core/lib/surface/call.cc +52 -53
- data/src/core/lib/surface/call.h +2 -1
- data/src/core/lib/surface/channel.cc +28 -20
- data/src/core/lib/surface/channel.h +12 -2
- data/src/core/lib/surface/completion_queue.cc +0 -5
- data/src/core/lib/surface/init.cc +1 -1
- data/src/core/lib/surface/server.cc +1102 -1347
- data/src/core/lib/surface/server.h +369 -71
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/authority_override.cc +38 -0
- data/src/core/lib/transport/authority_override.h +32 -0
- data/src/core/lib/transport/connectivity_state.cc +18 -13
- data/src/core/lib/transport/connectivity_state.h +18 -6
- data/src/core/lib/transport/error_utils.cc +13 -0
- data/src/core/lib/transport/error_utils.h +6 -0
- data/src/core/lib/transport/static_metadata.cc +295 -276
- data/src/core/lib/transport/static_metadata.h +80 -73
- data/src/core/lib/transport/transport.h +13 -0
- data/src/core/lib/uri/uri_parser.cc +30 -35
- data/src/core/lib/uri/uri_parser.h +3 -1
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +23 -13
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +24 -0
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +2 -0
- data/src/core/tsi/ssl_transport_security.cc +102 -11
- data/src/core/tsi/ssl_transport_security.h +14 -2
- data/src/core/tsi/transport_security_interface.h +5 -0
- data/src/ruby/bin/math_services_pb.rb +4 -4
- data/src/ruby/ext/grpc/extconf.rb +5 -2
- data/src/ruby/ext/grpc/rb_call.c +3 -2
- data/src/ruby/ext/grpc/rb_call.h +4 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +54 -10
- data/src/ruby/ext/grpc/rb_channel_credentials.c +9 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -4
- data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
- data/src/ruby/lib/grpc/generic/interceptors.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +2 -2
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +5 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +28 -12
- data/src/ruby/spec/channel_credentials_spec.rb +10 -0
- data/src/ruby/spec/generic/active_call_spec.rb +19 -8
- data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +20 -0
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- data/third_party/abseil-cpp/absl/algorithm/container.h +1727 -0
- data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +161 -0
- data/third_party/abseil-cpp/absl/base/internal/exponential_biased.cc +93 -0
- data/third_party/abseil-cpp/absl/base/internal/exponential_biased.h +130 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +620 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +126 -0
- data/third_party/abseil-cpp/absl/container/fixed_array.h +515 -0
- data/third_party/abseil-cpp/absl/container/flat_hash_set.h +503 -0
- data/third_party/abseil-cpp/absl/container/internal/common.h +202 -0
- data/third_party/abseil-cpp/absl/container/internal/container_memory.h +440 -0
- data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +146 -0
- data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +191 -0
- data/third_party/abseil-cpp/absl/container/internal/hashtable_debug_hooks.h +85 -0
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +269 -0
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +297 -0
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +30 -0
- data/third_party/abseil-cpp/absl/container/internal/have_sse.h +49 -0
- data/third_party/abseil-cpp/absl/container/internal/layout.h +741 -0
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +48 -0
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +1882 -0
- data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +138 -0
- data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.h +32 -0
- data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +1895 -0
- data/third_party/abseil-cpp/absl/debugging/internal/demangle.h +71 -0
- data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.cc +382 -0
- data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +134 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +192 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +125 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +70 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +99 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +248 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_unimplemented-inl.inc +24 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +85 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +346 -0
- data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +128 -0
- data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +194 -0
- data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.h +158 -0
- data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +140 -0
- data/third_party/abseil-cpp/absl/debugging/stacktrace.h +231 -0
- data/third_party/abseil-cpp/absl/debugging/symbolize.cc +25 -0
- data/third_party/abseil-cpp/absl/debugging/symbolize.h +99 -0
- data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +1480 -0
- data/third_party/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +40 -0
- data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +81 -0
- data/third_party/abseil-cpp/absl/functional/function_ref.h +139 -0
- data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +106 -0
- data/third_party/abseil-cpp/absl/hash/hash.h +324 -0
- data/third_party/abseil-cpp/absl/hash/internal/city.cc +346 -0
- data/third_party/abseil-cpp/absl/hash/internal/city.h +96 -0
- data/third_party/abseil-cpp/absl/hash/internal/hash.cc +55 -0
- data/third_party/abseil-cpp/absl/hash/internal/hash.h +988 -0
- data/third_party/abseil-cpp/absl/status/status.cc +447 -0
- data/third_party/abseil-cpp/absl/status/status.h +428 -0
- data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +43 -0
- data/third_party/abseil-cpp/absl/status/status_payload_printer.h +51 -0
- data/third_party/abseil-cpp/absl/strings/cord.cc +2019 -0
- data/third_party/abseil-cpp/absl/strings/cord.h +1121 -0
- data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +151 -0
- data/third_party/abseil-cpp/absl/synchronization/barrier.cc +52 -0
- data/third_party/abseil-cpp/absl/synchronization/barrier.h +79 -0
- data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +57 -0
- data/third_party/abseil-cpp/absl/synchronization/blocking_counter.h +99 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +140 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.h +60 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +697 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.h +141 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +155 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +261 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +106 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +115 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +484 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +159 -0
- data/third_party/abseil-cpp/absl/synchronization/mutex.cc +2728 -0
- data/third_party/abseil-cpp/absl/synchronization/mutex.h +1056 -0
- data/third_party/abseil-cpp/absl/synchronization/notification.cc +78 -0
- data/third_party/abseil-cpp/absl/synchronization/notification.h +123 -0
- data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +64 -0
- data/third_party/abseil-cpp/absl/types/bad_variant_access.h +82 -0
- data/third_party/abseil-cpp/absl/types/internal/variant.h +1646 -0
- data/third_party/abseil-cpp/absl/types/variant.h +861 -0
- data/third_party/boringssl-with-bazel/err_data.c +266 -254
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_enum.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_int.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/asn_pack.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/f_enum.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/f_int.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/asn1/f_string.c +1 -1
- data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +1 -0
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +12 -52
- data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +0 -22
- data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +159 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/mode_wrappers.c +17 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +11 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +2 -1
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +13 -11
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-x86_64.c +24 -23
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +20 -16
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +2 -2
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/util.c +3 -3
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +62 -0
- data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +456 -0
- data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +192 -0
- data/third_party/boringssl-with-bazel/src/crypto/mem.c +29 -15
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +7 -0
- data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +36 -5
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +0 -29
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +116 -363
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +7 -45
- data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +8 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.c +4 -4
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509.c +0 -67
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +13 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +10 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +41 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +4 -1
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +28 -9
- data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +25 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +35 -13
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +0 -154
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +20 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +28 -6
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +5 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +74 -35
- data/third_party/boringssl-with-bazel/src/include/openssl/aes.h +16 -4
- data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +52 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +22 -22
- data/third_party/boringssl-with-bazel/src/include/openssl/base.h +2 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +69 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +72 -23
- data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +2 -3
- data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +1 -10
- data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +800 -715
- data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +3 -3
- data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +9 -2
- data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -2
- data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +9 -0
- data/third_party/boringssl-with-bazel/src/ssl/internal.h +21 -14
- data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +7 -7
- data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +3 -6
- data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +38 -0
- data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +4 -24
- data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +5 -5
- data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +45 -24
- data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +34 -9
- data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +31 -21
- data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +17 -9
- data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +5 -3
- data/third_party/re2/re2/bitmap256.h +117 -0
- data/third_party/re2/re2/bitstate.cc +385 -0
- data/third_party/re2/re2/compile.cc +1279 -0
- data/third_party/re2/re2/dfa.cc +2130 -0
- data/third_party/re2/re2/filtered_re2.cc +121 -0
- data/third_party/re2/re2/filtered_re2.h +109 -0
- data/third_party/re2/re2/mimics_pcre.cc +197 -0
- data/third_party/re2/re2/nfa.cc +713 -0
- data/third_party/re2/re2/onepass.cc +623 -0
- data/third_party/re2/re2/parse.cc +2464 -0
- data/third_party/re2/re2/perl_groups.cc +119 -0
- data/third_party/re2/re2/pod_array.h +55 -0
- data/third_party/re2/re2/prefilter.cc +710 -0
- data/third_party/re2/re2/prefilter.h +108 -0
- data/third_party/re2/re2/prefilter_tree.cc +407 -0
- data/third_party/re2/re2/prefilter_tree.h +139 -0
- data/third_party/re2/re2/prog.cc +988 -0
- data/third_party/re2/re2/prog.h +436 -0
- data/third_party/re2/re2/re2.cc +1362 -0
- data/third_party/re2/re2/re2.h +1002 -0
- data/third_party/re2/re2/regexp.cc +980 -0
- data/third_party/re2/re2/regexp.h +659 -0
- data/third_party/re2/re2/set.cc +154 -0
- data/third_party/re2/re2/set.h +80 -0
- data/third_party/re2/re2/simplify.cc +657 -0
- data/third_party/re2/re2/sparse_array.h +392 -0
- data/third_party/re2/re2/sparse_set.h +264 -0
- data/third_party/re2/re2/stringpiece.cc +65 -0
- data/third_party/re2/re2/stringpiece.h +210 -0
- data/third_party/re2/re2/tostring.cc +351 -0
- data/third_party/re2/re2/unicode_casefold.cc +582 -0
- data/third_party/re2/re2/unicode_casefold.h +78 -0
- data/third_party/re2/re2/unicode_groups.cc +6269 -0
- data/third_party/re2/re2/unicode_groups.h +67 -0
- data/third_party/re2/re2/walker-inl.h +246 -0
- data/third_party/re2/util/benchmark.h +156 -0
- data/third_party/re2/util/flags.h +26 -0
- data/third_party/re2/util/logging.h +109 -0
- data/third_party/re2/util/malloc_counter.h +19 -0
- data/third_party/re2/util/mix.h +41 -0
- data/third_party/re2/util/mutex.h +148 -0
- data/third_party/re2/util/pcre.cc +1025 -0
- data/third_party/re2/util/pcre.h +681 -0
- data/third_party/re2/util/rune.cc +260 -0
- data/third_party/re2/util/strutil.cc +149 -0
- data/third_party/re2/util/strutil.h +21 -0
- data/third_party/re2/util/test.h +50 -0
- data/third_party/re2/util/utf.h +44 -0
- data/third_party/re2/util/util.h +42 -0
- data/third_party/upb/upb/decode.c +517 -505
- data/third_party/upb/upb/encode.c +165 -123
- data/third_party/upb/upb/msg.c +130 -64
- data/third_party/upb/upb/msg.h +418 -14
- data/third_party/upb/upb/port_def.inc +35 -6
- data/third_party/upb/upb/port_undef.inc +8 -1
- data/third_party/upb/upb/table.c +53 -86
- data/third_party/upb/upb/table.int.h +11 -52
- data/third_party/upb/upb/upb.c +151 -125
- data/third_party/upb/upb/upb.h +91 -147
- data/third_party/upb/upb/upb.hpp +88 -0
- metadata +308 -148
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +0 -1906
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +0 -21
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -35
- data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +0 -114
- data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +0 -418
- data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +0 -72
- data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +0 -197
- data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +0 -105
- data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +0 -378
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +0 -53
- data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +0 -403
- data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +0 -1447
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +0 -74
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +0 -218
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +0 -69
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +0 -305
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +0 -112
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +0 -328
- data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +0 -78
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +0 -313
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +0 -897
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +0 -96
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +0 -322
- data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +0 -34
- data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +0 -72
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +0 -197
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +0 -642
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +0 -172
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +0 -673
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +0 -80
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +0 -152
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +0 -518
- data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +0 -89
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +0 -129
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +0 -392
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +0 -53
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +0 -92
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +0 -240
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +0 -18
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -33
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +0 -91
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +0 -266
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +0 -112
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +0 -324
- data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +0 -53
- data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +0 -109
- data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +0 -399
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +0 -18
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -33
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +0 -145
- data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +0 -527
- data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +0 -43
- data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +0 -112
- data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +0 -53
- data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +0 -63
- data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +0 -199
- data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +0 -18
- data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -33
- data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +0 -815
- data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +0 -3032
- data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +0 -59
- data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +0 -134
- data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +0 -53
- data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +0 -228
- data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +0 -725
- data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +0 -316
- data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +0 -1132
- data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +0 -65
- data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +0 -51
- data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +0 -125
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +0 -50
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +0 -54
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +0 -134
- data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +0 -63
- data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +0 -144
- data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +0 -53
- data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +0 -133
- data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +0 -88
- data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +0 -258
- data/src/core/ext/upb-generated/envoy/type/percent.upb.h +0 -87
- data/src/core/ext/upb-generated/envoy/type/range.upb.h +0 -112
- data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +0 -62
- data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +0 -89
- data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +0 -249
- data/src/core/lib/security/transport/target_authority_table.cc +0 -75
- data/src/core/lib/security/transport/target_authority_table.h +0 -40
- data/src/core/lib/slice/slice_hash_table.h +0 -199
- data/src/core/lib/slice/slice_weak_hash_table.h +0 -102
- data/third_party/upb/upb/generated_util.h +0 -105
@@ -0,0 +1,2388 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2018 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <grpc/support/port_platform.h>
|
20
|
+
|
21
|
+
#include <algorithm>
|
22
|
+
#include <cctype>
|
23
|
+
#include <cstdint>
|
24
|
+
#include <cstdlib>
|
25
|
+
#include <string>
|
26
|
+
|
27
|
+
#include "absl/strings/str_cat.h"
|
28
|
+
#include "absl/strings/str_format.h"
|
29
|
+
#include "absl/strings/str_join.h"
|
30
|
+
#include "absl/strings/str_split.h"
|
31
|
+
|
32
|
+
#include "upb/upb.hpp"
|
33
|
+
|
34
|
+
#include <grpc/impl/codegen/log.h>
|
35
|
+
#include <grpc/support/alloc.h>
|
36
|
+
#include <grpc/support/string_util.h>
|
37
|
+
|
38
|
+
#include "src/core/ext/xds/xds_api.h"
|
39
|
+
#include "src/core/lib/gpr/env.h"
|
40
|
+
#include "src/core/lib/gpr/string.h"
|
41
|
+
#include "src/core/lib/gpr/useful.h"
|
42
|
+
#include "src/core/lib/iomgr/error.h"
|
43
|
+
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
44
|
+
|
45
|
+
#include "envoy/config/cluster/v3/cluster.upb.h"
|
46
|
+
#include "envoy/config/core/v3/address.upb.h"
|
47
|
+
#include "envoy/config/core/v3/base.upb.h"
|
48
|
+
#include "envoy/config/core/v3/config_source.upb.h"
|
49
|
+
#include "envoy/config/core/v3/health_check.upb.h"
|
50
|
+
#include "envoy/config/endpoint/v3/endpoint.upb.h"
|
51
|
+
#include "envoy/config/endpoint/v3/endpoint_components.upb.h"
|
52
|
+
#include "envoy/config/endpoint/v3/load_report.upb.h"
|
53
|
+
#include "envoy/config/listener/v3/api_listener.upb.h"
|
54
|
+
#include "envoy/config/listener/v3/listener.upb.h"
|
55
|
+
#include "envoy/config/route/v3/route.upb.h"
|
56
|
+
#include "envoy/config/route/v3/route_components.upb.h"
|
57
|
+
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h"
|
58
|
+
#include "envoy/service/cluster/v3/cds.upb.h"
|
59
|
+
#include "envoy/service/discovery/v3/discovery.upb.h"
|
60
|
+
#include "envoy/service/endpoint/v3/eds.upb.h"
|
61
|
+
#include "envoy/service/listener/v3/lds.upb.h"
|
62
|
+
#include "envoy/service/load_stats/v3/lrs.upb.h"
|
63
|
+
#include "envoy/service/route/v3/rds.upb.h"
|
64
|
+
#include "envoy/type/matcher/v3/regex.upb.h"
|
65
|
+
#include "envoy/type/v3/percent.upb.h"
|
66
|
+
#include "envoy/type/v3/range.upb.h"
|
67
|
+
#include "google/protobuf/any.upb.h"
|
68
|
+
#include "google/protobuf/duration.upb.h"
|
69
|
+
#include "google/protobuf/struct.upb.h"
|
70
|
+
#include "google/protobuf/wrappers.upb.h"
|
71
|
+
#include "google/rpc/status.upb.h"
|
72
|
+
#include "upb/upb.h"
|
73
|
+
|
74
|
+
namespace grpc_core {
|
75
|
+
|
76
|
+
//
|
77
|
+
// XdsApi::Route::Matchers::PathMatcher
|
78
|
+
//
|
79
|
+
|
80
|
+
XdsApi::Route::Matchers::PathMatcher::PathMatcher(const PathMatcher& other)
|
81
|
+
: type(other.type) {
|
82
|
+
if (type == PathMatcherType::REGEX) {
|
83
|
+
regex_matcher = absl::make_unique<RE2>(other.regex_matcher->pattern());
|
84
|
+
} else {
|
85
|
+
string_matcher = other.string_matcher;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
XdsApi::Route::Matchers::PathMatcher& XdsApi::Route::Matchers::PathMatcher::
|
90
|
+
operator=(const PathMatcher& other) {
|
91
|
+
type = other.type;
|
92
|
+
if (type == PathMatcherType::REGEX) {
|
93
|
+
regex_matcher = absl::make_unique<RE2>(other.regex_matcher->pattern());
|
94
|
+
} else {
|
95
|
+
string_matcher = other.string_matcher;
|
96
|
+
}
|
97
|
+
return *this;
|
98
|
+
}
|
99
|
+
|
100
|
+
bool XdsApi::Route::Matchers::PathMatcher::operator==(
|
101
|
+
const PathMatcher& other) const {
|
102
|
+
if (type != other.type) return false;
|
103
|
+
if (type == PathMatcherType::REGEX) {
|
104
|
+
// Should never be null.
|
105
|
+
if (regex_matcher == nullptr || other.regex_matcher == nullptr) {
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
return regex_matcher->pattern() == other.regex_matcher->pattern();
|
109
|
+
}
|
110
|
+
return string_matcher == other.string_matcher;
|
111
|
+
}
|
112
|
+
|
113
|
+
std::string XdsApi::Route::Matchers::PathMatcher::ToString() const {
|
114
|
+
std::string path_type_string;
|
115
|
+
switch (type) {
|
116
|
+
case PathMatcherType::PATH:
|
117
|
+
path_type_string = "path match";
|
118
|
+
break;
|
119
|
+
case PathMatcherType::PREFIX:
|
120
|
+
path_type_string = "prefix match";
|
121
|
+
break;
|
122
|
+
case PathMatcherType::REGEX:
|
123
|
+
path_type_string = "regex match";
|
124
|
+
break;
|
125
|
+
default:
|
126
|
+
break;
|
127
|
+
}
|
128
|
+
return absl::StrFormat("Path %s:%s", path_type_string,
|
129
|
+
type == PathMatcherType::REGEX
|
130
|
+
? regex_matcher->pattern()
|
131
|
+
: string_matcher);
|
132
|
+
}
|
133
|
+
|
134
|
+
//
|
135
|
+
// XdsApi::Route::Matchers::HeaderMatcher
|
136
|
+
//
|
137
|
+
|
138
|
+
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcher(
|
139
|
+
const HeaderMatcher& other)
|
140
|
+
: name(other.name), type(other.type), invert_match(other.invert_match) {
|
141
|
+
switch (type) {
|
142
|
+
case HeaderMatcherType::REGEX:
|
143
|
+
regex_match = absl::make_unique<RE2>(other.regex_match->pattern());
|
144
|
+
break;
|
145
|
+
case HeaderMatcherType::RANGE:
|
146
|
+
range_start = other.range_start;
|
147
|
+
range_end = other.range_end;
|
148
|
+
break;
|
149
|
+
case HeaderMatcherType::PRESENT:
|
150
|
+
present_match = other.present_match;
|
151
|
+
break;
|
152
|
+
default:
|
153
|
+
string_matcher = other.string_matcher;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
XdsApi::Route::Matchers::HeaderMatcher& XdsApi::Route::Matchers::HeaderMatcher::
|
158
|
+
operator=(const HeaderMatcher& other) {
|
159
|
+
name = other.name;
|
160
|
+
type = other.type;
|
161
|
+
invert_match = other.invert_match;
|
162
|
+
switch (type) {
|
163
|
+
case HeaderMatcherType::REGEX:
|
164
|
+
regex_match = absl::make_unique<RE2>(other.regex_match->pattern());
|
165
|
+
break;
|
166
|
+
case HeaderMatcherType::RANGE:
|
167
|
+
range_start = other.range_start;
|
168
|
+
range_end = other.range_end;
|
169
|
+
break;
|
170
|
+
case HeaderMatcherType::PRESENT:
|
171
|
+
present_match = other.present_match;
|
172
|
+
break;
|
173
|
+
default:
|
174
|
+
string_matcher = other.string_matcher;
|
175
|
+
}
|
176
|
+
return *this;
|
177
|
+
}
|
178
|
+
|
179
|
+
bool XdsApi::Route::Matchers::HeaderMatcher::operator==(
|
180
|
+
const HeaderMatcher& other) const {
|
181
|
+
if (name != other.name) return false;
|
182
|
+
if (type != other.type) return false;
|
183
|
+
if (invert_match != other.invert_match) return false;
|
184
|
+
switch (type) {
|
185
|
+
case HeaderMatcherType::REGEX:
|
186
|
+
return regex_match->pattern() != other.regex_match->pattern();
|
187
|
+
case HeaderMatcherType::RANGE:
|
188
|
+
return range_start != other.range_start && range_end != other.range_end;
|
189
|
+
case HeaderMatcherType::PRESENT:
|
190
|
+
return present_match != other.present_match;
|
191
|
+
default:
|
192
|
+
return string_matcher != other.string_matcher;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
std::string XdsApi::Route::Matchers::HeaderMatcher::ToString() const {
|
197
|
+
switch (type) {
|
198
|
+
case HeaderMatcherType::EXACT:
|
199
|
+
return absl::StrFormat("Header exact match:%s %s:%s",
|
200
|
+
invert_match ? " not" : "", name, string_matcher);
|
201
|
+
case HeaderMatcherType::REGEX:
|
202
|
+
return absl::StrFormat("Header regex match:%s %s:%s",
|
203
|
+
invert_match ? " not" : "", name,
|
204
|
+
regex_match->pattern());
|
205
|
+
case HeaderMatcherType::RANGE:
|
206
|
+
return absl::StrFormat("Header range match:%s %s:[%d, %d)",
|
207
|
+
invert_match ? " not" : "", name, range_start,
|
208
|
+
range_end);
|
209
|
+
case HeaderMatcherType::PRESENT:
|
210
|
+
return absl::StrFormat("Header present match:%s %s:%s",
|
211
|
+
invert_match ? " not" : "", name,
|
212
|
+
present_match ? "true" : "false");
|
213
|
+
case HeaderMatcherType::PREFIX:
|
214
|
+
return absl::StrFormat("Header prefix match:%s %s:%s",
|
215
|
+
invert_match ? " not" : "", name, string_matcher);
|
216
|
+
case HeaderMatcherType::SUFFIX:
|
217
|
+
return absl::StrFormat("Header suffix match:%s %s:%s",
|
218
|
+
invert_match ? " not" : "", name, string_matcher);
|
219
|
+
default:
|
220
|
+
return "";
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
//
|
225
|
+
// XdsApi::Route
|
226
|
+
//
|
227
|
+
|
228
|
+
std::string XdsApi::Route::Matchers::ToString() const {
|
229
|
+
std::vector<std::string> contents;
|
230
|
+
contents.push_back(path_matcher.ToString());
|
231
|
+
for (const auto& header_it : header_matchers) {
|
232
|
+
contents.push_back(header_it.ToString());
|
233
|
+
}
|
234
|
+
if (fraction_per_million.has_value()) {
|
235
|
+
contents.push_back(absl::StrFormat("Fraction Per Million %d",
|
236
|
+
fraction_per_million.value()));
|
237
|
+
}
|
238
|
+
return absl::StrJoin(contents, "\n");
|
239
|
+
}
|
240
|
+
|
241
|
+
std::string XdsApi::Route::ClusterWeight::ToString() const {
|
242
|
+
return absl::StrFormat("{cluster=%s, weight=%d}", name, weight);
|
243
|
+
}
|
244
|
+
|
245
|
+
std::string XdsApi::Route::ToString() const {
|
246
|
+
std::vector<std::string> contents;
|
247
|
+
contents.push_back(matchers.ToString());
|
248
|
+
if (!cluster_name.empty()) {
|
249
|
+
contents.push_back(absl::StrFormat("Cluster name: %s", cluster_name));
|
250
|
+
}
|
251
|
+
for (const auto& weighted_it : weighted_clusters) {
|
252
|
+
contents.push_back(weighted_it.ToString());
|
253
|
+
}
|
254
|
+
return absl::StrJoin(contents, "\n");
|
255
|
+
}
|
256
|
+
|
257
|
+
//
|
258
|
+
// XdsApi::RdsUpdate
|
259
|
+
//
|
260
|
+
|
261
|
+
std::string XdsApi::RdsUpdate::ToString() const {
|
262
|
+
std::vector<std::string> vhosts;
|
263
|
+
for (const VirtualHost& vhost : virtual_hosts) {
|
264
|
+
vhosts.push_back(
|
265
|
+
absl::StrCat("vhost={\n"
|
266
|
+
" domains=[",
|
267
|
+
absl::StrJoin(vhost.domains, ", "),
|
268
|
+
"]\n"
|
269
|
+
" routes=[\n"));
|
270
|
+
for (const XdsApi::Route& route : vhost.routes) {
|
271
|
+
vhosts.push_back(" {\n");
|
272
|
+
vhosts.push_back(route.ToString());
|
273
|
+
vhosts.push_back("\n }\n");
|
274
|
+
}
|
275
|
+
vhosts.push_back(" ]\n");
|
276
|
+
vhosts.push_back("]\n");
|
277
|
+
}
|
278
|
+
return absl::StrJoin(vhosts, "");
|
279
|
+
}
|
280
|
+
|
281
|
+
namespace {
|
282
|
+
|
283
|
+
// Better match type has smaller value.
|
284
|
+
enum MatchType {
|
285
|
+
EXACT_MATCH,
|
286
|
+
SUFFIX_MATCH,
|
287
|
+
PREFIX_MATCH,
|
288
|
+
UNIVERSE_MATCH,
|
289
|
+
INVALID_MATCH,
|
290
|
+
};
|
291
|
+
|
292
|
+
// Returns true if match succeeds.
|
293
|
+
bool DomainMatch(MatchType match_type, std::string domain_pattern,
|
294
|
+
std::string expected_host_name) {
|
295
|
+
// Normalize the args to lower-case. Domain matching is case-insensitive.
|
296
|
+
std::transform(domain_pattern.begin(), domain_pattern.end(),
|
297
|
+
domain_pattern.begin(),
|
298
|
+
[](unsigned char c) { return std::tolower(c); });
|
299
|
+
std::transform(expected_host_name.begin(), expected_host_name.end(),
|
300
|
+
expected_host_name.begin(),
|
301
|
+
[](unsigned char c) { return std::tolower(c); });
|
302
|
+
if (match_type == EXACT_MATCH) {
|
303
|
+
return domain_pattern == expected_host_name;
|
304
|
+
} else if (match_type == SUFFIX_MATCH) {
|
305
|
+
// Asterisk must match at least one char.
|
306
|
+
if (expected_host_name.size() < domain_pattern.size()) return false;
|
307
|
+
absl::string_view pattern_suffix(domain_pattern.c_str() + 1);
|
308
|
+
absl::string_view host_suffix(expected_host_name.c_str() +
|
309
|
+
expected_host_name.size() -
|
310
|
+
pattern_suffix.size());
|
311
|
+
return pattern_suffix == host_suffix;
|
312
|
+
} else if (match_type == PREFIX_MATCH) {
|
313
|
+
// Asterisk must match at least one char.
|
314
|
+
if (expected_host_name.size() < domain_pattern.size()) return false;
|
315
|
+
absl::string_view pattern_prefix(domain_pattern.c_str(),
|
316
|
+
domain_pattern.size() - 1);
|
317
|
+
absl::string_view host_prefix(expected_host_name.c_str(),
|
318
|
+
pattern_prefix.size());
|
319
|
+
return pattern_prefix == host_prefix;
|
320
|
+
} else {
|
321
|
+
return match_type == UNIVERSE_MATCH;
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
MatchType DomainPatternMatchType(const std::string& domain_pattern) {
|
326
|
+
if (domain_pattern.empty()) return INVALID_MATCH;
|
327
|
+
if (domain_pattern.find('*') == std::string::npos) return EXACT_MATCH;
|
328
|
+
if (domain_pattern == "*") return UNIVERSE_MATCH;
|
329
|
+
if (domain_pattern[0] == '*') return SUFFIX_MATCH;
|
330
|
+
if (domain_pattern[domain_pattern.size() - 1] == '*') return PREFIX_MATCH;
|
331
|
+
return INVALID_MATCH;
|
332
|
+
}
|
333
|
+
|
334
|
+
} // namespace
|
335
|
+
|
336
|
+
const XdsApi::RdsUpdate::VirtualHost*
|
337
|
+
XdsApi::RdsUpdate::FindVirtualHostForDomain(const std::string& domain) const {
|
338
|
+
// Find the best matched virtual host.
|
339
|
+
// The search order for 4 groups of domain patterns:
|
340
|
+
// 1. Exact match.
|
341
|
+
// 2. Suffix match (e.g., "*ABC").
|
342
|
+
// 3. Prefix match (e.g., "ABC*").
|
343
|
+
// 4. Universe match (i.e., "*").
|
344
|
+
// Within each group, longest match wins.
|
345
|
+
// If the same best matched domain pattern appears in multiple virtual hosts,
|
346
|
+
// the first matched virtual host wins.
|
347
|
+
const VirtualHost* target_vhost = nullptr;
|
348
|
+
MatchType best_match_type = INVALID_MATCH;
|
349
|
+
size_t longest_match = 0;
|
350
|
+
// Check each domain pattern in each virtual host to determine the best
|
351
|
+
// matched virtual host.
|
352
|
+
for (const VirtualHost& vhost : virtual_hosts) {
|
353
|
+
for (const std::string& domain_pattern : vhost.domains) {
|
354
|
+
// Check the match type first. Skip the pattern if it's not better than
|
355
|
+
// current match.
|
356
|
+
const MatchType match_type = DomainPatternMatchType(domain_pattern);
|
357
|
+
// This should be caught by RouteConfigParse().
|
358
|
+
GPR_ASSERT(match_type != INVALID_MATCH);
|
359
|
+
if (match_type > best_match_type) continue;
|
360
|
+
if (match_type == best_match_type &&
|
361
|
+
domain_pattern.size() <= longest_match) {
|
362
|
+
continue;
|
363
|
+
}
|
364
|
+
// Skip if match fails.
|
365
|
+
if (!DomainMatch(match_type, domain_pattern, domain)) continue;
|
366
|
+
// Choose this match.
|
367
|
+
target_vhost = &vhost;
|
368
|
+
best_match_type = match_type;
|
369
|
+
longest_match = domain_pattern.size();
|
370
|
+
if (best_match_type == EXACT_MATCH) break;
|
371
|
+
}
|
372
|
+
if (best_match_type == EXACT_MATCH) break;
|
373
|
+
}
|
374
|
+
return target_vhost;
|
375
|
+
}
|
376
|
+
|
377
|
+
//
|
378
|
+
// XdsApi::PriorityListUpdate
|
379
|
+
//
|
380
|
+
|
381
|
+
bool XdsApi::PriorityListUpdate::operator==(
|
382
|
+
const XdsApi::PriorityListUpdate& other) const {
|
383
|
+
if (priorities_.size() != other.priorities_.size()) return false;
|
384
|
+
for (size_t i = 0; i < priorities_.size(); ++i) {
|
385
|
+
if (priorities_[i].localities != other.priorities_[i].localities) {
|
386
|
+
return false;
|
387
|
+
}
|
388
|
+
}
|
389
|
+
return true;
|
390
|
+
}
|
391
|
+
|
392
|
+
void XdsApi::PriorityListUpdate::Add(
|
393
|
+
XdsApi::PriorityListUpdate::LocalityMap::Locality locality) {
|
394
|
+
// Pad the missing priorities in case the localities are not ordered by
|
395
|
+
// priority.
|
396
|
+
if (!Contains(locality.priority)) priorities_.resize(locality.priority + 1);
|
397
|
+
LocalityMap& locality_map = priorities_[locality.priority];
|
398
|
+
locality_map.localities.emplace(locality.name, std::move(locality));
|
399
|
+
}
|
400
|
+
|
401
|
+
const XdsApi::PriorityListUpdate::LocalityMap* XdsApi::PriorityListUpdate::Find(
|
402
|
+
uint32_t priority) const {
|
403
|
+
if (!Contains(priority)) return nullptr;
|
404
|
+
return &priorities_[priority];
|
405
|
+
}
|
406
|
+
|
407
|
+
bool XdsApi::PriorityListUpdate::Contains(
|
408
|
+
const RefCountedPtr<XdsLocalityName>& name) {
|
409
|
+
for (size_t i = 0; i < priorities_.size(); ++i) {
|
410
|
+
const LocalityMap& locality_map = priorities_[i];
|
411
|
+
if (locality_map.Contains(name)) return true;
|
412
|
+
}
|
413
|
+
return false;
|
414
|
+
}
|
415
|
+
|
416
|
+
//
|
417
|
+
// XdsApi::DropConfig
|
418
|
+
//
|
419
|
+
|
420
|
+
bool XdsApi::DropConfig::ShouldDrop(const std::string** category_name) const {
|
421
|
+
for (size_t i = 0; i < drop_category_list_.size(); ++i) {
|
422
|
+
const auto& drop_category = drop_category_list_[i];
|
423
|
+
// Generate a random number in [0, 1000000).
|
424
|
+
const uint32_t random = static_cast<uint32_t>(rand()) % 1000000;
|
425
|
+
if (random < drop_category.parts_per_million) {
|
426
|
+
*category_name = &drop_category.name;
|
427
|
+
return true;
|
428
|
+
}
|
429
|
+
}
|
430
|
+
return false;
|
431
|
+
}
|
432
|
+
|
433
|
+
//
|
434
|
+
// XdsApi
|
435
|
+
//
|
436
|
+
|
437
|
+
const char* XdsApi::kLdsTypeUrl =
|
438
|
+
"type.googleapis.com/envoy.config.listener.v3.Listener";
|
439
|
+
const char* XdsApi::kRdsTypeUrl =
|
440
|
+
"type.googleapis.com/envoy.config.route.v3.RouteConfiguration";
|
441
|
+
const char* XdsApi::kCdsTypeUrl =
|
442
|
+
"type.googleapis.com/envoy.config.cluster.v3.Cluster";
|
443
|
+
const char* XdsApi::kEdsTypeUrl =
|
444
|
+
"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment";
|
445
|
+
|
446
|
+
namespace {
|
447
|
+
|
448
|
+
const char* kLdsV2TypeUrl = "type.googleapis.com/envoy.api.v2.Listener";
|
449
|
+
const char* kRdsV2TypeUrl =
|
450
|
+
"type.googleapis.com/envoy.api.v2.RouteConfiguration";
|
451
|
+
const char* kCdsV2TypeUrl = "type.googleapis.com/envoy.api.v2.Cluster";
|
452
|
+
const char* kEdsV2TypeUrl =
|
453
|
+
"type.googleapis.com/envoy.api.v2.ClusterLoadAssignment";
|
454
|
+
|
455
|
+
bool IsLds(absl::string_view type_url) {
|
456
|
+
return type_url == XdsApi::kLdsTypeUrl || type_url == kLdsV2TypeUrl;
|
457
|
+
}
|
458
|
+
|
459
|
+
bool IsRds(absl::string_view type_url) {
|
460
|
+
return type_url == XdsApi::kRdsTypeUrl || type_url == kRdsV2TypeUrl;
|
461
|
+
}
|
462
|
+
|
463
|
+
bool IsCds(absl::string_view type_url) {
|
464
|
+
return type_url == XdsApi::kCdsTypeUrl || type_url == kCdsV2TypeUrl;
|
465
|
+
}
|
466
|
+
|
467
|
+
bool IsEds(absl::string_view type_url) {
|
468
|
+
return type_url == XdsApi::kEdsTypeUrl || type_url == kEdsV2TypeUrl;
|
469
|
+
}
|
470
|
+
|
471
|
+
} // namespace
|
472
|
+
|
473
|
+
XdsApi::XdsApi(XdsClient* client, TraceFlag* tracer,
|
474
|
+
const XdsBootstrap* bootstrap)
|
475
|
+
: client_(client),
|
476
|
+
tracer_(tracer),
|
477
|
+
use_v3_(bootstrap != nullptr && bootstrap->server().ShouldUseV3()),
|
478
|
+
bootstrap_(bootstrap),
|
479
|
+
build_version_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING, " ",
|
480
|
+
grpc_version_string())),
|
481
|
+
user_agent_name_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING)) {}
|
482
|
+
|
483
|
+
namespace {
|
484
|
+
|
485
|
+
// Works for both std::string and absl::string_view.
|
486
|
+
template <typename T>
|
487
|
+
inline upb_strview StdStringToUpbString(const T& str) {
|
488
|
+
return upb_strview_make(str.data(), str.size());
|
489
|
+
}
|
490
|
+
|
491
|
+
void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
|
492
|
+
const Json& value);
|
493
|
+
|
494
|
+
void PopulateListValue(upb_arena* arena, google_protobuf_ListValue* list_value,
|
495
|
+
const Json::Array& values) {
|
496
|
+
for (const auto& value : values) {
|
497
|
+
auto* value_pb = google_protobuf_ListValue_add_values(list_value, arena);
|
498
|
+
PopulateMetadataValue(arena, value_pb, value);
|
499
|
+
}
|
500
|
+
}
|
501
|
+
|
502
|
+
void PopulateMetadata(upb_arena* arena, google_protobuf_Struct* metadata_pb,
|
503
|
+
const Json::Object& metadata) {
|
504
|
+
for (const auto& p : metadata) {
|
505
|
+
google_protobuf_Value* value = google_protobuf_Value_new(arena);
|
506
|
+
PopulateMetadataValue(arena, value, p.second);
|
507
|
+
google_protobuf_Struct_fields_set(
|
508
|
+
metadata_pb, StdStringToUpbString(p.first), value, arena);
|
509
|
+
}
|
510
|
+
}
|
511
|
+
|
512
|
+
void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
|
513
|
+
const Json& value) {
|
514
|
+
switch (value.type()) {
|
515
|
+
case Json::Type::JSON_NULL:
|
516
|
+
google_protobuf_Value_set_null_value(value_pb, 0);
|
517
|
+
break;
|
518
|
+
case Json::Type::NUMBER:
|
519
|
+
google_protobuf_Value_set_number_value(
|
520
|
+
value_pb, strtod(value.string_value().c_str(), nullptr));
|
521
|
+
break;
|
522
|
+
case Json::Type::STRING:
|
523
|
+
google_protobuf_Value_set_string_value(
|
524
|
+
value_pb, StdStringToUpbString(value.string_value()));
|
525
|
+
break;
|
526
|
+
case Json::Type::JSON_TRUE:
|
527
|
+
google_protobuf_Value_set_bool_value(value_pb, true);
|
528
|
+
break;
|
529
|
+
case Json::Type::JSON_FALSE:
|
530
|
+
google_protobuf_Value_set_bool_value(value_pb, false);
|
531
|
+
break;
|
532
|
+
case Json::Type::OBJECT: {
|
533
|
+
google_protobuf_Struct* struct_value =
|
534
|
+
google_protobuf_Value_mutable_struct_value(value_pb, arena);
|
535
|
+
PopulateMetadata(arena, struct_value, value.object_value());
|
536
|
+
break;
|
537
|
+
}
|
538
|
+
case Json::Type::ARRAY: {
|
539
|
+
google_protobuf_ListValue* list_value =
|
540
|
+
google_protobuf_Value_mutable_list_value(value_pb, arena);
|
541
|
+
PopulateListValue(arena, list_value, value.array_value());
|
542
|
+
break;
|
543
|
+
}
|
544
|
+
}
|
545
|
+
}
|
546
|
+
|
547
|
+
// Helper functions to manually do protobuf string encoding, so that we
|
548
|
+
// can populate the node build_version field that was removed in v3.
|
549
|
+
std::string EncodeVarint(uint64_t val) {
|
550
|
+
std::string data;
|
551
|
+
do {
|
552
|
+
uint8_t byte = val & 0x7fU;
|
553
|
+
val >>= 7;
|
554
|
+
if (val) byte |= 0x80U;
|
555
|
+
data += byte;
|
556
|
+
} while (val);
|
557
|
+
return data;
|
558
|
+
}
|
559
|
+
std::string EncodeTag(uint32_t field_number, uint8_t wire_type) {
|
560
|
+
return EncodeVarint((field_number << 3) | wire_type);
|
561
|
+
}
|
562
|
+
std::string EncodeStringField(uint32_t field_number, const std::string& str) {
|
563
|
+
static const uint8_t kDelimitedWireType = 2;
|
564
|
+
return EncodeTag(field_number, kDelimitedWireType) +
|
565
|
+
EncodeVarint(str.size()) + str;
|
566
|
+
}
|
567
|
+
|
568
|
+
void PopulateBuildVersion(upb_arena* arena, envoy_config_core_v3_Node* node_msg,
|
569
|
+
const std::string& build_version) {
|
570
|
+
std::string encoded_build_version = EncodeStringField(5, build_version);
|
571
|
+
// TODO(roth): This should use upb_msg_addunknown(), but that API is
|
572
|
+
// broken in the current version of upb, so we're using the internal
|
573
|
+
// API for now. Change this once we upgrade to a version of upb that
|
574
|
+
// fixes this bug.
|
575
|
+
_upb_msg_addunknown(node_msg, encoded_build_version.data(),
|
576
|
+
encoded_build_version.size(), arena);
|
577
|
+
}
|
578
|
+
|
579
|
+
void PopulateNode(upb_arena* arena, const XdsBootstrap* bootstrap,
|
580
|
+
const std::string& build_version,
|
581
|
+
const std::string& user_agent_name,
|
582
|
+
const std::string& server_name,
|
583
|
+
envoy_config_core_v3_Node* node_msg) {
|
584
|
+
const XdsBootstrap::Node* node = bootstrap->node();
|
585
|
+
if (node != nullptr) {
|
586
|
+
if (!node->id.empty()) {
|
587
|
+
envoy_config_core_v3_Node_set_id(node_msg,
|
588
|
+
StdStringToUpbString(node->id));
|
589
|
+
}
|
590
|
+
if (!node->cluster.empty()) {
|
591
|
+
envoy_config_core_v3_Node_set_cluster(
|
592
|
+
node_msg, StdStringToUpbString(node->cluster));
|
593
|
+
}
|
594
|
+
if (!node->metadata.object_value().empty()) {
|
595
|
+
google_protobuf_Struct* metadata =
|
596
|
+
envoy_config_core_v3_Node_mutable_metadata(node_msg, arena);
|
597
|
+
PopulateMetadata(arena, metadata, node->metadata.object_value());
|
598
|
+
}
|
599
|
+
if (!server_name.empty()) {
|
600
|
+
google_protobuf_Struct* metadata =
|
601
|
+
envoy_config_core_v3_Node_mutable_metadata(node_msg, arena);
|
602
|
+
google_protobuf_Value* value = google_protobuf_Value_new(arena);
|
603
|
+
google_protobuf_Value_set_string_value(value,
|
604
|
+
StdStringToUpbString(server_name));
|
605
|
+
google_protobuf_Struct_fields_set(
|
606
|
+
metadata, upb_strview_makez("PROXYLESS_CLIENT_HOSTNAME"), value,
|
607
|
+
arena);
|
608
|
+
}
|
609
|
+
if (!node->locality_region.empty() || !node->locality_zone.empty() ||
|
610
|
+
!node->locality_subzone.empty()) {
|
611
|
+
envoy_config_core_v3_Locality* locality =
|
612
|
+
envoy_config_core_v3_Node_mutable_locality(node_msg, arena);
|
613
|
+
if (!node->locality_region.empty()) {
|
614
|
+
envoy_config_core_v3_Locality_set_region(
|
615
|
+
locality, StdStringToUpbString(node->locality_region));
|
616
|
+
}
|
617
|
+
if (!node->locality_zone.empty()) {
|
618
|
+
envoy_config_core_v3_Locality_set_zone(
|
619
|
+
locality, StdStringToUpbString(node->locality_zone));
|
620
|
+
}
|
621
|
+
if (!node->locality_subzone.empty()) {
|
622
|
+
envoy_config_core_v3_Locality_set_sub_zone(
|
623
|
+
locality, StdStringToUpbString(node->locality_subzone));
|
624
|
+
}
|
625
|
+
}
|
626
|
+
}
|
627
|
+
if (!bootstrap->server().ShouldUseV3()) {
|
628
|
+
PopulateBuildVersion(arena, node_msg, build_version);
|
629
|
+
}
|
630
|
+
envoy_config_core_v3_Node_set_user_agent_name(
|
631
|
+
node_msg, StdStringToUpbString(user_agent_name));
|
632
|
+
envoy_config_core_v3_Node_set_user_agent_version(
|
633
|
+
node_msg, upb_strview_makez(grpc_version_string()));
|
634
|
+
envoy_config_core_v3_Node_add_client_features(
|
635
|
+
node_msg, upb_strview_makez("envoy.lb.does_not_support_overprovisioning"),
|
636
|
+
arena);
|
637
|
+
}
|
638
|
+
|
639
|
+
inline absl::string_view UpbStringToAbsl(const upb_strview& str) {
|
640
|
+
return absl::string_view(str.data, str.size);
|
641
|
+
}
|
642
|
+
|
643
|
+
inline std::string UpbStringToStdString(const upb_strview& str) {
|
644
|
+
return std::string(str.data, str.size);
|
645
|
+
}
|
646
|
+
|
647
|
+
inline void AddStringField(const char* name, const upb_strview& value,
|
648
|
+
std::vector<std::string>* fields,
|
649
|
+
bool add_if_empty = false) {
|
650
|
+
if (value.size > 0 || add_if_empty) {
|
651
|
+
fields->emplace_back(
|
652
|
+
absl::StrCat(name, ": \"", UpbStringToAbsl(value), "\""));
|
653
|
+
}
|
654
|
+
}
|
655
|
+
|
656
|
+
inline void AddUInt32ValueField(const char* name,
|
657
|
+
const google_protobuf_UInt32Value* value,
|
658
|
+
std::vector<std::string>* fields) {
|
659
|
+
if (value != nullptr) {
|
660
|
+
fields->emplace_back(absl::StrCat(
|
661
|
+
name, " { value: ", google_protobuf_UInt32Value_value(value), " }"));
|
662
|
+
}
|
663
|
+
}
|
664
|
+
|
665
|
+
inline void AddLocalityField(int indent_level,
|
666
|
+
const envoy_config_core_v3_Locality* locality,
|
667
|
+
std::vector<std::string>* fields) {
|
668
|
+
std::string indent =
|
669
|
+
absl::StrJoin(std::vector<std::string>(indent_level, " "), "");
|
670
|
+
// region
|
671
|
+
std::string field = absl::StrCat(indent, "region");
|
672
|
+
AddStringField(field.c_str(), envoy_config_core_v3_Locality_region(locality),
|
673
|
+
fields);
|
674
|
+
// zone
|
675
|
+
field = absl::StrCat(indent, "zone");
|
676
|
+
AddStringField(field.c_str(), envoy_config_core_v3_Locality_zone(locality),
|
677
|
+
fields);
|
678
|
+
// sub_zone
|
679
|
+
field = absl::StrCat(indent, "sub_zone");
|
680
|
+
AddStringField(field.c_str(),
|
681
|
+
envoy_config_core_v3_Locality_sub_zone(locality), fields);
|
682
|
+
}
|
683
|
+
|
684
|
+
void AddNodeLogFields(const envoy_config_core_v3_Node* node,
|
685
|
+
const std::string& build_version,
|
686
|
+
std::vector<std::string>* fields) {
|
687
|
+
fields->emplace_back("node {");
|
688
|
+
// id
|
689
|
+
AddStringField(" id", envoy_config_core_v3_Node_id(node), fields);
|
690
|
+
// metadata
|
691
|
+
const google_protobuf_Struct* metadata =
|
692
|
+
envoy_config_core_v3_Node_metadata(node);
|
693
|
+
if (metadata != nullptr) {
|
694
|
+
fields->emplace_back(" metadata {");
|
695
|
+
size_t entry_idx = UPB_MAP_BEGIN;
|
696
|
+
while (true) {
|
697
|
+
const google_protobuf_Struct_FieldsEntry* entry =
|
698
|
+
google_protobuf_Struct_fields_next(metadata, &entry_idx);
|
699
|
+
if (entry == nullptr) break;
|
700
|
+
fields->emplace_back(" field {");
|
701
|
+
// key
|
702
|
+
AddStringField(" key", google_protobuf_Struct_FieldsEntry_key(entry),
|
703
|
+
fields);
|
704
|
+
// value
|
705
|
+
const google_protobuf_Value* value =
|
706
|
+
google_protobuf_Struct_FieldsEntry_value(entry);
|
707
|
+
if (value != nullptr) {
|
708
|
+
std::string value_str;
|
709
|
+
if (google_protobuf_Value_has_string_value(value)) {
|
710
|
+
value_str = absl::StrCat(
|
711
|
+
"string_value: \"",
|
712
|
+
UpbStringToAbsl(google_protobuf_Value_string_value(value)), "\"");
|
713
|
+
} else if (google_protobuf_Value_has_null_value(value)) {
|
714
|
+
value_str = "null_value: NULL_VALUE";
|
715
|
+
} else if (google_protobuf_Value_has_number_value(value)) {
|
716
|
+
value_str = absl::StrCat("double_value: ",
|
717
|
+
google_protobuf_Value_number_value(value));
|
718
|
+
} else if (google_protobuf_Value_has_bool_value(value)) {
|
719
|
+
value_str = absl::StrCat("bool_value: ",
|
720
|
+
google_protobuf_Value_bool_value(value));
|
721
|
+
} else if (google_protobuf_Value_has_struct_value(value)) {
|
722
|
+
value_str = "struct_value: <not printed>";
|
723
|
+
} else if (google_protobuf_Value_has_list_value(value)) {
|
724
|
+
value_str = "list_value: <not printed>";
|
725
|
+
} else {
|
726
|
+
value_str = "<unknown>";
|
727
|
+
}
|
728
|
+
fields->emplace_back(absl::StrCat(" value { ", value_str, " }"));
|
729
|
+
}
|
730
|
+
fields->emplace_back(" }");
|
731
|
+
}
|
732
|
+
fields->emplace_back(" }");
|
733
|
+
}
|
734
|
+
// locality
|
735
|
+
const envoy_config_core_v3_Locality* locality =
|
736
|
+
envoy_config_core_v3_Node_locality(node);
|
737
|
+
if (locality != nullptr) {
|
738
|
+
fields->emplace_back(" locality {");
|
739
|
+
AddLocalityField(2, locality, fields);
|
740
|
+
fields->emplace_back(" }");
|
741
|
+
}
|
742
|
+
// build_version (doesn't exist in v3 proto; this is a horrible hack)
|
743
|
+
if (!build_version.empty()) {
|
744
|
+
fields->emplace_back(
|
745
|
+
absl::StrCat(" build_version: \"", build_version, "\""));
|
746
|
+
}
|
747
|
+
// user_agent_name
|
748
|
+
AddStringField(" user_agent_name",
|
749
|
+
envoy_config_core_v3_Node_user_agent_name(node), fields);
|
750
|
+
// user_agent_version
|
751
|
+
AddStringField(" user_agent_version",
|
752
|
+
envoy_config_core_v3_Node_user_agent_version(node), fields);
|
753
|
+
// client_features
|
754
|
+
size_t num_client_features;
|
755
|
+
const upb_strview* client_features =
|
756
|
+
envoy_config_core_v3_Node_client_features(node, &num_client_features);
|
757
|
+
for (size_t i = 0; i < num_client_features; ++i) {
|
758
|
+
AddStringField(" client_features", client_features[i], fields);
|
759
|
+
}
|
760
|
+
fields->emplace_back("}");
|
761
|
+
}
|
762
|
+
|
763
|
+
void MaybeLogDiscoveryRequest(
|
764
|
+
XdsClient* client, TraceFlag* tracer,
|
765
|
+
const envoy_service_discovery_v3_DiscoveryRequest* request,
|
766
|
+
const std::string& build_version) {
|
767
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
|
768
|
+
gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
|
769
|
+
// TODO(roth): When we can upgrade upb, use upb textformat code to dump
|
770
|
+
// the raw proto instead of doing this manually.
|
771
|
+
std::vector<std::string> fields;
|
772
|
+
// version_info
|
773
|
+
AddStringField(
|
774
|
+
"version_info",
|
775
|
+
envoy_service_discovery_v3_DiscoveryRequest_version_info(request),
|
776
|
+
&fields);
|
777
|
+
// node
|
778
|
+
const envoy_config_core_v3_Node* node =
|
779
|
+
envoy_service_discovery_v3_DiscoveryRequest_node(request);
|
780
|
+
if (node != nullptr) AddNodeLogFields(node, build_version, &fields);
|
781
|
+
// resource_names
|
782
|
+
size_t num_resource_names;
|
783
|
+
const upb_strview* resource_names =
|
784
|
+
envoy_service_discovery_v3_DiscoveryRequest_resource_names(
|
785
|
+
request, &num_resource_names);
|
786
|
+
for (size_t i = 0; i < num_resource_names; ++i) {
|
787
|
+
AddStringField("resource_names", resource_names[i], &fields);
|
788
|
+
}
|
789
|
+
// type_url
|
790
|
+
AddStringField(
|
791
|
+
"type_url",
|
792
|
+
envoy_service_discovery_v3_DiscoveryRequest_type_url(request), &fields);
|
793
|
+
// response_nonce
|
794
|
+
AddStringField(
|
795
|
+
"response_nonce",
|
796
|
+
envoy_service_discovery_v3_DiscoveryRequest_response_nonce(request),
|
797
|
+
&fields);
|
798
|
+
// error_detail
|
799
|
+
const struct google_rpc_Status* error_detail =
|
800
|
+
envoy_service_discovery_v3_DiscoveryRequest_error_detail(request);
|
801
|
+
if (error_detail != nullptr) {
|
802
|
+
fields.emplace_back("error_detail {");
|
803
|
+
// code
|
804
|
+
int32_t code = google_rpc_Status_code(error_detail);
|
805
|
+
if (code != 0) fields.emplace_back(absl::StrCat(" code: ", code));
|
806
|
+
// message
|
807
|
+
AddStringField(" message", google_rpc_Status_message(error_detail),
|
808
|
+
&fields);
|
809
|
+
fields.emplace_back("}");
|
810
|
+
}
|
811
|
+
gpr_log(GPR_DEBUG, "[xds_client %p] constructed ADS request: %s", client,
|
812
|
+
absl::StrJoin(fields, "\n").c_str());
|
813
|
+
}
|
814
|
+
}
|
815
|
+
|
816
|
+
grpc_slice SerializeDiscoveryRequest(
|
817
|
+
upb_arena* arena, envoy_service_discovery_v3_DiscoveryRequest* request) {
|
818
|
+
size_t output_length;
|
819
|
+
char* output = envoy_service_discovery_v3_DiscoveryRequest_serialize(
|
820
|
+
request, arena, &output_length);
|
821
|
+
return grpc_slice_from_copied_buffer(output, output_length);
|
822
|
+
}
|
823
|
+
|
824
|
+
absl::string_view TypeUrlExternalToInternal(bool use_v3,
|
825
|
+
const std::string& type_url) {
|
826
|
+
if (!use_v3) {
|
827
|
+
if (type_url == XdsApi::kLdsTypeUrl) {
|
828
|
+
return kLdsV2TypeUrl;
|
829
|
+
}
|
830
|
+
if (type_url == XdsApi::kRdsTypeUrl) {
|
831
|
+
return kRdsV2TypeUrl;
|
832
|
+
}
|
833
|
+
if (type_url == XdsApi::kCdsTypeUrl) {
|
834
|
+
return kCdsV2TypeUrl;
|
835
|
+
}
|
836
|
+
if (type_url == XdsApi::kEdsTypeUrl) {
|
837
|
+
return kEdsV2TypeUrl;
|
838
|
+
}
|
839
|
+
}
|
840
|
+
return type_url;
|
841
|
+
}
|
842
|
+
|
843
|
+
} // namespace
|
844
|
+
|
845
|
+
grpc_slice XdsApi::CreateAdsRequest(
|
846
|
+
const std::string& type_url,
|
847
|
+
const std::set<absl::string_view>& resource_names,
|
848
|
+
const std::string& version, const std::string& nonce, grpc_error* error,
|
849
|
+
bool populate_node) {
|
850
|
+
upb::Arena arena;
|
851
|
+
// Create a request.
|
852
|
+
envoy_service_discovery_v3_DiscoveryRequest* request =
|
853
|
+
envoy_service_discovery_v3_DiscoveryRequest_new(arena.ptr());
|
854
|
+
// Set type_url.
|
855
|
+
absl::string_view real_type_url =
|
856
|
+
TypeUrlExternalToInternal(use_v3_, type_url);
|
857
|
+
envoy_service_discovery_v3_DiscoveryRequest_set_type_url(
|
858
|
+
request, StdStringToUpbString(real_type_url));
|
859
|
+
// Set version_info.
|
860
|
+
if (!version.empty()) {
|
861
|
+
envoy_service_discovery_v3_DiscoveryRequest_set_version_info(
|
862
|
+
request, StdStringToUpbString(version));
|
863
|
+
}
|
864
|
+
// Set nonce.
|
865
|
+
if (!nonce.empty()) {
|
866
|
+
envoy_service_discovery_v3_DiscoveryRequest_set_response_nonce(
|
867
|
+
request, StdStringToUpbString(nonce));
|
868
|
+
}
|
869
|
+
// Set error_detail if it's a NACK.
|
870
|
+
if (error != GRPC_ERROR_NONE) {
|
871
|
+
grpc_slice error_description_slice;
|
872
|
+
GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION,
|
873
|
+
&error_description_slice));
|
874
|
+
upb_strview error_description_strview =
|
875
|
+
upb_strview_make(reinterpret_cast<const char*>(
|
876
|
+
GPR_SLICE_START_PTR(error_description_slice)),
|
877
|
+
GPR_SLICE_LENGTH(error_description_slice));
|
878
|
+
google_rpc_Status* error_detail =
|
879
|
+
envoy_service_discovery_v3_DiscoveryRequest_mutable_error_detail(
|
880
|
+
request, arena.ptr());
|
881
|
+
google_rpc_Status_set_message(error_detail, error_description_strview);
|
882
|
+
GRPC_ERROR_UNREF(error);
|
883
|
+
}
|
884
|
+
// Populate node.
|
885
|
+
if (populate_node) {
|
886
|
+
envoy_config_core_v3_Node* node_msg =
|
887
|
+
envoy_service_discovery_v3_DiscoveryRequest_mutable_node(request,
|
888
|
+
arena.ptr());
|
889
|
+
PopulateNode(arena.ptr(), bootstrap_, build_version_, user_agent_name_, "",
|
890
|
+
node_msg);
|
891
|
+
}
|
892
|
+
// Add resource_names.
|
893
|
+
for (const auto& resource_name : resource_names) {
|
894
|
+
envoy_service_discovery_v3_DiscoveryRequest_add_resource_names(
|
895
|
+
request, StdStringToUpbString(resource_name), arena.ptr());
|
896
|
+
}
|
897
|
+
MaybeLogDiscoveryRequest(client_, tracer_, request, build_version_);
|
898
|
+
return SerializeDiscoveryRequest(arena.ptr(), request);
|
899
|
+
}
|
900
|
+
|
901
|
+
namespace {
|
902
|
+
|
903
|
+
void MaybeLogDiscoveryResponse(
|
904
|
+
XdsClient* client, TraceFlag* tracer,
|
905
|
+
const envoy_service_discovery_v3_DiscoveryResponse* response) {
|
906
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
|
907
|
+
gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
|
908
|
+
// TODO(roth): When we can upgrade upb, use upb textformat code to dump
|
909
|
+
// the raw proto instead of doing this manually.
|
910
|
+
std::vector<std::string> fields;
|
911
|
+
// version_info
|
912
|
+
AddStringField(
|
913
|
+
"version_info",
|
914
|
+
envoy_service_discovery_v3_DiscoveryResponse_version_info(response),
|
915
|
+
&fields);
|
916
|
+
// resources
|
917
|
+
size_t num_resources;
|
918
|
+
envoy_service_discovery_v3_DiscoveryResponse_resources(response,
|
919
|
+
&num_resources);
|
920
|
+
fields.emplace_back(
|
921
|
+
absl::StrCat("resources: <", num_resources, " element(s)>"));
|
922
|
+
// type_url
|
923
|
+
AddStringField(
|
924
|
+
"type_url",
|
925
|
+
envoy_service_discovery_v3_DiscoveryResponse_type_url(response),
|
926
|
+
&fields);
|
927
|
+
// nonce
|
928
|
+
AddStringField("nonce",
|
929
|
+
envoy_service_discovery_v3_DiscoveryResponse_nonce(response),
|
930
|
+
&fields);
|
931
|
+
gpr_log(GPR_DEBUG, "[xds_client %p] received response: %s", client,
|
932
|
+
absl::StrJoin(fields, "\n").c_str());
|
933
|
+
}
|
934
|
+
}
|
935
|
+
|
936
|
+
void MaybeLogRouteConfiguration(
|
937
|
+
XdsClient* client, TraceFlag* tracer,
|
938
|
+
const envoy_config_route_v3_RouteConfiguration* route_config) {
|
939
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
|
940
|
+
gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
|
941
|
+
// TODO(roth): When we can upgrade upb, use upb textformat code to dump
|
942
|
+
// the raw proto instead of doing this manually.
|
943
|
+
std::vector<std::string> fields;
|
944
|
+
// name
|
945
|
+
AddStringField("name",
|
946
|
+
envoy_config_route_v3_RouteConfiguration_name(route_config),
|
947
|
+
&fields);
|
948
|
+
// virtual_hosts
|
949
|
+
size_t num_virtual_hosts;
|
950
|
+
const envoy_config_route_v3_VirtualHost* const* virtual_hosts =
|
951
|
+
envoy_config_route_v3_RouteConfiguration_virtual_hosts(
|
952
|
+
route_config, &num_virtual_hosts);
|
953
|
+
for (size_t i = 0; i < num_virtual_hosts; ++i) {
|
954
|
+
const auto* virtual_host = virtual_hosts[i];
|
955
|
+
fields.push_back("virtual_hosts {");
|
956
|
+
// name
|
957
|
+
AddStringField(" name",
|
958
|
+
envoy_config_route_v3_VirtualHost_name(virtual_host),
|
959
|
+
&fields);
|
960
|
+
// domains
|
961
|
+
size_t num_domains;
|
962
|
+
const upb_strview* const domains =
|
963
|
+
envoy_config_route_v3_VirtualHost_domains(virtual_host, &num_domains);
|
964
|
+
for (size_t j = 0; j < num_domains; ++j) {
|
965
|
+
AddStringField(" domains", domains[j], &fields);
|
966
|
+
}
|
967
|
+
// routes
|
968
|
+
size_t num_routes;
|
969
|
+
const envoy_config_route_v3_Route* const* routes =
|
970
|
+
envoy_config_route_v3_VirtualHost_routes(virtual_host, &num_routes);
|
971
|
+
for (size_t j = 0; j < num_routes; ++j) {
|
972
|
+
const auto* route = routes[j];
|
973
|
+
fields.push_back(" route {");
|
974
|
+
// name
|
975
|
+
AddStringField(" name", envoy_config_route_v3_Route_name(route),
|
976
|
+
&fields);
|
977
|
+
// match
|
978
|
+
const envoy_config_route_v3_RouteMatch* match =
|
979
|
+
envoy_config_route_v3_Route_match(route);
|
980
|
+
if (match != nullptr) {
|
981
|
+
fields.emplace_back(" match {");
|
982
|
+
// path matching
|
983
|
+
if (envoy_config_route_v3_RouteMatch_has_prefix(match)) {
|
984
|
+
AddStringField(" prefix",
|
985
|
+
envoy_config_route_v3_RouteMatch_prefix(match),
|
986
|
+
&fields,
|
987
|
+
/*add_if_empty=*/true);
|
988
|
+
} else if (envoy_config_route_v3_RouteMatch_has_path(match)) {
|
989
|
+
AddStringField(" path",
|
990
|
+
envoy_config_route_v3_RouteMatch_path(match),
|
991
|
+
&fields,
|
992
|
+
/*add_if_empty=*/true);
|
993
|
+
} else if (envoy_config_route_v3_RouteMatch_has_safe_regex(match)) {
|
994
|
+
fields.emplace_back(" safe_regex: <not printed>");
|
995
|
+
} else {
|
996
|
+
fields.emplace_back(" <unknown path matching type>");
|
997
|
+
}
|
998
|
+
// header matching
|
999
|
+
size_t num_headers;
|
1000
|
+
envoy_config_route_v3_RouteMatch_headers(match, &num_headers);
|
1001
|
+
if (num_headers > 0) {
|
1002
|
+
fields.emplace_back(
|
1003
|
+
absl::StrCat(" headers: <", num_headers, " element(s)>"));
|
1004
|
+
}
|
1005
|
+
fields.emplace_back(" }");
|
1006
|
+
}
|
1007
|
+
// action
|
1008
|
+
if (envoy_config_route_v3_Route_has_route(route)) {
|
1009
|
+
const envoy_config_route_v3_RouteAction* action =
|
1010
|
+
envoy_config_route_v3_Route_route(route);
|
1011
|
+
fields.emplace_back(" route {");
|
1012
|
+
if (envoy_config_route_v3_RouteAction_has_cluster(action)) {
|
1013
|
+
AddStringField(" cluster",
|
1014
|
+
envoy_config_route_v3_RouteAction_cluster(action),
|
1015
|
+
&fields);
|
1016
|
+
} else if (envoy_config_route_v3_RouteAction_has_cluster_header(
|
1017
|
+
action)) {
|
1018
|
+
AddStringField(
|
1019
|
+
" cluster_header",
|
1020
|
+
envoy_config_route_v3_RouteAction_cluster_header(action),
|
1021
|
+
&fields);
|
1022
|
+
} else if (envoy_config_route_v3_RouteAction_has_weighted_clusters(
|
1023
|
+
action)) {
|
1024
|
+
const envoy_config_route_v3_WeightedCluster* weighted_clusters =
|
1025
|
+
envoy_config_route_v3_RouteAction_weighted_clusters(action);
|
1026
|
+
fields.emplace_back(" weighted_clusters {");
|
1027
|
+
size_t num_cluster_weights;
|
1028
|
+
const envoy_config_route_v3_WeightedCluster_ClusterWeight* const*
|
1029
|
+
cluster_weights =
|
1030
|
+
envoy_config_route_v3_WeightedCluster_clusters(
|
1031
|
+
weighted_clusters, &num_cluster_weights);
|
1032
|
+
for (size_t i = 0; i < num_cluster_weights; ++i) {
|
1033
|
+
const envoy_config_route_v3_WeightedCluster_ClusterWeight*
|
1034
|
+
cluster_weight = cluster_weights[i];
|
1035
|
+
fields.emplace_back(" clusters {");
|
1036
|
+
AddStringField(
|
1037
|
+
" name",
|
1038
|
+
envoy_config_route_v3_WeightedCluster_ClusterWeight_name(
|
1039
|
+
cluster_weight),
|
1040
|
+
&fields);
|
1041
|
+
AddUInt32ValueField(
|
1042
|
+
" weight",
|
1043
|
+
envoy_config_route_v3_WeightedCluster_ClusterWeight_weight(
|
1044
|
+
cluster_weight),
|
1045
|
+
&fields);
|
1046
|
+
fields.emplace_back(" }");
|
1047
|
+
}
|
1048
|
+
AddUInt32ValueField(
|
1049
|
+
" total_weight",
|
1050
|
+
envoy_config_route_v3_WeightedCluster_total_weight(
|
1051
|
+
weighted_clusters),
|
1052
|
+
&fields);
|
1053
|
+
fields.emplace_back(" }");
|
1054
|
+
}
|
1055
|
+
fields.emplace_back(" }");
|
1056
|
+
} else if (envoy_config_route_v3_Route_has_redirect(route)) {
|
1057
|
+
fields.emplace_back(" redirect: <not printed>");
|
1058
|
+
} else if (envoy_config_route_v3_Route_has_direct_response(route)) {
|
1059
|
+
fields.emplace_back(" direct_response: <not printed>");
|
1060
|
+
} else if (envoy_config_route_v3_Route_has_filter_action(route)) {
|
1061
|
+
fields.emplace_back(" filter_action: <not printed>");
|
1062
|
+
}
|
1063
|
+
fields.push_back(" }");
|
1064
|
+
}
|
1065
|
+
fields.push_back("}");
|
1066
|
+
}
|
1067
|
+
gpr_log(GPR_DEBUG, "[xds_client %p] RouteConfiguration: %s", client,
|
1068
|
+
absl::StrJoin(fields, "\n").c_str());
|
1069
|
+
}
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
void MaybeLogCluster(XdsClient* client, TraceFlag* tracer,
|
1073
|
+
const envoy_config_cluster_v3_Cluster* cluster) {
|
1074
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
|
1075
|
+
gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
|
1076
|
+
// TODO(roth): When we can upgrade upb, use upb textformat code to dump
|
1077
|
+
// the raw proto instead of doing this manually.
|
1078
|
+
std::vector<std::string> fields;
|
1079
|
+
// name
|
1080
|
+
AddStringField("name", envoy_config_cluster_v3_Cluster_name(cluster),
|
1081
|
+
&fields);
|
1082
|
+
// type
|
1083
|
+
if (envoy_config_cluster_v3_Cluster_has_type(cluster)) {
|
1084
|
+
fields.emplace_back(absl::StrCat(
|
1085
|
+
"type: ", envoy_config_cluster_v3_Cluster_type(cluster)));
|
1086
|
+
} else if (envoy_config_cluster_v3_Cluster_has_cluster_type(cluster)) {
|
1087
|
+
fields.emplace_back("cluster_type: <not printed>");
|
1088
|
+
} else {
|
1089
|
+
fields.emplace_back("<unknown type>");
|
1090
|
+
}
|
1091
|
+
// eds_cluster_config
|
1092
|
+
const envoy_config_cluster_v3_Cluster_EdsClusterConfig* eds_cluster_config =
|
1093
|
+
envoy_config_cluster_v3_Cluster_eds_cluster_config(cluster);
|
1094
|
+
if (eds_cluster_config != nullptr) {
|
1095
|
+
fields.emplace_back("eds_cluster_config {");
|
1096
|
+
// eds_config
|
1097
|
+
const struct envoy_config_core_v3_ConfigSource* eds_config =
|
1098
|
+
envoy_config_cluster_v3_Cluster_EdsClusterConfig_eds_config(
|
1099
|
+
eds_cluster_config);
|
1100
|
+
if (eds_config != nullptr) {
|
1101
|
+
if (envoy_config_core_v3_ConfigSource_has_ads(eds_config)) {
|
1102
|
+
fields.emplace_back(" eds_config { ads {} }");
|
1103
|
+
} else {
|
1104
|
+
fields.emplace_back(" eds_config: <non-ADS type>");
|
1105
|
+
}
|
1106
|
+
}
|
1107
|
+
// service_name
|
1108
|
+
AddStringField(
|
1109
|
+
" service_name",
|
1110
|
+
envoy_config_cluster_v3_Cluster_EdsClusterConfig_service_name(
|
1111
|
+
eds_cluster_config),
|
1112
|
+
&fields);
|
1113
|
+
fields.emplace_back("}");
|
1114
|
+
}
|
1115
|
+
// lb_policy
|
1116
|
+
fields.emplace_back(absl::StrCat(
|
1117
|
+
"lb_policy: ", envoy_config_cluster_v3_Cluster_lb_policy(cluster)));
|
1118
|
+
// lrs_server
|
1119
|
+
const envoy_config_core_v3_ConfigSource* lrs_server =
|
1120
|
+
envoy_config_cluster_v3_Cluster_lrs_server(cluster);
|
1121
|
+
if (lrs_server != nullptr) {
|
1122
|
+
if (envoy_config_core_v3_ConfigSource_has_self(lrs_server)) {
|
1123
|
+
fields.emplace_back("lrs_server { self {} }");
|
1124
|
+
} else {
|
1125
|
+
fields.emplace_back("lrs_server: <non-self type>");
|
1126
|
+
}
|
1127
|
+
}
|
1128
|
+
gpr_log(GPR_DEBUG, "[xds_client %p] Cluster: %s", client,
|
1129
|
+
absl::StrJoin(fields, "\n").c_str());
|
1130
|
+
}
|
1131
|
+
}
|
1132
|
+
|
1133
|
+
void MaybeLogClusterLoadAssignment(
|
1134
|
+
XdsClient* client, TraceFlag* tracer,
|
1135
|
+
const envoy_config_endpoint_v3_ClusterLoadAssignment* cla) {
|
1136
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
|
1137
|
+
gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
|
1138
|
+
// TODO(roth): When we can upgrade upb, use upb textformat code to dump
|
1139
|
+
// the raw proto instead of doing this manually.
|
1140
|
+
std::vector<std::string> fields;
|
1141
|
+
// cluster_name
|
1142
|
+
AddStringField(
|
1143
|
+
"cluster_name",
|
1144
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_cluster_name(cla),
|
1145
|
+
&fields);
|
1146
|
+
// endpoints
|
1147
|
+
size_t num_localities;
|
1148
|
+
const struct envoy_config_endpoint_v3_LocalityLbEndpoints* const*
|
1149
|
+
locality_endpoints =
|
1150
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_endpoints(
|
1151
|
+
cla, &num_localities);
|
1152
|
+
for (size_t i = 0; i < num_localities; ++i) {
|
1153
|
+
const auto* locality_endpoint = locality_endpoints[i];
|
1154
|
+
fields.emplace_back("endpoints {");
|
1155
|
+
// locality
|
1156
|
+
const auto* locality =
|
1157
|
+
envoy_config_endpoint_v3_LocalityLbEndpoints_locality(
|
1158
|
+
locality_endpoint);
|
1159
|
+
if (locality != nullptr) {
|
1160
|
+
fields.emplace_back(" locality {");
|
1161
|
+
AddLocalityField(2, locality, &fields);
|
1162
|
+
fields.emplace_back(" }");
|
1163
|
+
}
|
1164
|
+
// lb_endpoints
|
1165
|
+
size_t num_lb_endpoints;
|
1166
|
+
const envoy_config_endpoint_v3_LbEndpoint* const* lb_endpoints =
|
1167
|
+
envoy_config_endpoint_v3_LocalityLbEndpoints_lb_endpoints(
|
1168
|
+
locality_endpoint, &num_lb_endpoints);
|
1169
|
+
for (size_t j = 0; j < num_lb_endpoints; ++j) {
|
1170
|
+
const auto* lb_endpoint = lb_endpoints[j];
|
1171
|
+
fields.emplace_back(" lb_endpoints {");
|
1172
|
+
// health_status
|
1173
|
+
uint32_t health_status =
|
1174
|
+
envoy_config_endpoint_v3_LbEndpoint_health_status(lb_endpoint);
|
1175
|
+
if (health_status > 0) {
|
1176
|
+
fields.emplace_back(
|
1177
|
+
absl::StrCat(" health_status: ", health_status));
|
1178
|
+
}
|
1179
|
+
// endpoint
|
1180
|
+
const envoy_config_endpoint_v3_Endpoint* endpoint =
|
1181
|
+
envoy_config_endpoint_v3_LbEndpoint_endpoint(lb_endpoint);
|
1182
|
+
if (endpoint != nullptr) {
|
1183
|
+
fields.emplace_back(" endpoint {");
|
1184
|
+
// address
|
1185
|
+
const auto* address =
|
1186
|
+
envoy_config_endpoint_v3_Endpoint_address(endpoint);
|
1187
|
+
if (address != nullptr) {
|
1188
|
+
fields.emplace_back(" address {");
|
1189
|
+
// socket_address
|
1190
|
+
const auto* socket_address =
|
1191
|
+
envoy_config_core_v3_Address_socket_address(address);
|
1192
|
+
if (socket_address != nullptr) {
|
1193
|
+
fields.emplace_back(" socket_address {");
|
1194
|
+
// address
|
1195
|
+
AddStringField(
|
1196
|
+
" address",
|
1197
|
+
envoy_config_core_v3_SocketAddress_address(socket_address),
|
1198
|
+
&fields);
|
1199
|
+
// port_value
|
1200
|
+
if (envoy_config_core_v3_SocketAddress_has_port_value(
|
1201
|
+
socket_address)) {
|
1202
|
+
fields.emplace_back(
|
1203
|
+
absl::StrCat(" port_value: ",
|
1204
|
+
envoy_config_core_v3_SocketAddress_port_value(
|
1205
|
+
socket_address)));
|
1206
|
+
} else {
|
1207
|
+
fields.emplace_back(" <non-numeric port>");
|
1208
|
+
}
|
1209
|
+
fields.emplace_back(" }");
|
1210
|
+
} else {
|
1211
|
+
fields.emplace_back(" <non-socket address>");
|
1212
|
+
}
|
1213
|
+
fields.emplace_back(" }");
|
1214
|
+
}
|
1215
|
+
fields.emplace_back(" }");
|
1216
|
+
}
|
1217
|
+
fields.emplace_back(" }");
|
1218
|
+
}
|
1219
|
+
// load_balancing_weight
|
1220
|
+
AddUInt32ValueField(
|
1221
|
+
" load_balancing_weight",
|
1222
|
+
envoy_config_endpoint_v3_LocalityLbEndpoints_load_balancing_weight(
|
1223
|
+
locality_endpoint),
|
1224
|
+
&fields);
|
1225
|
+
// priority
|
1226
|
+
uint32_t priority = envoy_config_endpoint_v3_LocalityLbEndpoints_priority(
|
1227
|
+
locality_endpoint);
|
1228
|
+
if (priority > 0) {
|
1229
|
+
fields.emplace_back(absl::StrCat(" priority: ", priority));
|
1230
|
+
}
|
1231
|
+
fields.emplace_back("}");
|
1232
|
+
}
|
1233
|
+
// policy
|
1234
|
+
const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy* policy =
|
1235
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_policy(cla);
|
1236
|
+
if (policy != nullptr) {
|
1237
|
+
fields.emplace_back("policy {");
|
1238
|
+
// drop_overloads
|
1239
|
+
size_t num_drop_overloads;
|
1240
|
+
const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload* const*
|
1241
|
+
drop_overloads =
|
1242
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_drop_overloads(
|
1243
|
+
policy, &num_drop_overloads);
|
1244
|
+
for (size_t i = 0; i < num_drop_overloads; ++i) {
|
1245
|
+
auto* drop_overload = drop_overloads[i];
|
1246
|
+
fields.emplace_back(" drop_overloads {");
|
1247
|
+
// category
|
1248
|
+
AddStringField(
|
1249
|
+
" category",
|
1250
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category(
|
1251
|
+
drop_overload),
|
1252
|
+
&fields);
|
1253
|
+
// drop_percentage
|
1254
|
+
const auto* drop_percentage =
|
1255
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_drop_percentage(
|
1256
|
+
drop_overload);
|
1257
|
+
if (drop_percentage != nullptr) {
|
1258
|
+
fields.emplace_back(" drop_percentage {");
|
1259
|
+
fields.emplace_back(absl::StrCat(
|
1260
|
+
" numerator: ",
|
1261
|
+
envoy_type_v3_FractionalPercent_numerator(drop_percentage)));
|
1262
|
+
fields.emplace_back(absl::StrCat(
|
1263
|
+
" denominator: ",
|
1264
|
+
envoy_type_v3_FractionalPercent_denominator(drop_percentage)));
|
1265
|
+
fields.emplace_back(" }");
|
1266
|
+
}
|
1267
|
+
fields.emplace_back(" }");
|
1268
|
+
}
|
1269
|
+
// overprovisioning_factor
|
1270
|
+
fields.emplace_back("}");
|
1271
|
+
}
|
1272
|
+
gpr_log(GPR_DEBUG, "[xds_client %p] ClusterLoadAssignment: %s", client,
|
1273
|
+
absl::StrJoin(fields, "\n").c_str());
|
1274
|
+
}
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
grpc_error* RoutePathMatchParse(const envoy_config_route_v3_RouteMatch* match,
|
1278
|
+
XdsApi::Route* route, bool* ignore_route) {
|
1279
|
+
if (envoy_config_route_v3_RouteMatch_has_prefix(match)) {
|
1280
|
+
absl::string_view prefix =
|
1281
|
+
UpbStringToAbsl(envoy_config_route_v3_RouteMatch_prefix(match));
|
1282
|
+
// Empty prefix "" is accepted.
|
1283
|
+
if (prefix.size() > 0) {
|
1284
|
+
// Prefix "/" is accepted.
|
1285
|
+
if (prefix[0] != '/') {
|
1286
|
+
// Prefix which does not start with a / will never match anything, so
|
1287
|
+
// ignore this route.
|
1288
|
+
*ignore_route = true;
|
1289
|
+
return GRPC_ERROR_NONE;
|
1290
|
+
}
|
1291
|
+
std::vector<absl::string_view> prefix_elements =
|
1292
|
+
absl::StrSplit(prefix.substr(1), absl::MaxSplits('/', 2));
|
1293
|
+
if (prefix_elements.size() > 2) {
|
1294
|
+
// Prefix cannot have more than 2 slashes.
|
1295
|
+
*ignore_route = true;
|
1296
|
+
return GRPC_ERROR_NONE;
|
1297
|
+
} else if (prefix_elements.size() == 2 && prefix_elements[0].empty()) {
|
1298
|
+
// Prefix contains empty string between the 2 slashes
|
1299
|
+
*ignore_route = true;
|
1300
|
+
return GRPC_ERROR_NONE;
|
1301
|
+
}
|
1302
|
+
}
|
1303
|
+
route->matchers.path_matcher.type =
|
1304
|
+
XdsApi::Route::Matchers::PathMatcher::PathMatcherType::PREFIX;
|
1305
|
+
route->matchers.path_matcher.string_matcher = std::string(prefix);
|
1306
|
+
} else if (envoy_config_route_v3_RouteMatch_has_path(match)) {
|
1307
|
+
absl::string_view path =
|
1308
|
+
UpbStringToAbsl(envoy_config_route_v3_RouteMatch_path(match));
|
1309
|
+
if (path.size() == 0) {
|
1310
|
+
// Path that is empty will never match anything, so ignore this route.
|
1311
|
+
*ignore_route = true;
|
1312
|
+
return GRPC_ERROR_NONE;
|
1313
|
+
}
|
1314
|
+
if (path[0] != '/') {
|
1315
|
+
// Path which does not start with a / will never match anything, so
|
1316
|
+
// ignore this route.
|
1317
|
+
*ignore_route = true;
|
1318
|
+
return GRPC_ERROR_NONE;
|
1319
|
+
}
|
1320
|
+
std::vector<absl::string_view> path_elements =
|
1321
|
+
absl::StrSplit(path.substr(1), absl::MaxSplits('/', 2));
|
1322
|
+
if (path_elements.size() != 2) {
|
1323
|
+
// Path not in the required format of /service/method will never match
|
1324
|
+
// anything, so ignore this route.
|
1325
|
+
*ignore_route = true;
|
1326
|
+
return GRPC_ERROR_NONE;
|
1327
|
+
} else if (path_elements[0].empty()) {
|
1328
|
+
// Path contains empty service name will never match anything, so ignore
|
1329
|
+
// this route.
|
1330
|
+
*ignore_route = true;
|
1331
|
+
return GRPC_ERROR_NONE;
|
1332
|
+
} else if (path_elements[1].empty()) {
|
1333
|
+
// Path contains empty method name will never match anything, so ignore
|
1334
|
+
// this route.
|
1335
|
+
*ignore_route = true;
|
1336
|
+
return GRPC_ERROR_NONE;
|
1337
|
+
}
|
1338
|
+
route->matchers.path_matcher.type =
|
1339
|
+
XdsApi::Route::Matchers::PathMatcher::PathMatcherType::PATH;
|
1340
|
+
route->matchers.path_matcher.string_matcher = std::string(path);
|
1341
|
+
} else if (envoy_config_route_v3_RouteMatch_has_safe_regex(match)) {
|
1342
|
+
const envoy_type_matcher_v3_RegexMatcher* regex_matcher =
|
1343
|
+
envoy_config_route_v3_RouteMatch_safe_regex(match);
|
1344
|
+
GPR_ASSERT(regex_matcher != nullptr);
|
1345
|
+
std::string matcher = UpbStringToStdString(
|
1346
|
+
envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher));
|
1347
|
+
std::unique_ptr<RE2> regex = absl::make_unique<RE2>(std::move(matcher));
|
1348
|
+
if (!regex->ok()) {
|
1349
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1350
|
+
"Invalid regex string specified in path matcher.");
|
1351
|
+
}
|
1352
|
+
route->matchers.path_matcher.type =
|
1353
|
+
XdsApi::Route::Matchers::PathMatcher::PathMatcherType::REGEX;
|
1354
|
+
route->matchers.path_matcher.regex_matcher = std::move(regex);
|
1355
|
+
} else {
|
1356
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1357
|
+
"Invalid route path specifier specified.");
|
1358
|
+
}
|
1359
|
+
return GRPC_ERROR_NONE;
|
1360
|
+
}
|
1361
|
+
|
1362
|
+
grpc_error* RouteHeaderMatchersParse(
|
1363
|
+
const envoy_config_route_v3_RouteMatch* match, XdsApi::Route* route) {
|
1364
|
+
size_t size;
|
1365
|
+
const envoy_config_route_v3_HeaderMatcher* const* headers =
|
1366
|
+
envoy_config_route_v3_RouteMatch_headers(match, &size);
|
1367
|
+
for (size_t i = 0; i < size; ++i) {
|
1368
|
+
const envoy_config_route_v3_HeaderMatcher* header = headers[i];
|
1369
|
+
XdsApi::Route::Matchers::HeaderMatcher header_matcher;
|
1370
|
+
header_matcher.name =
|
1371
|
+
UpbStringToStdString(envoy_config_route_v3_HeaderMatcher_name(header));
|
1372
|
+
if (envoy_config_route_v3_HeaderMatcher_has_exact_match(header)) {
|
1373
|
+
header_matcher.type =
|
1374
|
+
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::EXACT;
|
1375
|
+
header_matcher.string_matcher = UpbStringToStdString(
|
1376
|
+
envoy_config_route_v3_HeaderMatcher_exact_match(header));
|
1377
|
+
} else if (envoy_config_route_v3_HeaderMatcher_has_safe_regex_match(
|
1378
|
+
header)) {
|
1379
|
+
const envoy_type_matcher_v3_RegexMatcher* regex_matcher =
|
1380
|
+
envoy_config_route_v3_HeaderMatcher_safe_regex_match(header);
|
1381
|
+
GPR_ASSERT(regex_matcher != nullptr);
|
1382
|
+
const std::string matcher = UpbStringToStdString(
|
1383
|
+
envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher));
|
1384
|
+
std::unique_ptr<RE2> regex = absl::make_unique<RE2>(matcher);
|
1385
|
+
if (!regex->ok()) {
|
1386
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1387
|
+
"Invalid regex string specified in header matcher.");
|
1388
|
+
}
|
1389
|
+
header_matcher.type =
|
1390
|
+
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::REGEX;
|
1391
|
+
header_matcher.regex_match = std::move(regex);
|
1392
|
+
} else if (envoy_config_route_v3_HeaderMatcher_has_range_match(header)) {
|
1393
|
+
header_matcher.type =
|
1394
|
+
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::RANGE;
|
1395
|
+
const envoy_type_v3_Int64Range* range_matcher =
|
1396
|
+
envoy_config_route_v3_HeaderMatcher_range_match(header);
|
1397
|
+
header_matcher.range_start =
|
1398
|
+
envoy_type_v3_Int64Range_start(range_matcher);
|
1399
|
+
header_matcher.range_end = envoy_type_v3_Int64Range_end(range_matcher);
|
1400
|
+
if (header_matcher.range_end < header_matcher.range_start) {
|
1401
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1402
|
+
"Invalid range header matcher specifier specified: end "
|
1403
|
+
"cannot be smaller than start.");
|
1404
|
+
}
|
1405
|
+
} else if (envoy_config_route_v3_HeaderMatcher_has_present_match(header)) {
|
1406
|
+
header_matcher.type =
|
1407
|
+
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::PRESENT;
|
1408
|
+
header_matcher.present_match =
|
1409
|
+
envoy_config_route_v3_HeaderMatcher_present_match(header);
|
1410
|
+
} else if (envoy_config_route_v3_HeaderMatcher_has_prefix_match(header)) {
|
1411
|
+
header_matcher.type =
|
1412
|
+
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::PREFIX;
|
1413
|
+
header_matcher.string_matcher = UpbStringToStdString(
|
1414
|
+
envoy_config_route_v3_HeaderMatcher_prefix_match(header));
|
1415
|
+
} else if (envoy_config_route_v3_HeaderMatcher_has_suffix_match(header)) {
|
1416
|
+
header_matcher.type =
|
1417
|
+
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::SUFFIX;
|
1418
|
+
header_matcher.string_matcher = UpbStringToStdString(
|
1419
|
+
envoy_config_route_v3_HeaderMatcher_suffix_match(header));
|
1420
|
+
} else {
|
1421
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1422
|
+
"Invalid route header matcher specified.");
|
1423
|
+
}
|
1424
|
+
header_matcher.invert_match =
|
1425
|
+
envoy_config_route_v3_HeaderMatcher_invert_match(header);
|
1426
|
+
route->matchers.header_matchers.emplace_back(std::move(header_matcher));
|
1427
|
+
}
|
1428
|
+
return GRPC_ERROR_NONE;
|
1429
|
+
}
|
1430
|
+
|
1431
|
+
grpc_error* RouteRuntimeFractionParse(
|
1432
|
+
const envoy_config_route_v3_RouteMatch* match, XdsApi::Route* route) {
|
1433
|
+
const envoy_config_core_v3_RuntimeFractionalPercent* runtime_fraction =
|
1434
|
+
envoy_config_route_v3_RouteMatch_runtime_fraction(match);
|
1435
|
+
if (runtime_fraction != nullptr) {
|
1436
|
+
const envoy_type_v3_FractionalPercent* fraction =
|
1437
|
+
envoy_config_core_v3_RuntimeFractionalPercent_default_value(
|
1438
|
+
runtime_fraction);
|
1439
|
+
if (fraction != nullptr) {
|
1440
|
+
uint32_t numerator = envoy_type_v3_FractionalPercent_numerator(fraction);
|
1441
|
+
const auto denominator =
|
1442
|
+
static_cast<envoy_type_v3_FractionalPercent_DenominatorType>(
|
1443
|
+
envoy_type_v3_FractionalPercent_denominator(fraction));
|
1444
|
+
// Normalize to million.
|
1445
|
+
switch (denominator) {
|
1446
|
+
case envoy_type_v3_FractionalPercent_HUNDRED:
|
1447
|
+
numerator *= 10000;
|
1448
|
+
break;
|
1449
|
+
case envoy_type_v3_FractionalPercent_TEN_THOUSAND:
|
1450
|
+
numerator *= 100;
|
1451
|
+
break;
|
1452
|
+
case envoy_type_v3_FractionalPercent_MILLION:
|
1453
|
+
break;
|
1454
|
+
default:
|
1455
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1456
|
+
"Unknown denominator type");
|
1457
|
+
}
|
1458
|
+
route->matchers.fraction_per_million = numerator;
|
1459
|
+
}
|
1460
|
+
}
|
1461
|
+
return GRPC_ERROR_NONE;
|
1462
|
+
}
|
1463
|
+
|
1464
|
+
grpc_error* RouteActionParse(const envoy_config_route_v3_Route* route_msg,
|
1465
|
+
XdsApi::Route* route, bool* ignore_route) {
|
1466
|
+
if (!envoy_config_route_v3_Route_has_route(route_msg)) {
|
1467
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1468
|
+
"No RouteAction found in route.");
|
1469
|
+
}
|
1470
|
+
const envoy_config_route_v3_RouteAction* route_action =
|
1471
|
+
envoy_config_route_v3_Route_route(route_msg);
|
1472
|
+
// Get the cluster or weighted_clusters in the RouteAction.
|
1473
|
+
if (envoy_config_route_v3_RouteAction_has_cluster(route_action)) {
|
1474
|
+
route->cluster_name = UpbStringToStdString(
|
1475
|
+
envoy_config_route_v3_RouteAction_cluster(route_action));
|
1476
|
+
if (route->cluster_name.size() == 0) {
|
1477
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1478
|
+
"RouteAction cluster contains empty cluster name.");
|
1479
|
+
}
|
1480
|
+
} else if (envoy_config_route_v3_RouteAction_has_weighted_clusters(
|
1481
|
+
route_action)) {
|
1482
|
+
const envoy_config_route_v3_WeightedCluster* weighted_cluster =
|
1483
|
+
envoy_config_route_v3_RouteAction_weighted_clusters(route_action);
|
1484
|
+
uint32_t total_weight = 100;
|
1485
|
+
const google_protobuf_UInt32Value* weight =
|
1486
|
+
envoy_config_route_v3_WeightedCluster_total_weight(weighted_cluster);
|
1487
|
+
if (weight != nullptr) {
|
1488
|
+
total_weight = google_protobuf_UInt32Value_value(weight);
|
1489
|
+
}
|
1490
|
+
size_t clusters_size;
|
1491
|
+
const envoy_config_route_v3_WeightedCluster_ClusterWeight* const* clusters =
|
1492
|
+
envoy_config_route_v3_WeightedCluster_clusters(weighted_cluster,
|
1493
|
+
&clusters_size);
|
1494
|
+
uint32_t sum_of_weights = 0;
|
1495
|
+
for (size_t j = 0; j < clusters_size; ++j) {
|
1496
|
+
const envoy_config_route_v3_WeightedCluster_ClusterWeight*
|
1497
|
+
cluster_weight = clusters[j];
|
1498
|
+
XdsApi::Route::ClusterWeight cluster;
|
1499
|
+
cluster.name = UpbStringToStdString(
|
1500
|
+
envoy_config_route_v3_WeightedCluster_ClusterWeight_name(
|
1501
|
+
cluster_weight));
|
1502
|
+
if (cluster.name.empty()) {
|
1503
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1504
|
+
"RouteAction weighted_cluster cluster contains empty cluster "
|
1505
|
+
"name.");
|
1506
|
+
}
|
1507
|
+
const google_protobuf_UInt32Value* weight =
|
1508
|
+
envoy_config_route_v3_WeightedCluster_ClusterWeight_weight(
|
1509
|
+
cluster_weight);
|
1510
|
+
if (weight == nullptr) {
|
1511
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1512
|
+
"RouteAction weighted_cluster cluster missing weight");
|
1513
|
+
}
|
1514
|
+
cluster.weight = google_protobuf_UInt32Value_value(weight);
|
1515
|
+
sum_of_weights += cluster.weight;
|
1516
|
+
route->weighted_clusters.emplace_back(std::move(cluster));
|
1517
|
+
}
|
1518
|
+
if (total_weight != sum_of_weights) {
|
1519
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1520
|
+
"RouteAction weighted_cluster has incorrect total weight");
|
1521
|
+
}
|
1522
|
+
if (route->weighted_clusters.empty()) {
|
1523
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1524
|
+
"RouteAction weighted_cluster has no valid clusters specified.");
|
1525
|
+
}
|
1526
|
+
} else {
|
1527
|
+
// No cluster or weighted_clusters found in RouteAction, ignore this route.
|
1528
|
+
*ignore_route = true;
|
1529
|
+
return GRPC_ERROR_NONE;
|
1530
|
+
}
|
1531
|
+
return GRPC_ERROR_NONE;
|
1532
|
+
}
|
1533
|
+
|
1534
|
+
grpc_error* RouteConfigParse(
|
1535
|
+
XdsClient* client, TraceFlag* tracer,
|
1536
|
+
const envoy_config_route_v3_RouteConfiguration* route_config,
|
1537
|
+
XdsApi::RdsUpdate* rds_update) {
|
1538
|
+
MaybeLogRouteConfiguration(client, tracer, route_config);
|
1539
|
+
// Get the virtual hosts.
|
1540
|
+
size_t size;
|
1541
|
+
const envoy_config_route_v3_VirtualHost* const* virtual_hosts =
|
1542
|
+
envoy_config_route_v3_RouteConfiguration_virtual_hosts(route_config,
|
1543
|
+
&size);
|
1544
|
+
for (size_t i = 0; i < size; ++i) {
|
1545
|
+
rds_update->virtual_hosts.emplace_back();
|
1546
|
+
XdsApi::RdsUpdate::VirtualHost& vhost = rds_update->virtual_hosts.back();
|
1547
|
+
// Parse domains.
|
1548
|
+
size_t domain_size;
|
1549
|
+
upb_strview const* domains = envoy_config_route_v3_VirtualHost_domains(
|
1550
|
+
virtual_hosts[i], &domain_size);
|
1551
|
+
for (size_t j = 0; j < domain_size; ++j) {
|
1552
|
+
std::string domain_pattern = UpbStringToStdString(domains[j]);
|
1553
|
+
const MatchType match_type = DomainPatternMatchType(domain_pattern);
|
1554
|
+
if (match_type == INVALID_MATCH) {
|
1555
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid domain pattern.");
|
1556
|
+
}
|
1557
|
+
vhost.domains.emplace_back(std::move(domain_pattern));
|
1558
|
+
}
|
1559
|
+
if (vhost.domains.empty()) {
|
1560
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("VirtualHost has no domains");
|
1561
|
+
}
|
1562
|
+
// Parse routes.
|
1563
|
+
size_t num_routes;
|
1564
|
+
const envoy_config_route_v3_Route* const* routes =
|
1565
|
+
envoy_config_route_v3_VirtualHost_routes(virtual_hosts[i], &num_routes);
|
1566
|
+
if (num_routes < 1) {
|
1567
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1568
|
+
"No route found in the virtual host.");
|
1569
|
+
}
|
1570
|
+
// Loop over the whole list of routes
|
1571
|
+
for (size_t j = 0; j < num_routes; ++j) {
|
1572
|
+
const envoy_config_route_v3_RouteMatch* match =
|
1573
|
+
envoy_config_route_v3_Route_match(routes[j]);
|
1574
|
+
size_t query_parameters_size;
|
1575
|
+
static_cast<void>(envoy_config_route_v3_RouteMatch_query_parameters(
|
1576
|
+
match, &query_parameters_size));
|
1577
|
+
if (query_parameters_size > 0) {
|
1578
|
+
continue;
|
1579
|
+
}
|
1580
|
+
XdsApi::Route route;
|
1581
|
+
bool ignore_route = false;
|
1582
|
+
grpc_error* error = RoutePathMatchParse(match, &route, &ignore_route);
|
1583
|
+
if (error != GRPC_ERROR_NONE) return error;
|
1584
|
+
if (ignore_route) continue;
|
1585
|
+
error = RouteHeaderMatchersParse(match, &route);
|
1586
|
+
if (error != GRPC_ERROR_NONE) return error;
|
1587
|
+
error = RouteRuntimeFractionParse(match, &route);
|
1588
|
+
if (error != GRPC_ERROR_NONE) return error;
|
1589
|
+
error = RouteActionParse(routes[j], &route, &ignore_route);
|
1590
|
+
if (error != GRPC_ERROR_NONE) return error;
|
1591
|
+
if (ignore_route) continue;
|
1592
|
+
const google_protobuf_BoolValue* case_sensitive =
|
1593
|
+
envoy_config_route_v3_RouteMatch_case_sensitive(match);
|
1594
|
+
if (case_sensitive != nullptr &&
|
1595
|
+
!google_protobuf_BoolValue_value(case_sensitive)) {
|
1596
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1597
|
+
"case_sensitive if set must be set to true.");
|
1598
|
+
}
|
1599
|
+
vhost.routes.emplace_back(std::move(route));
|
1600
|
+
}
|
1601
|
+
if (vhost.routes.empty()) {
|
1602
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No valid routes specified.");
|
1603
|
+
}
|
1604
|
+
}
|
1605
|
+
return GRPC_ERROR_NONE;
|
1606
|
+
}
|
1607
|
+
|
1608
|
+
grpc_error* LdsResponseParse(
|
1609
|
+
XdsClient* client, TraceFlag* tracer,
|
1610
|
+
const envoy_service_discovery_v3_DiscoveryResponse* response,
|
1611
|
+
const std::string& expected_server_name,
|
1612
|
+
absl::optional<XdsApi::LdsUpdate>* lds_update, upb_arena* arena) {
|
1613
|
+
// Get the resources from the response.
|
1614
|
+
size_t size;
|
1615
|
+
const google_protobuf_Any* const* resources =
|
1616
|
+
envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
|
1617
|
+
for (size_t i = 0; i < size; ++i) {
|
1618
|
+
// Check the type_url of the resource.
|
1619
|
+
absl::string_view type_url =
|
1620
|
+
UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
|
1621
|
+
if (!IsLds(type_url)) {
|
1622
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not LDS.");
|
1623
|
+
}
|
1624
|
+
// Decode the listener.
|
1625
|
+
const upb_strview encoded_listener =
|
1626
|
+
google_protobuf_Any_value(resources[i]);
|
1627
|
+
const envoy_config_listener_v3_Listener* listener =
|
1628
|
+
envoy_config_listener_v3_Listener_parse(encoded_listener.data,
|
1629
|
+
encoded_listener.size, arena);
|
1630
|
+
if (listener == nullptr) {
|
1631
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode listener.");
|
1632
|
+
}
|
1633
|
+
// Check listener name. Ignore unexpected listeners.
|
1634
|
+
absl::string_view name =
|
1635
|
+
UpbStringToAbsl(envoy_config_listener_v3_Listener_name(listener));
|
1636
|
+
if (name != expected_server_name) continue;
|
1637
|
+
// Get api_listener and decode it to http_connection_manager.
|
1638
|
+
const envoy_config_listener_v3_ApiListener* api_listener =
|
1639
|
+
envoy_config_listener_v3_Listener_api_listener(listener);
|
1640
|
+
if (api_listener == nullptr) {
|
1641
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1642
|
+
"Listener has no ApiListener.");
|
1643
|
+
}
|
1644
|
+
const upb_strview encoded_api_listener = google_protobuf_Any_value(
|
1645
|
+
envoy_config_listener_v3_ApiListener_api_listener(api_listener));
|
1646
|
+
const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
|
1647
|
+
http_connection_manager =
|
1648
|
+
envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
|
1649
|
+
encoded_api_listener.data, encoded_api_listener.size, arena);
|
1650
|
+
if (http_connection_manager == nullptr) {
|
1651
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1652
|
+
"Could not parse HttpConnectionManager config from ApiListener");
|
1653
|
+
}
|
1654
|
+
// Found inlined route_config. Parse it to find the cluster_name.
|
1655
|
+
if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_route_config(
|
1656
|
+
http_connection_manager)) {
|
1657
|
+
const envoy_config_route_v3_RouteConfiguration* route_config =
|
1658
|
+
envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_route_config(
|
1659
|
+
http_connection_manager);
|
1660
|
+
XdsApi::RdsUpdate rds_update;
|
1661
|
+
grpc_error* error =
|
1662
|
+
RouteConfigParse(client, tracer, route_config, &rds_update);
|
1663
|
+
if (error != GRPC_ERROR_NONE) return error;
|
1664
|
+
lds_update->emplace();
|
1665
|
+
(*lds_update)->rds_update = std::move(rds_update);
|
1666
|
+
return GRPC_ERROR_NONE;
|
1667
|
+
}
|
1668
|
+
// Validate that RDS must be used to get the route_config dynamically.
|
1669
|
+
if (!envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_rds(
|
1670
|
+
http_connection_manager)) {
|
1671
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1672
|
+
"HttpConnectionManager neither has inlined route_config nor RDS.");
|
1673
|
+
}
|
1674
|
+
const envoy_extensions_filters_network_http_connection_manager_v3_Rds* rds =
|
1675
|
+
envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_rds(
|
1676
|
+
http_connection_manager);
|
1677
|
+
// Check that the ConfigSource specifies ADS.
|
1678
|
+
const envoy_config_core_v3_ConfigSource* config_source =
|
1679
|
+
envoy_extensions_filters_network_http_connection_manager_v3_Rds_config_source(
|
1680
|
+
rds);
|
1681
|
+
if (config_source == nullptr) {
|
1682
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1683
|
+
"HttpConnectionManager missing config_source for RDS.");
|
1684
|
+
}
|
1685
|
+
if (!envoy_config_core_v3_ConfigSource_has_ads(config_source)) {
|
1686
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1687
|
+
"HttpConnectionManager ConfigSource for RDS does not specify ADS.");
|
1688
|
+
}
|
1689
|
+
// Get the route_config_name.
|
1690
|
+
lds_update->emplace();
|
1691
|
+
(*lds_update)->route_config_name = UpbStringToStdString(
|
1692
|
+
envoy_extensions_filters_network_http_connection_manager_v3_Rds_route_config_name(
|
1693
|
+
rds));
|
1694
|
+
return GRPC_ERROR_NONE;
|
1695
|
+
}
|
1696
|
+
return GRPC_ERROR_NONE;
|
1697
|
+
}
|
1698
|
+
|
1699
|
+
grpc_error* RdsResponseParse(
|
1700
|
+
XdsClient* client, TraceFlag* tracer,
|
1701
|
+
const envoy_service_discovery_v3_DiscoveryResponse* response,
|
1702
|
+
const std::set<absl::string_view>& expected_route_configuration_names,
|
1703
|
+
absl::optional<XdsApi::RdsUpdate>* rds_update, upb_arena* arena) {
|
1704
|
+
// Get the resources from the response.
|
1705
|
+
size_t size;
|
1706
|
+
const google_protobuf_Any* const* resources =
|
1707
|
+
envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
|
1708
|
+
for (size_t i = 0; i < size; ++i) {
|
1709
|
+
// Check the type_url of the resource.
|
1710
|
+
absl::string_view type_url =
|
1711
|
+
UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
|
1712
|
+
if (!IsRds(type_url)) {
|
1713
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not RDS.");
|
1714
|
+
}
|
1715
|
+
// Decode the route_config.
|
1716
|
+
const upb_strview encoded_route_config =
|
1717
|
+
google_protobuf_Any_value(resources[i]);
|
1718
|
+
const envoy_config_route_v3_RouteConfiguration* route_config =
|
1719
|
+
envoy_config_route_v3_RouteConfiguration_parse(
|
1720
|
+
encoded_route_config.data, encoded_route_config.size, arena);
|
1721
|
+
if (route_config == nullptr) {
|
1722
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode route_config.");
|
1723
|
+
}
|
1724
|
+
// Check route_config_name. Ignore unexpected route_config.
|
1725
|
+
absl::string_view route_config_name = UpbStringToAbsl(
|
1726
|
+
envoy_config_route_v3_RouteConfiguration_name(route_config));
|
1727
|
+
if (expected_route_configuration_names.find(route_config_name) ==
|
1728
|
+
expected_route_configuration_names.end()) {
|
1729
|
+
continue;
|
1730
|
+
}
|
1731
|
+
// Parse the route_config.
|
1732
|
+
XdsApi::RdsUpdate local_rds_update;
|
1733
|
+
grpc_error* error =
|
1734
|
+
RouteConfigParse(client, tracer, route_config, &local_rds_update);
|
1735
|
+
if (error != GRPC_ERROR_NONE) return error;
|
1736
|
+
rds_update->emplace(std::move(local_rds_update));
|
1737
|
+
return GRPC_ERROR_NONE;
|
1738
|
+
}
|
1739
|
+
return GRPC_ERROR_NONE;
|
1740
|
+
}
|
1741
|
+
|
1742
|
+
grpc_error* CdsResponseParse(
|
1743
|
+
XdsClient* client, TraceFlag* tracer,
|
1744
|
+
const envoy_service_discovery_v3_DiscoveryResponse* response,
|
1745
|
+
const std::set<absl::string_view>& expected_cluster_names,
|
1746
|
+
XdsApi::CdsUpdateMap* cds_update_map, upb_arena* arena) {
|
1747
|
+
// Get the resources from the response.
|
1748
|
+
size_t size;
|
1749
|
+
const google_protobuf_Any* const* resources =
|
1750
|
+
envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
|
1751
|
+
// Parse all the resources in the CDS response.
|
1752
|
+
for (size_t i = 0; i < size; ++i) {
|
1753
|
+
XdsApi::CdsUpdate cds_update;
|
1754
|
+
// Check the type_url of the resource.
|
1755
|
+
absl::string_view type_url =
|
1756
|
+
UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
|
1757
|
+
if (!IsCds(type_url)) {
|
1758
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not CDS.");
|
1759
|
+
}
|
1760
|
+
// Decode the cluster.
|
1761
|
+
const upb_strview encoded_cluster = google_protobuf_Any_value(resources[i]);
|
1762
|
+
const envoy_config_cluster_v3_Cluster* cluster =
|
1763
|
+
envoy_config_cluster_v3_Cluster_parse(encoded_cluster.data,
|
1764
|
+
encoded_cluster.size, arena);
|
1765
|
+
if (cluster == nullptr) {
|
1766
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode cluster.");
|
1767
|
+
}
|
1768
|
+
MaybeLogCluster(client, tracer, cluster);
|
1769
|
+
// Ignore unexpected cluster names.
|
1770
|
+
std::string cluster_name =
|
1771
|
+
UpbStringToStdString(envoy_config_cluster_v3_Cluster_name(cluster));
|
1772
|
+
if (expected_cluster_names.find(cluster_name) ==
|
1773
|
+
expected_cluster_names.end()) {
|
1774
|
+
continue;
|
1775
|
+
}
|
1776
|
+
// Fail on duplicate resources.
|
1777
|
+
if (cds_update_map->find(cluster_name) != cds_update_map->end()) {
|
1778
|
+
return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
|
1779
|
+
absl::StrCat("duplicate resource name \"", cluster_name, "\"")
|
1780
|
+
.c_str());
|
1781
|
+
}
|
1782
|
+
// Check the cluster_discovery_type.
|
1783
|
+
if (!envoy_config_cluster_v3_Cluster_has_type(cluster)) {
|
1784
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType not found.");
|
1785
|
+
}
|
1786
|
+
if (envoy_config_cluster_v3_Cluster_type(cluster) !=
|
1787
|
+
envoy_config_cluster_v3_Cluster_EDS) {
|
1788
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType is not EDS.");
|
1789
|
+
}
|
1790
|
+
// Check the EDS config source.
|
1791
|
+
const envoy_config_cluster_v3_Cluster_EdsClusterConfig* eds_cluster_config =
|
1792
|
+
envoy_config_cluster_v3_Cluster_eds_cluster_config(cluster);
|
1793
|
+
const envoy_config_core_v3_ConfigSource* eds_config =
|
1794
|
+
envoy_config_cluster_v3_Cluster_EdsClusterConfig_eds_config(
|
1795
|
+
eds_cluster_config);
|
1796
|
+
if (!envoy_config_core_v3_ConfigSource_has_ads(eds_config)) {
|
1797
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1798
|
+
"EDS ConfigSource is not ADS.");
|
1799
|
+
}
|
1800
|
+
// Record EDS service_name (if any).
|
1801
|
+
upb_strview service_name =
|
1802
|
+
envoy_config_cluster_v3_Cluster_EdsClusterConfig_service_name(
|
1803
|
+
eds_cluster_config);
|
1804
|
+
if (service_name.size != 0) {
|
1805
|
+
cds_update.eds_service_name = UpbStringToStdString(service_name);
|
1806
|
+
}
|
1807
|
+
// Check the LB policy.
|
1808
|
+
if (envoy_config_cluster_v3_Cluster_lb_policy(cluster) !=
|
1809
|
+
envoy_config_cluster_v3_Cluster_ROUND_ROBIN) {
|
1810
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1811
|
+
"LB policy is not ROUND_ROBIN.");
|
1812
|
+
}
|
1813
|
+
// Record LRS server name (if any).
|
1814
|
+
const envoy_config_core_v3_ConfigSource* lrs_server =
|
1815
|
+
envoy_config_cluster_v3_Cluster_lrs_server(cluster);
|
1816
|
+
if (lrs_server != nullptr) {
|
1817
|
+
if (!envoy_config_core_v3_ConfigSource_has_self(lrs_server)) {
|
1818
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1819
|
+
"LRS ConfigSource is not self.");
|
1820
|
+
}
|
1821
|
+
cds_update.lrs_load_reporting_server_name.emplace("");
|
1822
|
+
}
|
1823
|
+
cds_update_map->emplace(std::move(cluster_name), std::move(cds_update));
|
1824
|
+
}
|
1825
|
+
return GRPC_ERROR_NONE;
|
1826
|
+
}
|
1827
|
+
|
1828
|
+
grpc_error* ServerAddressParseAndAppend(
|
1829
|
+
const envoy_config_endpoint_v3_LbEndpoint* lb_endpoint,
|
1830
|
+
ServerAddressList* list) {
|
1831
|
+
// If health_status is not HEALTHY or UNKNOWN, skip this endpoint.
|
1832
|
+
const int32_t health_status =
|
1833
|
+
envoy_config_endpoint_v3_LbEndpoint_health_status(lb_endpoint);
|
1834
|
+
if (health_status != envoy_config_core_v3_UNKNOWN &&
|
1835
|
+
health_status != envoy_config_core_v3_HEALTHY) {
|
1836
|
+
return GRPC_ERROR_NONE;
|
1837
|
+
}
|
1838
|
+
// Find the ip:port.
|
1839
|
+
const envoy_config_endpoint_v3_Endpoint* endpoint =
|
1840
|
+
envoy_config_endpoint_v3_LbEndpoint_endpoint(lb_endpoint);
|
1841
|
+
const envoy_config_core_v3_Address* address =
|
1842
|
+
envoy_config_endpoint_v3_Endpoint_address(endpoint);
|
1843
|
+
const envoy_config_core_v3_SocketAddress* socket_address =
|
1844
|
+
envoy_config_core_v3_Address_socket_address(address);
|
1845
|
+
std::string address_str = UpbStringToStdString(
|
1846
|
+
envoy_config_core_v3_SocketAddress_address(socket_address));
|
1847
|
+
uint32_t port = envoy_config_core_v3_SocketAddress_port_value(socket_address);
|
1848
|
+
if (GPR_UNLIKELY(port >> 16) != 0) {
|
1849
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid port.");
|
1850
|
+
}
|
1851
|
+
// Populate grpc_resolved_address.
|
1852
|
+
grpc_resolved_address addr;
|
1853
|
+
grpc_string_to_sockaddr(&addr, address_str.c_str(), port);
|
1854
|
+
// Append the address to the list.
|
1855
|
+
list->emplace_back(addr, nullptr);
|
1856
|
+
return GRPC_ERROR_NONE;
|
1857
|
+
}
|
1858
|
+
|
1859
|
+
grpc_error* LocalityParse(
|
1860
|
+
const envoy_config_endpoint_v3_LocalityLbEndpoints* locality_lb_endpoints,
|
1861
|
+
XdsApi::PriorityListUpdate::LocalityMap::Locality* output_locality) {
|
1862
|
+
// Parse LB weight.
|
1863
|
+
const google_protobuf_UInt32Value* lb_weight =
|
1864
|
+
envoy_config_endpoint_v3_LocalityLbEndpoints_load_balancing_weight(
|
1865
|
+
locality_lb_endpoints);
|
1866
|
+
// If LB weight is not specified, it means this locality is assigned no load.
|
1867
|
+
// TODO(juanlishen): When we support CDS to configure the inter-locality
|
1868
|
+
// policy, we should change the LB weight handling.
|
1869
|
+
output_locality->lb_weight =
|
1870
|
+
lb_weight != nullptr ? google_protobuf_UInt32Value_value(lb_weight) : 0;
|
1871
|
+
if (output_locality->lb_weight == 0) return GRPC_ERROR_NONE;
|
1872
|
+
// Parse locality name.
|
1873
|
+
const envoy_config_core_v3_Locality* locality =
|
1874
|
+
envoy_config_endpoint_v3_LocalityLbEndpoints_locality(
|
1875
|
+
locality_lb_endpoints);
|
1876
|
+
std::string region =
|
1877
|
+
UpbStringToStdString(envoy_config_core_v3_Locality_region(locality));
|
1878
|
+
std::string zone =
|
1879
|
+
UpbStringToStdString(envoy_config_core_v3_Locality_region(locality));
|
1880
|
+
std::string sub_zone =
|
1881
|
+
UpbStringToStdString(envoy_config_core_v3_Locality_sub_zone(locality));
|
1882
|
+
output_locality->name = MakeRefCounted<XdsLocalityName>(
|
1883
|
+
std::move(region), std::move(zone), std::move(sub_zone));
|
1884
|
+
// Parse the addresses.
|
1885
|
+
size_t size;
|
1886
|
+
const envoy_config_endpoint_v3_LbEndpoint* const* lb_endpoints =
|
1887
|
+
envoy_config_endpoint_v3_LocalityLbEndpoints_lb_endpoints(
|
1888
|
+
locality_lb_endpoints, &size);
|
1889
|
+
for (size_t i = 0; i < size; ++i) {
|
1890
|
+
grpc_error* error = ServerAddressParseAndAppend(
|
1891
|
+
lb_endpoints[i], &output_locality->serverlist);
|
1892
|
+
if (error != GRPC_ERROR_NONE) return error;
|
1893
|
+
}
|
1894
|
+
// Parse the priority.
|
1895
|
+
output_locality->priority =
|
1896
|
+
envoy_config_endpoint_v3_LocalityLbEndpoints_priority(
|
1897
|
+
locality_lb_endpoints);
|
1898
|
+
return GRPC_ERROR_NONE;
|
1899
|
+
}
|
1900
|
+
|
1901
|
+
grpc_error* DropParseAndAppend(
|
1902
|
+
const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload*
|
1903
|
+
drop_overload,
|
1904
|
+
XdsApi::DropConfig* drop_config) {
|
1905
|
+
// Get the category.
|
1906
|
+
std::string category = UpbStringToStdString(
|
1907
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category(
|
1908
|
+
drop_overload));
|
1909
|
+
if (category.size() == 0) {
|
1910
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty drop category name");
|
1911
|
+
}
|
1912
|
+
// Get the drop rate (per million).
|
1913
|
+
const envoy_type_v3_FractionalPercent* drop_percentage =
|
1914
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_drop_percentage(
|
1915
|
+
drop_overload);
|
1916
|
+
uint32_t numerator =
|
1917
|
+
envoy_type_v3_FractionalPercent_numerator(drop_percentage);
|
1918
|
+
const auto denominator =
|
1919
|
+
static_cast<envoy_type_v3_FractionalPercent_DenominatorType>(
|
1920
|
+
envoy_type_v3_FractionalPercent_denominator(drop_percentage));
|
1921
|
+
// Normalize to million.
|
1922
|
+
switch (denominator) {
|
1923
|
+
case envoy_type_v3_FractionalPercent_HUNDRED:
|
1924
|
+
numerator *= 10000;
|
1925
|
+
break;
|
1926
|
+
case envoy_type_v3_FractionalPercent_TEN_THOUSAND:
|
1927
|
+
numerator *= 100;
|
1928
|
+
break;
|
1929
|
+
case envoy_type_v3_FractionalPercent_MILLION:
|
1930
|
+
break;
|
1931
|
+
default:
|
1932
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unknown denominator type");
|
1933
|
+
}
|
1934
|
+
// Cap numerator to 1000000.
|
1935
|
+
numerator = GPR_MIN(numerator, 1000000);
|
1936
|
+
drop_config->AddCategory(std::move(category), numerator);
|
1937
|
+
return GRPC_ERROR_NONE;
|
1938
|
+
}
|
1939
|
+
|
1940
|
+
grpc_error* EdsResponseParse(
|
1941
|
+
XdsClient* client, TraceFlag* tracer,
|
1942
|
+
const envoy_service_discovery_v3_DiscoveryResponse* response,
|
1943
|
+
const std::set<absl::string_view>& expected_eds_service_names,
|
1944
|
+
XdsApi::EdsUpdateMap* eds_update_map, upb_arena* arena) {
|
1945
|
+
// Get the resources from the response.
|
1946
|
+
size_t size;
|
1947
|
+
const google_protobuf_Any* const* resources =
|
1948
|
+
envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
|
1949
|
+
for (size_t i = 0; i < size; ++i) {
|
1950
|
+
XdsApi::EdsUpdate eds_update;
|
1951
|
+
// Check the type_url of the resource.
|
1952
|
+
absl::string_view type_url =
|
1953
|
+
UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
|
1954
|
+
if (!IsEds(type_url)) {
|
1955
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not EDS.");
|
1956
|
+
}
|
1957
|
+
// Get the cluster_load_assignment.
|
1958
|
+
upb_strview encoded_cluster_load_assignment =
|
1959
|
+
google_protobuf_Any_value(resources[i]);
|
1960
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment* cluster_load_assignment =
|
1961
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_parse(
|
1962
|
+
encoded_cluster_load_assignment.data,
|
1963
|
+
encoded_cluster_load_assignment.size, arena);
|
1964
|
+
if (cluster_load_assignment == nullptr) {
|
1965
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1966
|
+
"Can't parse cluster_load_assignment.");
|
1967
|
+
}
|
1968
|
+
MaybeLogClusterLoadAssignment(client, tracer, cluster_load_assignment);
|
1969
|
+
// Check the EDS service name. Ignore unexpected names.
|
1970
|
+
std::string eds_service_name = UpbStringToStdString(
|
1971
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_cluster_name(
|
1972
|
+
cluster_load_assignment));
|
1973
|
+
if (expected_eds_service_names.find(eds_service_name) ==
|
1974
|
+
expected_eds_service_names.end()) {
|
1975
|
+
continue;
|
1976
|
+
}
|
1977
|
+
// Fail on duplicate resources.
|
1978
|
+
if (eds_update_map->find(eds_service_name) != eds_update_map->end()) {
|
1979
|
+
return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
|
1980
|
+
absl::StrCat("duplicate resource name \"", eds_service_name, "\"")
|
1981
|
+
.c_str());
|
1982
|
+
}
|
1983
|
+
// Get the endpoints.
|
1984
|
+
size_t locality_size;
|
1985
|
+
const envoy_config_endpoint_v3_LocalityLbEndpoints* const* endpoints =
|
1986
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_endpoints(
|
1987
|
+
cluster_load_assignment, &locality_size);
|
1988
|
+
for (size_t j = 0; j < locality_size; ++j) {
|
1989
|
+
XdsApi::PriorityListUpdate::LocalityMap::Locality locality;
|
1990
|
+
grpc_error* error = LocalityParse(endpoints[j], &locality);
|
1991
|
+
if (error != GRPC_ERROR_NONE) return error;
|
1992
|
+
// Filter out locality with weight 0.
|
1993
|
+
if (locality.lb_weight == 0) continue;
|
1994
|
+
eds_update.priority_list_update.Add(locality);
|
1995
|
+
}
|
1996
|
+
for (uint32_t priority = 0;
|
1997
|
+
priority < eds_update.priority_list_update.size(); ++priority) {
|
1998
|
+
auto* locality_map = eds_update.priority_list_update.Find(priority);
|
1999
|
+
if (locality_map == nullptr || locality_map->size() == 0) {
|
2000
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
2001
|
+
"EDS update includes sparse priority list");
|
2002
|
+
}
|
2003
|
+
}
|
2004
|
+
// Get the drop config.
|
2005
|
+
eds_update.drop_config = MakeRefCounted<XdsApi::DropConfig>();
|
2006
|
+
const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy* policy =
|
2007
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_policy(
|
2008
|
+
cluster_load_assignment);
|
2009
|
+
if (policy != nullptr) {
|
2010
|
+
size_t drop_size;
|
2011
|
+
const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload* const*
|
2012
|
+
drop_overload =
|
2013
|
+
envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_drop_overloads(
|
2014
|
+
policy, &drop_size);
|
2015
|
+
for (size_t j = 0; j < drop_size; ++j) {
|
2016
|
+
grpc_error* error =
|
2017
|
+
DropParseAndAppend(drop_overload[j], eds_update.drop_config.get());
|
2018
|
+
if (error != GRPC_ERROR_NONE) return error;
|
2019
|
+
}
|
2020
|
+
}
|
2021
|
+
eds_update_map->emplace(std::move(eds_service_name), std::move(eds_update));
|
2022
|
+
}
|
2023
|
+
return GRPC_ERROR_NONE;
|
2024
|
+
}
|
2025
|
+
|
2026
|
+
std::string TypeUrlInternalToExternal(absl::string_view type_url) {
|
2027
|
+
if (type_url == kLdsV2TypeUrl) {
|
2028
|
+
return XdsApi::kLdsTypeUrl;
|
2029
|
+
} else if (type_url == kRdsV2TypeUrl) {
|
2030
|
+
return XdsApi::kRdsTypeUrl;
|
2031
|
+
} else if (type_url == kCdsV2TypeUrl) {
|
2032
|
+
return XdsApi::kCdsTypeUrl;
|
2033
|
+
} else if (type_url == kEdsV2TypeUrl) {
|
2034
|
+
return XdsApi::kEdsTypeUrl;
|
2035
|
+
}
|
2036
|
+
return std::string(type_url);
|
2037
|
+
}
|
2038
|
+
|
2039
|
+
} // namespace
|
2040
|
+
|
2041
|
+
XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
|
2042
|
+
const grpc_slice& encoded_response, const std::string& expected_server_name,
|
2043
|
+
const std::set<absl::string_view>& expected_route_configuration_names,
|
2044
|
+
const std::set<absl::string_view>& expected_cluster_names,
|
2045
|
+
const std::set<absl::string_view>& expected_eds_service_names) {
|
2046
|
+
AdsParseResult result;
|
2047
|
+
upb::Arena arena;
|
2048
|
+
// Decode the response.
|
2049
|
+
const envoy_service_discovery_v3_DiscoveryResponse* response =
|
2050
|
+
envoy_service_discovery_v3_DiscoveryResponse_parse(
|
2051
|
+
reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(encoded_response)),
|
2052
|
+
GRPC_SLICE_LENGTH(encoded_response), arena.ptr());
|
2053
|
+
// If decoding fails, output an empty type_url and return.
|
2054
|
+
if (response == nullptr) {
|
2055
|
+
result.parse_error =
|
2056
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode DiscoveryResponse.");
|
2057
|
+
return result;
|
2058
|
+
}
|
2059
|
+
MaybeLogDiscoveryResponse(client_, tracer_, response);
|
2060
|
+
// Record the type_url, the version_info, and the nonce of the response.
|
2061
|
+
result.type_url = TypeUrlInternalToExternal(UpbStringToAbsl(
|
2062
|
+
envoy_service_discovery_v3_DiscoveryResponse_type_url(response)));
|
2063
|
+
result.version = UpbStringToStdString(
|
2064
|
+
envoy_service_discovery_v3_DiscoveryResponse_version_info(response));
|
2065
|
+
result.nonce = UpbStringToStdString(
|
2066
|
+
envoy_service_discovery_v3_DiscoveryResponse_nonce(response));
|
2067
|
+
// Parse the response according to the resource type.
|
2068
|
+
if (IsLds(result.type_url)) {
|
2069
|
+
result.parse_error =
|
2070
|
+
LdsResponseParse(client_, tracer_, response, expected_server_name,
|
2071
|
+
&result.lds_update, arena.ptr());
|
2072
|
+
} else if (IsRds(result.type_url)) {
|
2073
|
+
result.parse_error = RdsResponseParse(client_, tracer_, response,
|
2074
|
+
expected_route_configuration_names,
|
2075
|
+
&result.rds_update, arena.ptr());
|
2076
|
+
} else if (IsCds(result.type_url)) {
|
2077
|
+
result.parse_error =
|
2078
|
+
CdsResponseParse(client_, tracer_, response, expected_cluster_names,
|
2079
|
+
&result.cds_update_map, arena.ptr());
|
2080
|
+
} else if (IsEds(result.type_url)) {
|
2081
|
+
result.parse_error =
|
2082
|
+
EdsResponseParse(client_, tracer_, response, expected_eds_service_names,
|
2083
|
+
&result.eds_update_map, arena.ptr());
|
2084
|
+
}
|
2085
|
+
return result;
|
2086
|
+
}
|
2087
|
+
|
2088
|
+
namespace {
|
2089
|
+
|
2090
|
+
void MaybeLogLrsRequest(
|
2091
|
+
XdsClient* client, TraceFlag* tracer,
|
2092
|
+
const envoy_service_load_stats_v3_LoadStatsRequest* request,
|
2093
|
+
const std::string& build_version) {
|
2094
|
+
if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
|
2095
|
+
gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
|
2096
|
+
// TODO(roth): When we can upgrade upb, use upb textformat code to dump
|
2097
|
+
// the raw proto instead of doing this manually.
|
2098
|
+
std::vector<std::string> fields;
|
2099
|
+
// node
|
2100
|
+
const auto* node =
|
2101
|
+
envoy_service_load_stats_v3_LoadStatsRequest_node(request);
|
2102
|
+
if (node != nullptr) {
|
2103
|
+
AddNodeLogFields(node, build_version, &fields);
|
2104
|
+
}
|
2105
|
+
// cluster_stats
|
2106
|
+
size_t num_cluster_stats;
|
2107
|
+
const struct envoy_config_endpoint_v3_ClusterStats* const* cluster_stats =
|
2108
|
+
envoy_service_load_stats_v3_LoadStatsRequest_cluster_stats(
|
2109
|
+
request, &num_cluster_stats);
|
2110
|
+
for (size_t i = 0; i < num_cluster_stats; ++i) {
|
2111
|
+
const auto* cluster_stat = cluster_stats[i];
|
2112
|
+
fields.emplace_back("cluster_stats {");
|
2113
|
+
// cluster_name
|
2114
|
+
AddStringField(
|
2115
|
+
" cluster_name",
|
2116
|
+
envoy_config_endpoint_v3_ClusterStats_cluster_name(cluster_stat),
|
2117
|
+
&fields);
|
2118
|
+
// cluster_service_name
|
2119
|
+
AddStringField(" cluster_service_name",
|
2120
|
+
envoy_config_endpoint_v3_ClusterStats_cluster_service_name(
|
2121
|
+
cluster_stat),
|
2122
|
+
&fields);
|
2123
|
+
// upstream_locality_stats
|
2124
|
+
size_t num_stats;
|
2125
|
+
const envoy_config_endpoint_v3_UpstreamLocalityStats* const* stats =
|
2126
|
+
envoy_config_endpoint_v3_ClusterStats_upstream_locality_stats(
|
2127
|
+
cluster_stat, &num_stats);
|
2128
|
+
for (size_t j = 0; j < num_stats; ++j) {
|
2129
|
+
const auto* stat = stats[j];
|
2130
|
+
fields.emplace_back(" upstream_locality_stats {");
|
2131
|
+
// locality
|
2132
|
+
const auto* locality =
|
2133
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_locality(stat);
|
2134
|
+
if (locality != nullptr) {
|
2135
|
+
fields.emplace_back(" locality {");
|
2136
|
+
AddLocalityField(3, locality, &fields);
|
2137
|
+
fields.emplace_back(" }");
|
2138
|
+
}
|
2139
|
+
// total_successful_requests
|
2140
|
+
fields.emplace_back(absl::StrCat(
|
2141
|
+
" total_successful_requests: ",
|
2142
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_total_successful_requests(
|
2143
|
+
stat)));
|
2144
|
+
// total_requests_in_progress
|
2145
|
+
fields.emplace_back(absl::StrCat(
|
2146
|
+
" total_requests_in_progress: ",
|
2147
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_total_requests_in_progress(
|
2148
|
+
stat)));
|
2149
|
+
// total_error_requests
|
2150
|
+
fields.emplace_back(absl::StrCat(
|
2151
|
+
" total_error_requests: ",
|
2152
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_total_error_requests(
|
2153
|
+
stat)));
|
2154
|
+
// total_issued_requests
|
2155
|
+
fields.emplace_back(absl::StrCat(
|
2156
|
+
" total_issued_requests: ",
|
2157
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_total_issued_requests(
|
2158
|
+
stat)));
|
2159
|
+
fields.emplace_back(" }");
|
2160
|
+
}
|
2161
|
+
// total_dropped_requests
|
2162
|
+
fields.emplace_back(absl::StrCat(
|
2163
|
+
" total_dropped_requests: ",
|
2164
|
+
envoy_config_endpoint_v3_ClusterStats_total_dropped_requests(
|
2165
|
+
cluster_stat)));
|
2166
|
+
// dropped_requests
|
2167
|
+
size_t num_drops;
|
2168
|
+
const envoy_config_endpoint_v3_ClusterStats_DroppedRequests* const*
|
2169
|
+
drops = envoy_config_endpoint_v3_ClusterStats_dropped_requests(
|
2170
|
+
cluster_stat, &num_drops);
|
2171
|
+
for (size_t j = 0; j < num_drops; ++j) {
|
2172
|
+
const auto* drop = drops[j];
|
2173
|
+
fields.emplace_back(" dropped_requests {");
|
2174
|
+
// category
|
2175
|
+
AddStringField(
|
2176
|
+
" category",
|
2177
|
+
envoy_config_endpoint_v3_ClusterStats_DroppedRequests_category(
|
2178
|
+
drop),
|
2179
|
+
&fields);
|
2180
|
+
// dropped_count
|
2181
|
+
fields.emplace_back(absl::StrCat(
|
2182
|
+
" dropped_count: ",
|
2183
|
+
envoy_config_endpoint_v3_ClusterStats_DroppedRequests_dropped_count(
|
2184
|
+
drop)));
|
2185
|
+
fields.emplace_back(" }");
|
2186
|
+
}
|
2187
|
+
// load_report_interval
|
2188
|
+
const auto* load_report_interval =
|
2189
|
+
envoy_config_endpoint_v3_ClusterStats_load_report_interval(
|
2190
|
+
cluster_stat);
|
2191
|
+
if (load_report_interval != nullptr) {
|
2192
|
+
fields.emplace_back(" load_report_interval {");
|
2193
|
+
fields.emplace_back(absl::StrCat(
|
2194
|
+
" seconds: ",
|
2195
|
+
google_protobuf_Duration_seconds(load_report_interval)));
|
2196
|
+
fields.emplace_back(
|
2197
|
+
absl::StrCat(" nanos: ",
|
2198
|
+
google_protobuf_Duration_nanos(load_report_interval)));
|
2199
|
+
fields.emplace_back(" }");
|
2200
|
+
}
|
2201
|
+
fields.emplace_back("}");
|
2202
|
+
}
|
2203
|
+
gpr_log(GPR_DEBUG, "[xds_client %p] constructed LRS request: %s", client,
|
2204
|
+
absl::StrJoin(fields, "\n").c_str());
|
2205
|
+
}
|
2206
|
+
}
|
2207
|
+
|
2208
|
+
grpc_slice SerializeLrsRequest(
|
2209
|
+
const envoy_service_load_stats_v3_LoadStatsRequest* request,
|
2210
|
+
upb_arena* arena) {
|
2211
|
+
size_t output_length;
|
2212
|
+
char* output = envoy_service_load_stats_v3_LoadStatsRequest_serialize(
|
2213
|
+
request, arena, &output_length);
|
2214
|
+
return grpc_slice_from_copied_buffer(output, output_length);
|
2215
|
+
}
|
2216
|
+
|
2217
|
+
} // namespace
|
2218
|
+
|
2219
|
+
grpc_slice XdsApi::CreateLrsInitialRequest(const std::string& server_name) {
|
2220
|
+
upb::Arena arena;
|
2221
|
+
// Create a request.
|
2222
|
+
envoy_service_load_stats_v3_LoadStatsRequest* request =
|
2223
|
+
envoy_service_load_stats_v3_LoadStatsRequest_new(arena.ptr());
|
2224
|
+
// Populate node.
|
2225
|
+
envoy_config_core_v3_Node* node_msg =
|
2226
|
+
envoy_service_load_stats_v3_LoadStatsRequest_mutable_node(request,
|
2227
|
+
arena.ptr());
|
2228
|
+
PopulateNode(arena.ptr(), bootstrap_, build_version_, user_agent_name_,
|
2229
|
+
server_name, node_msg);
|
2230
|
+
envoy_config_core_v3_Node_add_client_features(
|
2231
|
+
node_msg, upb_strview_makez("envoy.lrs.supports_send_all_clusters"),
|
2232
|
+
arena.ptr());
|
2233
|
+
MaybeLogLrsRequest(client_, tracer_, request, build_version_);
|
2234
|
+
return SerializeLrsRequest(request, arena.ptr());
|
2235
|
+
}
|
2236
|
+
|
2237
|
+
namespace {
|
2238
|
+
|
2239
|
+
void LocalityStatsPopulate(
|
2240
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats* output,
|
2241
|
+
const XdsLocalityName& locality_name,
|
2242
|
+
const XdsClusterLocalityStats::Snapshot& snapshot, upb_arena* arena) {
|
2243
|
+
// Set locality.
|
2244
|
+
envoy_config_core_v3_Locality* locality =
|
2245
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_mutable_locality(output,
|
2246
|
+
arena);
|
2247
|
+
if (!locality_name.region().empty()) {
|
2248
|
+
envoy_config_core_v3_Locality_set_region(
|
2249
|
+
locality, StdStringToUpbString(locality_name.region()));
|
2250
|
+
}
|
2251
|
+
if (!locality_name.zone().empty()) {
|
2252
|
+
envoy_config_core_v3_Locality_set_zone(
|
2253
|
+
locality, StdStringToUpbString(locality_name.zone()));
|
2254
|
+
}
|
2255
|
+
if (!locality_name.sub_zone().empty()) {
|
2256
|
+
envoy_config_core_v3_Locality_set_sub_zone(
|
2257
|
+
locality, StdStringToUpbString(locality_name.sub_zone()));
|
2258
|
+
}
|
2259
|
+
// Set total counts.
|
2260
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_set_total_successful_requests(
|
2261
|
+
output, snapshot.total_successful_requests);
|
2262
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_set_total_requests_in_progress(
|
2263
|
+
output, snapshot.total_requests_in_progress);
|
2264
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_set_total_error_requests(
|
2265
|
+
output, snapshot.total_error_requests);
|
2266
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_set_total_issued_requests(
|
2267
|
+
output, snapshot.total_issued_requests);
|
2268
|
+
// Add backend metrics.
|
2269
|
+
for (const auto& p : snapshot.backend_metrics) {
|
2270
|
+
const std::string& metric_name = p.first;
|
2271
|
+
const XdsClusterLocalityStats::BackendMetric& metric_value = p.second;
|
2272
|
+
envoy_config_endpoint_v3_EndpointLoadMetricStats* load_metric =
|
2273
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats_add_load_metric_stats(
|
2274
|
+
output, arena);
|
2275
|
+
envoy_config_endpoint_v3_EndpointLoadMetricStats_set_metric_name(
|
2276
|
+
load_metric, StdStringToUpbString(metric_name));
|
2277
|
+
envoy_config_endpoint_v3_EndpointLoadMetricStats_set_num_requests_finished_with_metric(
|
2278
|
+
load_metric, metric_value.num_requests_finished_with_metric);
|
2279
|
+
envoy_config_endpoint_v3_EndpointLoadMetricStats_set_total_metric_value(
|
2280
|
+
load_metric, metric_value.total_metric_value);
|
2281
|
+
}
|
2282
|
+
}
|
2283
|
+
|
2284
|
+
} // namespace
|
2285
|
+
|
2286
|
+
grpc_slice XdsApi::CreateLrsRequest(
|
2287
|
+
ClusterLoadReportMap cluster_load_report_map) {
|
2288
|
+
upb::Arena arena;
|
2289
|
+
// Create a request.
|
2290
|
+
envoy_service_load_stats_v3_LoadStatsRequest* request =
|
2291
|
+
envoy_service_load_stats_v3_LoadStatsRequest_new(arena.ptr());
|
2292
|
+
for (auto& p : cluster_load_report_map) {
|
2293
|
+
const std::string& cluster_name = p.first.first;
|
2294
|
+
const std::string& eds_service_name = p.first.second;
|
2295
|
+
const ClusterLoadReport& load_report = p.second;
|
2296
|
+
// Add cluster stats.
|
2297
|
+
envoy_config_endpoint_v3_ClusterStats* cluster_stats =
|
2298
|
+
envoy_service_load_stats_v3_LoadStatsRequest_add_cluster_stats(
|
2299
|
+
request, arena.ptr());
|
2300
|
+
// Set the cluster name.
|
2301
|
+
envoy_config_endpoint_v3_ClusterStats_set_cluster_name(
|
2302
|
+
cluster_stats, StdStringToUpbString(cluster_name));
|
2303
|
+
// Set EDS service name, if non-empty.
|
2304
|
+
if (!eds_service_name.empty()) {
|
2305
|
+
envoy_config_endpoint_v3_ClusterStats_set_cluster_service_name(
|
2306
|
+
cluster_stats, StdStringToUpbString(eds_service_name));
|
2307
|
+
}
|
2308
|
+
// Add locality stats.
|
2309
|
+
for (const auto& p : load_report.locality_stats) {
|
2310
|
+
const XdsLocalityName& locality_name = *p.first;
|
2311
|
+
const auto& snapshot = p.second;
|
2312
|
+
envoy_config_endpoint_v3_UpstreamLocalityStats* locality_stats =
|
2313
|
+
envoy_config_endpoint_v3_ClusterStats_add_upstream_locality_stats(
|
2314
|
+
cluster_stats, arena.ptr());
|
2315
|
+
LocalityStatsPopulate(locality_stats, locality_name, snapshot,
|
2316
|
+
arena.ptr());
|
2317
|
+
}
|
2318
|
+
// Add dropped requests.
|
2319
|
+
uint64_t total_dropped_requests = 0;
|
2320
|
+
for (const auto& p : load_report.dropped_requests) {
|
2321
|
+
const std::string& category = p.first;
|
2322
|
+
const uint64_t count = p.second;
|
2323
|
+
envoy_config_endpoint_v3_ClusterStats_DroppedRequests* dropped_requests =
|
2324
|
+
envoy_config_endpoint_v3_ClusterStats_add_dropped_requests(
|
2325
|
+
cluster_stats, arena.ptr());
|
2326
|
+
envoy_config_endpoint_v3_ClusterStats_DroppedRequests_set_category(
|
2327
|
+
dropped_requests, StdStringToUpbString(category));
|
2328
|
+
envoy_config_endpoint_v3_ClusterStats_DroppedRequests_set_dropped_count(
|
2329
|
+
dropped_requests, count);
|
2330
|
+
total_dropped_requests += count;
|
2331
|
+
}
|
2332
|
+
// Set total dropped requests.
|
2333
|
+
envoy_config_endpoint_v3_ClusterStats_set_total_dropped_requests(
|
2334
|
+
cluster_stats, total_dropped_requests);
|
2335
|
+
// Set real load report interval.
|
2336
|
+
gpr_timespec timespec =
|
2337
|
+
grpc_millis_to_timespec(load_report.load_report_interval, GPR_TIMESPAN);
|
2338
|
+
google_protobuf_Duration* load_report_interval =
|
2339
|
+
envoy_config_endpoint_v3_ClusterStats_mutable_load_report_interval(
|
2340
|
+
cluster_stats, arena.ptr());
|
2341
|
+
google_protobuf_Duration_set_seconds(load_report_interval, timespec.tv_sec);
|
2342
|
+
google_protobuf_Duration_set_nanos(load_report_interval, timespec.tv_nsec);
|
2343
|
+
}
|
2344
|
+
MaybeLogLrsRequest(client_, tracer_, request, build_version_);
|
2345
|
+
return SerializeLrsRequest(request, arena.ptr());
|
2346
|
+
}
|
2347
|
+
|
2348
|
+
grpc_error* XdsApi::ParseLrsResponse(const grpc_slice& encoded_response,
|
2349
|
+
bool* send_all_clusters,
|
2350
|
+
std::set<std::string>* cluster_names,
|
2351
|
+
grpc_millis* load_reporting_interval) {
|
2352
|
+
upb::Arena arena;
|
2353
|
+
// Decode the response.
|
2354
|
+
const envoy_service_load_stats_v3_LoadStatsResponse* decoded_response =
|
2355
|
+
envoy_service_load_stats_v3_LoadStatsResponse_parse(
|
2356
|
+
reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(encoded_response)),
|
2357
|
+
GRPC_SLICE_LENGTH(encoded_response), arena.ptr());
|
2358
|
+
// Parse the response.
|
2359
|
+
if (decoded_response == nullptr) {
|
2360
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode response.");
|
2361
|
+
}
|
2362
|
+
// Check send_all_clusters.
|
2363
|
+
if (envoy_service_load_stats_v3_LoadStatsResponse_send_all_clusters(
|
2364
|
+
decoded_response)) {
|
2365
|
+
*send_all_clusters = true;
|
2366
|
+
} else {
|
2367
|
+
// Store the cluster names.
|
2368
|
+
size_t size;
|
2369
|
+
const upb_strview* clusters =
|
2370
|
+
envoy_service_load_stats_v3_LoadStatsResponse_clusters(decoded_response,
|
2371
|
+
&size);
|
2372
|
+
for (size_t i = 0; i < size; ++i) {
|
2373
|
+
cluster_names->emplace(UpbStringToStdString(clusters[i]));
|
2374
|
+
}
|
2375
|
+
}
|
2376
|
+
// Get the load report interval.
|
2377
|
+
const google_protobuf_Duration* load_reporting_interval_duration =
|
2378
|
+
envoy_service_load_stats_v3_LoadStatsResponse_load_reporting_interval(
|
2379
|
+
decoded_response);
|
2380
|
+
gpr_timespec timespec{
|
2381
|
+
google_protobuf_Duration_seconds(load_reporting_interval_duration),
|
2382
|
+
google_protobuf_Duration_nanos(load_reporting_interval_duration),
|
2383
|
+
GPR_TIMESPAN};
|
2384
|
+
*load_reporting_interval = gpr_time_to_millis(timespec);
|
2385
|
+
return GRPC_ERROR_NONE;
|
2386
|
+
}
|
2387
|
+
|
2388
|
+
} // namespace grpc_core
|