grpc 1.31.0.pre1 → 1.33.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (614) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +693 -16022
  3. data/include/grpc/grpc.h +0 -5
  4. data/include/grpc/grpc_security.h +47 -14
  5. data/include/grpc/impl/codegen/README.md +22 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +0 -5
  7. data/include/grpc/impl/codegen/port_platform.h +6 -1
  8. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -2
  9. data/src/core/ext/filters/client_channel/client_channel.cc +264 -186
  10. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +0 -3
  12. data/src/core/ext/filters/client_channel/config_selector.cc +0 -4
  13. data/src/core/ext/filters/client_channel/config_selector.h +34 -5
  14. data/src/core/ext/filters/client_channel/health/health_check_client.cc +6 -1
  15. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -3
  16. data/src/core/ext/filters/client_channel/lb_policy.h +3 -1
  17. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +48 -35
  18. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  19. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +9 -6
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +126 -119
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +0 -13
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +0 -3
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -37
  24. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +21 -15
  25. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +32 -13
  26. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -7
  27. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +9 -32
  28. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +26 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +207 -129
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +453 -255
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc +571 -0
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +727 -0
  33. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +8 -1
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +3 -3
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  38. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
  39. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
  40. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +602 -58
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +28 -0
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -39
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +4 -3
  44. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +49 -47
  45. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +5 -9
  46. data/src/core/ext/filters/client_channel/server_address.cc +120 -7
  47. data/src/core/ext/filters/client_channel/server_address.h +48 -21
  48. data/src/core/ext/filters/client_channel/service_config.cc +16 -13
  49. data/src/core/ext/filters/client_channel/service_config.h +7 -4
  50. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +2 -2
  51. data/src/core/ext/filters/client_channel/service_config_parser.cc +8 -6
  52. data/src/core/ext/filters/client_channel/service_config_parser.h +8 -5
  53. data/src/core/ext/filters/client_channel/subchannel.cc +64 -23
  54. data/src/core/ext/filters/client_channel/subchannel.h +16 -4
  55. data/src/core/ext/filters/client_channel/subchannel_interface.h +44 -0
  56. data/src/core/ext/filters/max_age/max_age_filter.cc +2 -1
  57. data/src/core/ext/filters/message_size/message_size_filter.cc +2 -1
  58. data/src/core/ext/filters/message_size/message_size_filter.h +2 -1
  59. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +87 -31
  60. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +18 -1
  61. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +10 -35
  62. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +19 -25
  63. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -1
  64. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +2 -2
  65. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +6 -6
  66. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -2
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +256 -287
  68. data/src/core/ext/transport/chttp2/transport/flow_control.cc +11 -3
  69. data/src/core/ext/transport/chttp2/transport/flow_control.h +10 -0
  70. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -2
  71. data/src/core/ext/transport/chttp2/transport/internal.h +10 -1
  72. data/src/core/ext/transport/chttp2/transport/parsing.cc +17 -30
  73. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -5
  74. data/src/core/ext/transport/inproc/inproc_transport.cc +12 -12
  75. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +244 -0
  76. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +766 -0
  77. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +74 -0
  78. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +226 -0
  79. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +458 -0
  80. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +1635 -0
  81. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/filter.upb.c +8 -8
  82. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +69 -0
  83. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/outlier_detection.upb.c +8 -8
  84. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +323 -0
  85. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +124 -0
  86. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +379 -0
  87. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/backoff.upb.c +8 -8
  88. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +79 -0
  89. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +310 -0
  90. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +869 -0
  91. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +103 -0
  92. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +351 -0
  93. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +34 -0
  94. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +71 -0
  95. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +53 -0
  96. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +133 -0
  97. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +241 -0
  98. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +752 -0
  99. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +170 -0
  100. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +684 -0
  101. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/http_uri.upb.c +8 -8
  102. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +80 -0
  103. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +176 -0
  104. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +645 -0
  105. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +28 -0
  106. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +58 -0
  107. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/socket_option.upb.c +6 -6
  108. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +88 -0
  109. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +36 -0
  110. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +85 -0
  111. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +91 -0
  112. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +220 -0
  113. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +91 -0
  114. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +273 -0
  115. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +112 -0
  116. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +332 -0
  117. data/src/core/ext/upb-generated/envoy/config/listener/{v2 → v3}/api_listener.upb.c +8 -8
  118. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +65 -0
  119. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +128 -0
  120. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +467 -0
  121. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +155 -0
  122. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +539 -0
  123. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +41 -0
  124. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +94 -0
  125. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +178 -0
  126. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +616 -0
  127. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +63 -0
  128. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +204 -0
  129. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +900 -0
  130. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +3290 -0
  131. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +60 -0
  132. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +139 -0
  133. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +50 -0
  134. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +108 -0
  135. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +364 -0
  136. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +1336 -0
  137. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +20 -0
  138. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +34 -0
  139. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +110 -0
  140. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +387 -0
  141. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +76 -0
  142. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +214 -0
  143. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +147 -0
  144. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +570 -0
  145. data/src/core/ext/upb-generated/envoy/{api/v2 → service/cluster/v3}/cds.upb.c +5 -6
  146. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +49 -0
  147. data/src/core/ext/upb-generated/envoy/service/discovery/{v2 → v3}/ads.upb.c +5 -4
  148. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +49 -0
  149. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +139 -0
  150. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +449 -0
  151. data/src/core/ext/upb-generated/envoy/{api/v2 → service/endpoint/v3}/eds.upb.c +5 -6
  152. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +49 -0
  153. data/src/core/ext/upb-generated/envoy/{api/v2 → service/listener/v3}/lds.upb.c +5 -6
  154. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +49 -0
  155. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +55 -0
  156. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +136 -0
  157. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/rds.upb.c +5 -6
  158. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +49 -0
  159. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/srds.upb.c +5 -6
  160. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +49 -0
  161. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +47 -0
  162. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +114 -0
  163. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +35 -0
  164. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +77 -0
  165. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +34 -0
  166. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +71 -0
  167. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +64 -0
  168. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +145 -0
  169. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +54 -0
  170. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +133 -0
  171. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +63 -0
  172. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +188 -0
  173. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +88 -0
  174. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +258 -0
  175. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +90 -0
  176. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +250 -0
  177. data/src/core/ext/upb-generated/envoy/type/{http.upb.c → v3/http.upb.c} +2 -2
  178. data/src/core/ext/upb-generated/envoy/type/{http.upb.h → v3/http.upb.h} +8 -8
  179. data/src/core/ext/upb-generated/envoy/type/{percent.upb.c → v3/percent.upb.c} +9 -8
  180. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +86 -0
  181. data/src/core/ext/upb-generated/envoy/type/{range.upb.c → v3/range.upb.c} +12 -11
  182. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +111 -0
  183. data/src/core/ext/upb-generated/envoy/type/{semantic_version.upb.c → v3/semantic_version.upb.c} +6 -5
  184. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +61 -0
  185. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +242 -0
  186. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +753 -0
  187. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +234 -0
  188. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +759 -0
  189. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +36 -36
  190. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +1 -1
  191. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +31 -0
  192. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +57 -0
  193. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +27 -0
  194. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +53 -0
  195. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +28 -0
  196. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +53 -0
  197. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +52 -0
  198. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +129 -0
  199. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +42 -0
  200. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +77 -0
  201. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +36 -0
  202. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +85 -0
  203. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +54 -0
  204. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +160 -0
  205. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +36 -0
  206. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +84 -0
  207. data/src/core/ext/upb-generated/validate/validate.upb.c +11 -11
  208. data/src/core/ext/upb-generated/validate/validate.upb.h +1 -1
  209. data/src/core/ext/xds/certificate_provider_factory.h +59 -0
  210. data/src/core/ext/xds/certificate_provider_registry.cc +103 -0
  211. data/src/core/ext/xds/certificate_provider_registry.h +57 -0
  212. data/src/core/ext/xds/certificate_provider_store.h +50 -0
  213. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +377 -0
  214. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +102 -0
  215. data/src/core/ext/xds/xds_api.cc +2596 -0
  216. data/src/core/ext/xds/xds_api.h +397 -0
  217. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.cc +44 -2
  218. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.h +8 -3
  219. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_args.h +9 -6
  220. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.cc +541 -785
  221. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.h +114 -93
  222. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.cc +20 -14
  223. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.h +36 -8
  224. data/src/core/lib/channel/channel_args.h +0 -1
  225. data/src/core/lib/channel/channelz.cc +24 -60
  226. data/src/core/lib/channel/channelz.h +12 -20
  227. data/src/core/lib/channel/channelz_registry.cc +15 -12
  228. data/src/core/lib/channel/channelz_registry.h +3 -0
  229. data/src/core/lib/gpr/sync_posix.cc +2 -8
  230. data/src/core/lib/gpr/time_precise.cc +2 -0
  231. data/src/core/lib/gpr/time_precise.h +6 -2
  232. data/src/core/lib/gprpp/dual_ref_counted.h +336 -0
  233. data/src/core/lib/gprpp/ref_counted.h +51 -22
  234. data/src/core/lib/gprpp/ref_counted_ptr.h +153 -0
  235. data/src/core/lib/iomgr/endpoint.cc +5 -1
  236. data/src/core/lib/iomgr/endpoint.h +7 -3
  237. data/src/core/lib/iomgr/endpoint_cfstream.cc +36 -11
  238. data/src/core/lib/iomgr/ev_posix.cc +0 -2
  239. data/src/core/lib/iomgr/exec_ctx.h +10 -8
  240. data/src/core/lib/iomgr/iomgr.cc +0 -10
  241. data/src/core/lib/iomgr/iomgr.h +0 -10
  242. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.cc +1 -1
  243. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.h +3 -3
  244. data/src/core/lib/iomgr/sockaddr_utils.cc +2 -1
  245. data/src/core/lib/iomgr/sockaddr_utils.h +2 -1
  246. data/src/core/lib/iomgr/tcp_custom.cc +32 -16
  247. data/src/core/lib/iomgr/tcp_posix.cc +31 -13
  248. data/src/core/lib/iomgr/tcp_windows.cc +26 -10
  249. data/src/core/lib/json/json_util.cc +58 -0
  250. data/src/core/lib/json/json_util.h +37 -0
  251. data/src/core/lib/security/authorization/authorization_engine.cc +177 -0
  252. data/src/core/lib/security/authorization/authorization_engine.h +84 -0
  253. data/src/core/lib/security/authorization/evaluate_args.cc +153 -0
  254. data/src/core/lib/security/authorization/evaluate_args.h +59 -0
  255. data/src/core/lib/security/authorization/mock_cel/activation.h +57 -0
  256. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +42 -0
  257. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +68 -0
  258. data/src/core/lib/security/authorization/mock_cel/cel_value.h +93 -0
  259. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +67 -0
  260. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +56 -0
  261. data/src/core/lib/security/authorization/mock_cel/statusor.h +50 -0
  262. data/src/core/lib/security/certificate_provider.h +60 -0
  263. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +56 -38
  264. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +321 -0
  265. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +214 -0
  266. data/src/core/lib/security/credentials/xds/xds_credentials.cc +45 -0
  267. data/src/core/lib/security/credentials/xds/xds_credentials.h +51 -0
  268. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +7 -12
  269. data/src/core/lib/security/security_connector/ssl_utils.h +5 -0
  270. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  271. data/src/core/lib/surface/call.cc +12 -12
  272. data/src/core/lib/surface/call.h +2 -1
  273. data/src/core/lib/surface/channel.cc +37 -51
  274. data/src/core/lib/surface/channel.h +18 -3
  275. data/src/core/lib/surface/completion_queue.cc +10 -272
  276. data/src/core/lib/surface/completion_queue.h +0 -8
  277. data/src/core/lib/surface/init.cc +27 -12
  278. data/src/core/lib/surface/server.cc +1066 -1244
  279. data/src/core/lib/surface/server.h +363 -87
  280. data/src/core/lib/surface/version.cc +2 -2
  281. data/src/core/lib/transport/authority_override.cc +38 -0
  282. data/src/core/lib/transport/authority_override.h +32 -0
  283. data/src/core/lib/transport/bdp_estimator.h +2 -1
  284. data/src/core/lib/transport/connectivity_state.cc +18 -13
  285. data/src/core/lib/transport/connectivity_state.h +20 -8
  286. data/src/core/lib/transport/error_utils.cc +13 -0
  287. data/src/core/lib/transport/error_utils.h +6 -0
  288. data/src/core/lib/transport/metadata.cc +11 -1
  289. data/src/core/lib/transport/static_metadata.cc +295 -276
  290. data/src/core/lib/transport/static_metadata.h +80 -73
  291. data/src/core/lib/transport/transport.h +7 -0
  292. data/src/core/lib/uri/uri_parser.cc +23 -21
  293. data/src/core/lib/uri/uri_parser.h +3 -1
  294. data/src/core/plugin_registry/grpc_plugin_registry.cc +35 -20
  295. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +22 -0
  296. data/src/core/tsi/ssl_transport_security.cc +2 -2
  297. data/src/ruby/bin/math_services_pb.rb +4 -4
  298. data/src/ruby/ext/grpc/rb_channel_credentials.c +9 -0
  299. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -4
  300. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +7 -7
  301. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  302. data/src/ruby/lib/grpc/version.rb +1 -1
  303. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +2 -2
  304. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +5 -0
  305. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +28 -12
  306. data/src/ruby/spec/channel_credentials_spec.rb +10 -0
  307. data/src/ruby/spec/generic/active_call_spec.rb +19 -8
  308. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  309. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  310. data/src/ruby/spec/pb/codegen/package_option_spec.rb +20 -0
  311. data/src/ruby/spec/user_agent_spec.rb +74 -0
  312. data/third_party/abseil-cpp/absl/algorithm/container.h +1727 -0
  313. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +161 -0
  314. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.cc +93 -0
  315. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.h +130 -0
  316. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +620 -0
  317. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +126 -0
  318. data/third_party/abseil-cpp/absl/container/fixed_array.h +515 -0
  319. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +503 -0
  320. data/third_party/abseil-cpp/absl/container/internal/common.h +202 -0
  321. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +440 -0
  322. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +146 -0
  323. data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +191 -0
  324. data/third_party/abseil-cpp/absl/container/internal/hashtable_debug_hooks.h +85 -0
  325. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +269 -0
  326. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +297 -0
  327. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +30 -0
  328. data/third_party/abseil-cpp/absl/container/internal/have_sse.h +49 -0
  329. data/third_party/abseil-cpp/absl/container/internal/layout.h +741 -0
  330. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +48 -0
  331. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +1882 -0
  332. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +138 -0
  333. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.h +32 -0
  334. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +1895 -0
  335. data/third_party/abseil-cpp/absl/debugging/internal/demangle.h +71 -0
  336. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.cc +382 -0
  337. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +134 -0
  338. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +192 -0
  339. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +125 -0
  340. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +70 -0
  341. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +99 -0
  342. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +248 -0
  343. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_unimplemented-inl.inc +24 -0
  344. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +85 -0
  345. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +346 -0
  346. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +128 -0
  347. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +194 -0
  348. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.h +158 -0
  349. data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +140 -0
  350. data/third_party/abseil-cpp/absl/debugging/stacktrace.h +231 -0
  351. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +25 -0
  352. data/third_party/abseil-cpp/absl/debugging/symbolize.h +99 -0
  353. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +1480 -0
  354. data/third_party/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +40 -0
  355. data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +81 -0
  356. data/third_party/abseil-cpp/absl/functional/function_ref.h +139 -0
  357. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +106 -0
  358. data/third_party/abseil-cpp/absl/hash/hash.h +324 -0
  359. data/third_party/abseil-cpp/absl/hash/internal/city.cc +346 -0
  360. data/third_party/abseil-cpp/absl/hash/internal/city.h +96 -0
  361. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +55 -0
  362. data/third_party/abseil-cpp/absl/hash/internal/hash.h +988 -0
  363. data/third_party/abseil-cpp/absl/status/status.cc +447 -0
  364. data/third_party/abseil-cpp/absl/status/status.h +428 -0
  365. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +43 -0
  366. data/third_party/abseil-cpp/absl/status/status_payload_printer.h +51 -0
  367. data/third_party/abseil-cpp/absl/strings/cord.cc +2019 -0
  368. data/third_party/abseil-cpp/absl/strings/cord.h +1121 -0
  369. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +151 -0
  370. data/third_party/abseil-cpp/absl/synchronization/barrier.cc +52 -0
  371. data/third_party/abseil-cpp/absl/synchronization/barrier.h +79 -0
  372. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +57 -0
  373. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.h +99 -0
  374. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +140 -0
  375. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.h +60 -0
  376. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +697 -0
  377. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.h +141 -0
  378. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +155 -0
  379. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +261 -0
  380. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +106 -0
  381. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +115 -0
  382. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +484 -0
  383. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +159 -0
  384. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +2728 -0
  385. data/third_party/abseil-cpp/absl/synchronization/mutex.h +1056 -0
  386. data/third_party/abseil-cpp/absl/synchronization/notification.cc +78 -0
  387. data/third_party/abseil-cpp/absl/synchronization/notification.h +123 -0
  388. data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +64 -0
  389. data/third_party/abseil-cpp/absl/types/bad_variant_access.h +82 -0
  390. data/third_party/abseil-cpp/absl/types/internal/variant.h +1646 -0
  391. data/third_party/abseil-cpp/absl/types/variant.h +861 -0
  392. data/third_party/boringssl-with-bazel/err_data.c +475 -467
  393. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +0 -6
  394. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +9 -43
  395. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.c +55 -4
  396. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +34 -0
  397. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +4 -0
  398. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +16 -0
  399. data/third_party/boringssl-with-bazel/src/crypto/evp/p_dsa_asn1.c +6 -2
  400. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +2 -0
  401. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +4 -0
  402. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +30 -10
  403. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -15
  404. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +543 -0
  405. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +237 -0
  406. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +44 -2
  407. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +221 -49
  408. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +64 -20
  409. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +3 -3
  410. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +0 -8
  411. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +3 -3
  412. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +1 -1
  413. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +7 -2
  414. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +21 -18
  415. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_obj.c +1 -1
  416. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +24 -3
  417. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +3 -3
  418. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_txt.c +67 -67
  419. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +3 -3
  420. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +29 -35
  421. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +13 -2
  422. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +9 -8
  423. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +10 -10
  424. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +2 -2
  425. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +28 -40
  426. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +20 -0
  427. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +3 -1
  428. data/third_party/boringssl-with-bazel/src/crypto/x509v3/ext_dat.h +1 -4
  429. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +7 -3
  430. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_genn.c +2 -2
  431. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +1 -1
  432. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +55 -8
  433. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -1
  434. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +52 -0
  435. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +0 -1
  436. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +2 -2
  437. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +6 -0
  438. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +1 -1
  439. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +12 -0
  440. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +9 -0
  441. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +4 -1
  442. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +48 -9
  443. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +2 -3
  444. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +26 -6
  445. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +199 -78
  446. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +52 -43
  447. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +18 -18
  448. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -3
  449. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
  450. data/third_party/boringssl-with-bazel/src/ssl/internal.h +13 -9
  451. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +3 -6
  452. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +8 -9
  453. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +10 -0
  454. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +34 -9
  455. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -2
  456. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +4 -8
  457. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +7 -2
  458. data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +5 -3
  459. data/third_party/re2/re2/bitmap256.h +117 -0
  460. data/third_party/re2/re2/bitstate.cc +385 -0
  461. data/third_party/re2/re2/compile.cc +1279 -0
  462. data/third_party/re2/re2/dfa.cc +2130 -0
  463. data/third_party/re2/re2/filtered_re2.cc +121 -0
  464. data/third_party/re2/re2/filtered_re2.h +109 -0
  465. data/third_party/re2/re2/mimics_pcre.cc +197 -0
  466. data/third_party/re2/re2/nfa.cc +713 -0
  467. data/third_party/re2/re2/onepass.cc +623 -0
  468. data/third_party/re2/re2/parse.cc +2464 -0
  469. data/third_party/re2/re2/perl_groups.cc +119 -0
  470. data/third_party/re2/re2/pod_array.h +55 -0
  471. data/third_party/re2/re2/prefilter.cc +710 -0
  472. data/third_party/re2/re2/prefilter.h +108 -0
  473. data/third_party/re2/re2/prefilter_tree.cc +407 -0
  474. data/third_party/re2/re2/prefilter_tree.h +139 -0
  475. data/third_party/re2/re2/prog.cc +988 -0
  476. data/third_party/re2/re2/prog.h +436 -0
  477. data/third_party/re2/re2/re2.cc +1362 -0
  478. data/third_party/re2/re2/re2.h +1002 -0
  479. data/third_party/re2/re2/regexp.cc +980 -0
  480. data/third_party/re2/re2/regexp.h +659 -0
  481. data/third_party/re2/re2/set.cc +154 -0
  482. data/third_party/re2/re2/set.h +80 -0
  483. data/third_party/re2/re2/simplify.cc +657 -0
  484. data/third_party/re2/re2/sparse_array.h +392 -0
  485. data/third_party/re2/re2/sparse_set.h +264 -0
  486. data/third_party/re2/re2/stringpiece.cc +65 -0
  487. data/third_party/re2/re2/stringpiece.h +210 -0
  488. data/third_party/re2/re2/tostring.cc +351 -0
  489. data/third_party/re2/re2/unicode_casefold.cc +582 -0
  490. data/third_party/re2/re2/unicode_casefold.h +78 -0
  491. data/third_party/re2/re2/unicode_groups.cc +6269 -0
  492. data/third_party/re2/re2/unicode_groups.h +67 -0
  493. data/third_party/re2/re2/walker-inl.h +246 -0
  494. data/third_party/re2/util/benchmark.h +156 -0
  495. data/third_party/re2/util/flags.h +26 -0
  496. data/third_party/re2/util/logging.h +109 -0
  497. data/third_party/re2/util/malloc_counter.h +19 -0
  498. data/third_party/re2/util/mix.h +41 -0
  499. data/third_party/re2/util/mutex.h +148 -0
  500. data/third_party/re2/util/pcre.cc +1025 -0
  501. data/third_party/re2/util/pcre.h +681 -0
  502. data/third_party/re2/util/rune.cc +260 -0
  503. data/third_party/re2/util/strutil.cc +149 -0
  504. data/third_party/re2/util/strutil.h +21 -0
  505. data/third_party/re2/util/test.h +50 -0
  506. data/third_party/re2/util/utf.h +44 -0
  507. data/third_party/re2/util/util.h +42 -0
  508. data/third_party/upb/upb/decode.c +64 -15
  509. data/third_party/upb/upb/encode.c +2 -2
  510. data/third_party/upb/upb/msg.h +2 -2
  511. data/third_party/upb/upb/port_def.inc +1 -1
  512. data/third_party/upb/upb/table.c +0 -11
  513. data/third_party/upb/upb/table.int.h +0 -9
  514. data/third_party/upb/upb/upb.c +16 -14
  515. data/third_party/upb/upb/upb.h +26 -0
  516. data/third_party/upb/upb/upb.hpp +2 -0
  517. metadata +340 -153
  518. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +0 -528
  519. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +0 -1142
  520. data/src/core/ext/filters/client_channel/xds/xds_api.cc +0 -2110
  521. data/src/core/ext/filters/client_channel/xds/xds_api.h +0 -345
  522. data/src/core/ext/filters/client_channel/xds/xds_channel.h +0 -46
  523. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +0 -106
  524. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +0 -21
  525. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -34
  526. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +0 -114
  527. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +0 -429
  528. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +0 -72
  529. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +0 -198
  530. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +0 -105
  531. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +0 -388
  532. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +0 -52
  533. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +0 -403
  534. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +0 -1453
  535. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +0 -74
  536. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +0 -226
  537. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +0 -69
  538. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +0 -323
  539. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +0 -112
  540. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +0 -334
  541. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +0 -79
  542. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +0 -313
  543. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +0 -891
  544. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +0 -96
  545. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +0 -328
  546. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +0 -34
  547. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +0 -71
  548. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +0 -197
  549. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +0 -649
  550. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +0 -172
  551. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +0 -693
  552. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +0 -80
  553. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +0 -152
  554. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +0 -536
  555. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +0 -88
  556. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +0 -129
  557. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +0 -386
  558. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +0 -52
  559. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +0 -92
  560. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +0 -224
  561. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +0 -18
  562. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -32
  563. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +0 -91
  564. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +0 -273
  565. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +0 -112
  566. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +0 -332
  567. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +0 -52
  568. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +0 -109
  569. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +0 -415
  570. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +0 -18
  571. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -32
  572. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +0 -145
  573. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +0 -538
  574. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +0 -43
  575. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +0 -111
  576. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +0 -52
  577. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +0 -63
  578. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +0 -204
  579. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +0 -18
  580. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -32
  581. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +0 -815
  582. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +0 -2984
  583. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +0 -59
  584. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +0 -135
  585. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +0 -52
  586. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +0 -228
  587. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +0 -732
  588. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +0 -316
  589. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +0 -1167
  590. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +0 -65
  591. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +0 -51
  592. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +0 -125
  593. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +0 -49
  594. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +0 -54
  595. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +0 -136
  596. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +0 -63
  597. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +0 -145
  598. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +0 -53
  599. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +0 -133
  600. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +0 -88
  601. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +0 -258
  602. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +0 -86
  603. data/src/core/ext/upb-generated/envoy/type/range.upb.h +0 -111
  604. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +0 -61
  605. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +0 -89
  606. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +0 -250
  607. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +0 -17
  608. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -29
  609. data/src/core/lib/security/transport/target_authority_table.cc +0 -75
  610. data/src/core/lib/security/transport/target_authority_table.h +0 -40
  611. data/src/core/lib/slice/slice_hash_table.h +0 -199
  612. data/src/core/lib/slice/slice_weak_hash_table.h +0 -102
  613. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_pku.c +0 -110
  614. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_sxnet.c +0 -274
@@ -1,2110 +0,0 @@
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 <cstdlib>
24
-
25
- #include "absl/strings/str_cat.h"
26
- #include "absl/strings/str_format.h"
27
- #include "absl/strings/str_join.h"
28
- #include "absl/strings/str_split.h"
29
-
30
- #include "upb/upb.hpp"
31
-
32
- #include <grpc/impl/codegen/log.h>
33
- #include <grpc/support/alloc.h>
34
- #include <grpc/support/string_util.h>
35
-
36
- #include "src/core/ext/filters/client_channel/xds/xds_api.h"
37
- #include "src/core/lib/gpr/env.h"
38
- #include "src/core/lib/gpr/string.h"
39
- #include "src/core/lib/gpr/useful.h"
40
- #include "src/core/lib/iomgr/error.h"
41
- #include "src/core/lib/iomgr/sockaddr_utils.h"
42
-
43
- #include "envoy/api/v2/cds.upb.h"
44
- #include "envoy/api/v2/core/address.upb.h"
45
- #include "envoy/api/v2/core/base.upb.h"
46
- #include "envoy/api/v2/core/config_source.upb.h"
47
- #include "envoy/api/v2/core/health_check.upb.h"
48
- #include "envoy/api/v2/discovery.upb.h"
49
- #include "envoy/api/v2/eds.upb.h"
50
- #include "envoy/api/v2/endpoint/endpoint.upb.h"
51
- #include "envoy/api/v2/endpoint/load_report.upb.h"
52
- #include "envoy/api/v2/lds.upb.h"
53
- #include "envoy/api/v2/rds.upb.h"
54
- #include "envoy/api/v2/route/route.upb.h"
55
- #include "envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h"
56
- #include "envoy/config/listener/v2/api_listener.upb.h"
57
- #include "envoy/service/load_stats/v2/lrs.upb.h"
58
- #include "envoy/type/matcher/regex.upb.h"
59
- #include "envoy/type/percent.upb.h"
60
- #include "envoy/type/range.upb.h"
61
- #include "google/protobuf/any.upb.h"
62
- #include "google/protobuf/duration.upb.h"
63
- #include "google/protobuf/struct.upb.h"
64
- #include "google/protobuf/wrappers.upb.h"
65
- #include "google/rpc/status.upb.h"
66
- #include "upb/upb.h"
67
-
68
- namespace grpc_core {
69
-
70
- //
71
- // XdsApi::PriorityListUpdate
72
- //
73
-
74
- bool XdsApi::PriorityListUpdate::operator==(
75
- const XdsApi::PriorityListUpdate& other) const {
76
- if (priorities_.size() != other.priorities_.size()) return false;
77
- for (size_t i = 0; i < priorities_.size(); ++i) {
78
- if (priorities_[i].localities != other.priorities_[i].localities) {
79
- return false;
80
- }
81
- }
82
- return true;
83
- }
84
-
85
- void XdsApi::PriorityListUpdate::Add(
86
- XdsApi::PriorityListUpdate::LocalityMap::Locality locality) {
87
- // Pad the missing priorities in case the localities are not ordered by
88
- // priority.
89
- if (!Contains(locality.priority)) priorities_.resize(locality.priority + 1);
90
- LocalityMap& locality_map = priorities_[locality.priority];
91
- locality_map.localities.emplace(locality.name, std::move(locality));
92
- }
93
-
94
- const XdsApi::PriorityListUpdate::LocalityMap* XdsApi::PriorityListUpdate::Find(
95
- uint32_t priority) const {
96
- if (!Contains(priority)) return nullptr;
97
- return &priorities_[priority];
98
- }
99
-
100
- bool XdsApi::PriorityListUpdate::Contains(
101
- const RefCountedPtr<XdsLocalityName>& name) {
102
- for (size_t i = 0; i < priorities_.size(); ++i) {
103
- const LocalityMap& locality_map = priorities_[i];
104
- if (locality_map.Contains(name)) return true;
105
- }
106
- return false;
107
- }
108
-
109
- //
110
- // XdsApi::DropConfig
111
- //
112
-
113
- bool XdsApi::DropConfig::ShouldDrop(const std::string** category_name) const {
114
- for (size_t i = 0; i < drop_category_list_.size(); ++i) {
115
- const auto& drop_category = drop_category_list_[i];
116
- // Generate a random number in [0, 1000000).
117
- const uint32_t random = static_cast<uint32_t>(rand()) % 1000000;
118
- if (random < drop_category.parts_per_million) {
119
- *category_name = &drop_category.name;
120
- return true;
121
- }
122
- }
123
- return false;
124
- }
125
-
126
- //
127
- // XdsApi
128
- //
129
-
130
- const char* XdsApi::kLdsTypeUrl = "type.googleapis.com/envoy.api.v2.Listener";
131
- const char* XdsApi::kRdsTypeUrl =
132
- "type.googleapis.com/envoy.api.v2.RouteConfiguration";
133
- const char* XdsApi::kCdsTypeUrl = "type.googleapis.com/envoy.api.v2.Cluster";
134
- const char* XdsApi::kEdsTypeUrl =
135
- "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment";
136
-
137
- std::string XdsApi::RdsUpdate::RdsRoute::Matchers::PathMatcher::ToString()
138
- const {
139
- std::string path_type_string;
140
- switch (type) {
141
- case PathMatcherType::PATH:
142
- path_type_string = "path match";
143
- break;
144
- case PathMatcherType::PREFIX:
145
- path_type_string = "prefix match";
146
- break;
147
- case PathMatcherType::REGEX:
148
- path_type_string = "regex match";
149
- break;
150
- default:
151
- break;
152
- }
153
- return absl::StrFormat("Path %s:/%s/", path_type_string,
154
- type == PathMatcherType::REGEX
155
- ? regex_matcher->pattern()
156
- : string_matcher);
157
- }
158
-
159
- std::string XdsApi::RdsUpdate::RdsRoute::Matchers::HeaderMatcher::ToString()
160
- const {
161
- switch (type) {
162
- case HeaderMatcherType::EXACT:
163
- return absl::StrFormat("Header exact match:%s %s:%s",
164
- invert_match ? " not" : "", name, string_matcher);
165
- case HeaderMatcherType::REGEX:
166
- return absl::StrFormat("Header regex match:%s %s:%s",
167
- invert_match ? " not" : "", name,
168
- regex_match->pattern());
169
- case HeaderMatcherType::RANGE:
170
- return absl::StrFormat("Header range match:%s %s:[%d, %d)",
171
- invert_match ? " not" : "", name, range_start,
172
- range_end);
173
- case HeaderMatcherType::PRESENT:
174
- return absl::StrFormat("Header present match:%s %s:%s",
175
- invert_match ? " not" : "", name,
176
- present_match ? "true" : "false");
177
- case HeaderMatcherType::PREFIX:
178
- return absl::StrFormat("Header prefix match:%s %s:%s",
179
- invert_match ? " not" : "", name, string_matcher);
180
- case HeaderMatcherType::SUFFIX:
181
- return absl::StrFormat("Header suffix match:%s %s:%s",
182
- invert_match ? " not" : "", name, string_matcher);
183
- default:
184
- return "";
185
- }
186
- }
187
-
188
- std::string XdsApi::RdsUpdate::RdsRoute::Matchers::ToString() const {
189
- std::vector<std::string> contents;
190
- contents.push_back(path_matcher.ToString());
191
- for (const auto& header_it : header_matchers) {
192
- contents.push_back(header_it.ToString());
193
- }
194
- if (fraction_per_million.has_value()) {
195
- contents.push_back(absl::StrFormat("Fraction Per Million %d",
196
- fraction_per_million.value()));
197
- }
198
- return absl::StrJoin(contents, "\n");
199
- }
200
-
201
- std::string XdsApi::RdsUpdate::RdsRoute::ClusterWeight::ToString() const {
202
- return absl::StrFormat("{cluster=%s, weight=%d}", name, weight);
203
- }
204
-
205
- std::string XdsApi::RdsUpdate::RdsRoute::ToString() const {
206
- std::vector<std::string> contents;
207
- contents.push_back(matchers.ToString());
208
- if (!cluster_name.empty()) {
209
- contents.push_back(absl::StrFormat("Cluster name: %s", cluster_name));
210
- }
211
- for (const auto& weighted_it : weighted_clusters) {
212
- contents.push_back(weighted_it.ToString());
213
- }
214
- return absl::StrJoin(contents, "\n");
215
- }
216
-
217
- std::string XdsApi::RdsUpdate::ToString() const {
218
- std::vector<std::string> contents;
219
- for (const auto& route_it : routes) {
220
- contents.push_back(route_it.ToString());
221
- }
222
- return absl::StrJoin(contents, ",\n");
223
- }
224
-
225
- XdsApi::XdsApi(XdsClient* client, TraceFlag* tracer,
226
- const XdsBootstrap::Node* node)
227
- : client_(client),
228
- tracer_(tracer),
229
- node_(node),
230
- build_version_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING, " ",
231
- grpc_version_string())),
232
- user_agent_name_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING)) {}
233
-
234
- namespace {
235
-
236
- void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
237
- const Json& value);
238
-
239
- void PopulateListValue(upb_arena* arena, google_protobuf_ListValue* list_value,
240
- const Json::Array& values) {
241
- for (const auto& value : values) {
242
- auto* value_pb = google_protobuf_ListValue_add_values(list_value, arena);
243
- PopulateMetadataValue(arena, value_pb, value);
244
- }
245
- }
246
-
247
- void PopulateMetadata(upb_arena* arena, google_protobuf_Struct* metadata_pb,
248
- const Json::Object& metadata) {
249
- for (const auto& p : metadata) {
250
- google_protobuf_Value* value = google_protobuf_Value_new(arena);
251
- PopulateMetadataValue(arena, value, p.second);
252
- google_protobuf_Struct_fields_set(
253
- metadata_pb, upb_strview_makez(p.first.c_str()), value, arena);
254
- }
255
- }
256
-
257
- void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
258
- const Json& value) {
259
- switch (value.type()) {
260
- case Json::Type::JSON_NULL:
261
- google_protobuf_Value_set_null_value(value_pb, 0);
262
- break;
263
- case Json::Type::NUMBER:
264
- google_protobuf_Value_set_number_value(
265
- value_pb, strtod(value.string_value().c_str(), nullptr));
266
- break;
267
- case Json::Type::STRING:
268
- google_protobuf_Value_set_string_value(
269
- value_pb, upb_strview_makez(value.string_value().c_str()));
270
- break;
271
- case Json::Type::JSON_TRUE:
272
- google_protobuf_Value_set_bool_value(value_pb, true);
273
- break;
274
- case Json::Type::JSON_FALSE:
275
- google_protobuf_Value_set_bool_value(value_pb, false);
276
- break;
277
- case Json::Type::OBJECT: {
278
- google_protobuf_Struct* struct_value =
279
- google_protobuf_Value_mutable_struct_value(value_pb, arena);
280
- PopulateMetadata(arena, struct_value, value.object_value());
281
- break;
282
- }
283
- case Json::Type::ARRAY: {
284
- google_protobuf_ListValue* list_value =
285
- google_protobuf_Value_mutable_list_value(value_pb, arena);
286
- PopulateListValue(arena, list_value, value.array_value());
287
- break;
288
- }
289
- }
290
- }
291
-
292
- void PopulateNode(upb_arena* arena, const XdsBootstrap::Node* node,
293
- const std::string& build_version,
294
- const std::string& user_agent_name,
295
- const std::string& server_name,
296
- envoy_api_v2_core_Node* node_msg) {
297
- if (node != nullptr) {
298
- if (!node->id.empty()) {
299
- envoy_api_v2_core_Node_set_id(node_msg,
300
- upb_strview_makez(node->id.c_str()));
301
- }
302
- if (!node->cluster.empty()) {
303
- envoy_api_v2_core_Node_set_cluster(
304
- node_msg, upb_strview_makez(node->cluster.c_str()));
305
- }
306
- if (!node->metadata.object_value().empty()) {
307
- google_protobuf_Struct* metadata =
308
- envoy_api_v2_core_Node_mutable_metadata(node_msg, arena);
309
- PopulateMetadata(arena, metadata, node->metadata.object_value());
310
- }
311
- if (!server_name.empty()) {
312
- google_protobuf_Struct* metadata =
313
- envoy_api_v2_core_Node_mutable_metadata(node_msg, arena);
314
- google_protobuf_Value* value = google_protobuf_Value_new(arena);
315
- google_protobuf_Value_set_string_value(
316
- value, upb_strview_make(server_name.data(), server_name.size()));
317
- google_protobuf_Struct_fields_set(
318
- metadata, upb_strview_makez("PROXYLESS_CLIENT_HOSTNAME"), value,
319
- arena);
320
- }
321
- if (!node->locality_region.empty() || !node->locality_zone.empty() ||
322
- !node->locality_subzone.empty()) {
323
- envoy_api_v2_core_Locality* locality =
324
- envoy_api_v2_core_Node_mutable_locality(node_msg, arena);
325
- if (!node->locality_region.empty()) {
326
- envoy_api_v2_core_Locality_set_region(
327
- locality, upb_strview_makez(node->locality_region.c_str()));
328
- }
329
- if (!node->locality_zone.empty()) {
330
- envoy_api_v2_core_Locality_set_zone(
331
- locality, upb_strview_makez(node->locality_zone.c_str()));
332
- }
333
- if (!node->locality_subzone.empty()) {
334
- envoy_api_v2_core_Locality_set_sub_zone(
335
- locality, upb_strview_makez(node->locality_subzone.c_str()));
336
- }
337
- }
338
- }
339
- envoy_api_v2_core_Node_set_build_version(
340
- node_msg, upb_strview_make(build_version.data(), build_version.size()));
341
- envoy_api_v2_core_Node_set_user_agent_name(
342
- node_msg,
343
- upb_strview_make(user_agent_name.data(), user_agent_name.size()));
344
- envoy_api_v2_core_Node_set_user_agent_version(
345
- node_msg, upb_strview_makez(grpc_version_string()));
346
- envoy_api_v2_core_Node_add_client_features(
347
- node_msg, upb_strview_makez("envoy.lb.does_not_support_overprovisioning"),
348
- arena);
349
- }
350
-
351
- inline absl::string_view UpbStringToAbsl(const upb_strview& str) {
352
- return absl::string_view(str.data, str.size);
353
- }
354
-
355
- inline std::string UpbStringToStdString(const upb_strview& str) {
356
- return std::string(str.data, str.size);
357
- }
358
-
359
- inline void AddStringField(const char* name, const upb_strview& value,
360
- std::vector<std::string>* fields,
361
- bool add_if_empty = false) {
362
- if (value.size > 0 || add_if_empty) {
363
- fields->emplace_back(
364
- absl::StrCat(name, ": \"", UpbStringToAbsl(value), "\""));
365
- }
366
- }
367
-
368
- inline void AddUInt32ValueField(const char* name,
369
- const google_protobuf_UInt32Value* value,
370
- std::vector<std::string>* fields) {
371
- if (value != nullptr) {
372
- fields->emplace_back(absl::StrCat(
373
- name, " { value: ", google_protobuf_UInt32Value_value(value), " }"));
374
- }
375
- }
376
-
377
- inline void AddLocalityField(int indent_level,
378
- const envoy_api_v2_core_Locality* locality,
379
- std::vector<std::string>* fields) {
380
- std::string indent =
381
- absl::StrJoin(std::vector<std::string>(indent_level, " "), "");
382
- // region
383
- std::string field = absl::StrCat(indent, "region");
384
- AddStringField(field.c_str(), envoy_api_v2_core_Locality_region(locality),
385
- fields);
386
- // zone
387
- field = absl::StrCat(indent, "zone");
388
- AddStringField(field.c_str(), envoy_api_v2_core_Locality_zone(locality),
389
- fields);
390
- // sub_zone
391
- field = absl::StrCat(indent, "sub_zone");
392
- AddStringField(field.c_str(), envoy_api_v2_core_Locality_sub_zone(locality),
393
- fields);
394
- }
395
-
396
- void AddNodeLogFields(const envoy_api_v2_core_Node* node,
397
- std::vector<std::string>* fields) {
398
- fields->emplace_back("node {");
399
- // id
400
- AddStringField(" id", envoy_api_v2_core_Node_id(node), fields);
401
- // metadata
402
- const google_protobuf_Struct* metadata =
403
- envoy_api_v2_core_Node_metadata(node);
404
- if (metadata != nullptr) {
405
- fields->emplace_back(" metadata {");
406
- size_t entry_idx = UPB_MAP_BEGIN;
407
- while (true) {
408
- const google_protobuf_Struct_FieldsEntry* entry =
409
- google_protobuf_Struct_fields_next(metadata, &entry_idx);
410
- if (entry == nullptr) break;
411
- fields->emplace_back(" field {");
412
- // key
413
- AddStringField(" key", google_protobuf_Struct_FieldsEntry_key(entry),
414
- fields);
415
- // value
416
- const google_protobuf_Value* value =
417
- google_protobuf_Struct_FieldsEntry_value(entry);
418
- if (value != nullptr) {
419
- std::string value_str;
420
- if (google_protobuf_Value_has_string_value(value)) {
421
- value_str = absl::StrCat(
422
- "string_value: \"",
423
- UpbStringToAbsl(google_protobuf_Value_string_value(value)), "\"");
424
- } else if (google_protobuf_Value_has_null_value(value)) {
425
- value_str = "null_value: NULL_VALUE";
426
- } else if (google_protobuf_Value_has_number_value(value)) {
427
- value_str = absl::StrCat("double_value: ",
428
- google_protobuf_Value_number_value(value));
429
- } else if (google_protobuf_Value_has_bool_value(value)) {
430
- value_str = absl::StrCat("bool_value: ",
431
- google_protobuf_Value_bool_value(value));
432
- } else if (google_protobuf_Value_has_struct_value(value)) {
433
- value_str = "struct_value: <not printed>";
434
- } else if (google_protobuf_Value_has_list_value(value)) {
435
- value_str = "list_value: <not printed>";
436
- } else {
437
- value_str = "<unknown>";
438
- }
439
- fields->emplace_back(absl::StrCat(" value { ", value_str, " }"));
440
- }
441
- fields->emplace_back(" }");
442
- }
443
- fields->emplace_back(" }");
444
- }
445
- // locality
446
- const envoy_api_v2_core_Locality* locality =
447
- envoy_api_v2_core_Node_locality(node);
448
- if (locality != nullptr) {
449
- fields->emplace_back(" locality {");
450
- AddLocalityField(2, locality, fields);
451
- fields->emplace_back(" }");
452
- }
453
- // build_version
454
- AddStringField(" build_version", envoy_api_v2_core_Node_build_version(node),
455
- fields);
456
- // user_agent_name
457
- AddStringField(" user_agent_name",
458
- envoy_api_v2_core_Node_user_agent_name(node), fields);
459
- // user_agent_version
460
- AddStringField(" user_agent_version",
461
- envoy_api_v2_core_Node_user_agent_version(node), fields);
462
- // client_features
463
- size_t num_client_features;
464
- const upb_strview* client_features =
465
- envoy_api_v2_core_Node_client_features(node, &num_client_features);
466
- for (size_t i = 0; i < num_client_features; ++i) {
467
- AddStringField(" client_features", client_features[i], fields);
468
- }
469
- fields->emplace_back("}");
470
- }
471
-
472
- void MaybeLogDiscoveryRequest(XdsClient* client, TraceFlag* tracer,
473
- const envoy_api_v2_DiscoveryRequest* request) {
474
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
475
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
476
- // TODO(roth): When we can upgrade upb, use upb textformat code to dump
477
- // the raw proto instead of doing this manually.
478
- std::vector<std::string> fields;
479
- // version_info
480
- AddStringField("version_info",
481
- envoy_api_v2_DiscoveryRequest_version_info(request),
482
- &fields);
483
- // node
484
- const envoy_api_v2_core_Node* node =
485
- envoy_api_v2_DiscoveryRequest_node(request);
486
- if (node != nullptr) AddNodeLogFields(node, &fields);
487
- // resource_names
488
- size_t num_resource_names;
489
- const upb_strview* resource_names =
490
- envoy_api_v2_DiscoveryRequest_resource_names(request,
491
- &num_resource_names);
492
- for (size_t i = 0; i < num_resource_names; ++i) {
493
- AddStringField("resource_names", resource_names[i], &fields);
494
- }
495
- // type_url
496
- AddStringField("type_url", envoy_api_v2_DiscoveryRequest_type_url(request),
497
- &fields);
498
- // response_nonce
499
- AddStringField("response_nonce",
500
- envoy_api_v2_DiscoveryRequest_response_nonce(request),
501
- &fields);
502
- // error_detail
503
- const struct google_rpc_Status* error_detail =
504
- envoy_api_v2_DiscoveryRequest_error_detail(request);
505
- if (error_detail != nullptr) {
506
- fields.emplace_back("error_detail {");
507
- // code
508
- int32_t code = google_rpc_Status_code(error_detail);
509
- if (code != 0) fields.emplace_back(absl::StrCat(" code: ", code));
510
- // message
511
- AddStringField(" message", google_rpc_Status_message(error_detail),
512
- &fields);
513
- fields.emplace_back("}");
514
- }
515
- gpr_log(GPR_DEBUG, "[xds_client %p] constructed ADS request: %s", client,
516
- absl::StrJoin(fields, "\n").c_str());
517
- }
518
- }
519
-
520
- grpc_slice SerializeDiscoveryRequest(upb_arena* arena,
521
- envoy_api_v2_DiscoveryRequest* request) {
522
- size_t output_length;
523
- char* output =
524
- envoy_api_v2_DiscoveryRequest_serialize(request, arena, &output_length);
525
- return grpc_slice_from_copied_buffer(output, output_length);
526
- }
527
-
528
- } // namespace
529
-
530
- grpc_slice XdsApi::CreateAdsRequest(
531
- const std::string& type_url,
532
- const std::set<absl::string_view>& resource_names,
533
- const std::string& version, const std::string& nonce, grpc_error* error,
534
- bool populate_node) {
535
- upb::Arena arena;
536
- // Create a request.
537
- envoy_api_v2_DiscoveryRequest* request =
538
- envoy_api_v2_DiscoveryRequest_new(arena.ptr());
539
- // Set type_url.
540
- envoy_api_v2_DiscoveryRequest_set_type_url(
541
- request, upb_strview_make(type_url.data(), type_url.size()));
542
- // Set version_info.
543
- if (!version.empty()) {
544
- envoy_api_v2_DiscoveryRequest_set_version_info(
545
- request, upb_strview_make(version.data(), version.size()));
546
- }
547
- // Set nonce.
548
- if (!nonce.empty()) {
549
- envoy_api_v2_DiscoveryRequest_set_response_nonce(
550
- request, upb_strview_make(nonce.data(), nonce.size()));
551
- }
552
- // Set error_detail if it's a NACK.
553
- if (error != GRPC_ERROR_NONE) {
554
- grpc_slice error_description_slice;
555
- GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION,
556
- &error_description_slice));
557
- upb_strview error_description_strview =
558
- upb_strview_make(reinterpret_cast<const char*>(
559
- GPR_SLICE_START_PTR(error_description_slice)),
560
- GPR_SLICE_LENGTH(error_description_slice));
561
- google_rpc_Status* error_detail =
562
- envoy_api_v2_DiscoveryRequest_mutable_error_detail(request,
563
- arena.ptr());
564
- google_rpc_Status_set_message(error_detail, error_description_strview);
565
- GRPC_ERROR_UNREF(error);
566
- }
567
- // Populate node.
568
- if (populate_node) {
569
- envoy_api_v2_core_Node* node_msg =
570
- envoy_api_v2_DiscoveryRequest_mutable_node(request, arena.ptr());
571
- PopulateNode(arena.ptr(), node_, build_version_, user_agent_name_, "",
572
- node_msg);
573
- }
574
- // Add resource_names.
575
- for (const auto& resource_name : resource_names) {
576
- envoy_api_v2_DiscoveryRequest_add_resource_names(
577
- request, upb_strview_make(resource_name.data(), resource_name.size()),
578
- arena.ptr());
579
- }
580
- MaybeLogDiscoveryRequest(client_, tracer_, request);
581
- return SerializeDiscoveryRequest(arena.ptr(), request);
582
- }
583
-
584
- namespace {
585
-
586
- void MaybeLogDiscoveryResponse(XdsClient* client, TraceFlag* tracer,
587
- const envoy_api_v2_DiscoveryResponse* response) {
588
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
589
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
590
- // TODO(roth): When we can upgrade upb, use upb textformat code to dump
591
- // the raw proto instead of doing this manually.
592
- std::vector<std::string> fields;
593
- // version_info
594
- AddStringField("version_info",
595
- envoy_api_v2_DiscoveryResponse_version_info(response),
596
- &fields);
597
- // resources
598
- size_t num_resources;
599
- envoy_api_v2_DiscoveryResponse_resources(response, &num_resources);
600
- fields.emplace_back(
601
- absl::StrCat("resources: <", num_resources, " element(s)>"));
602
- // type_url
603
- AddStringField("type_url",
604
- envoy_api_v2_DiscoveryResponse_type_url(response), &fields);
605
- // nonce
606
- AddStringField("nonce", envoy_api_v2_DiscoveryResponse_nonce(response),
607
- &fields);
608
- gpr_log(GPR_DEBUG, "[xds_client %p] received response: %s", client,
609
- absl::StrJoin(fields, "\n").c_str());
610
- }
611
- }
612
-
613
- void MaybeLogRouteConfiguration(
614
- XdsClient* client, TraceFlag* tracer,
615
- const envoy_api_v2_RouteConfiguration* route_config) {
616
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
617
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
618
- // TODO(roth): When we can upgrade upb, use upb textformat code to dump
619
- // the raw proto instead of doing this manually.
620
- std::vector<std::string> fields;
621
- // name
622
- AddStringField("name", envoy_api_v2_RouteConfiguration_name(route_config),
623
- &fields);
624
- // virtual_hosts
625
- size_t num_virtual_hosts;
626
- const envoy_api_v2_route_VirtualHost* const* virtual_hosts =
627
- envoy_api_v2_RouteConfiguration_virtual_hosts(route_config,
628
- &num_virtual_hosts);
629
- for (size_t i = 0; i < num_virtual_hosts; ++i) {
630
- const auto* virtual_host = virtual_hosts[i];
631
- fields.push_back("virtual_hosts {");
632
- // name
633
- AddStringField(
634
- " name", envoy_api_v2_route_VirtualHost_name(virtual_host), &fields);
635
- // domains
636
- size_t num_domains;
637
- const upb_strview* const domains =
638
- envoy_api_v2_route_VirtualHost_domains(virtual_host, &num_domains);
639
- for (size_t j = 0; j < num_domains; ++j) {
640
- AddStringField(" domains", domains[j], &fields);
641
- }
642
- // routes
643
- size_t num_routes;
644
- const envoy_api_v2_route_Route* const* routes =
645
- envoy_api_v2_route_VirtualHost_routes(virtual_host, &num_routes);
646
- for (size_t j = 0; j < num_routes; ++j) {
647
- const auto* route = routes[j];
648
- fields.push_back(" route {");
649
- // name
650
- AddStringField(" name", envoy_api_v2_route_Route_name(route),
651
- &fields);
652
- // match
653
- const envoy_api_v2_route_RouteMatch* match =
654
- envoy_api_v2_route_Route_match(route);
655
- if (match != nullptr) {
656
- fields.emplace_back(" match {");
657
- // path matching
658
- if (envoy_api_v2_route_RouteMatch_has_prefix(match)) {
659
- AddStringField(" prefix",
660
- envoy_api_v2_route_RouteMatch_prefix(match), &fields,
661
- /*add_if_empty=*/true);
662
- } else if (envoy_api_v2_route_RouteMatch_has_path(match)) {
663
- AddStringField(" path",
664
- envoy_api_v2_route_RouteMatch_path(match), &fields,
665
- /*add_if_empty=*/true);
666
- } else if (envoy_api_v2_route_RouteMatch_has_regex(match)) {
667
- AddStringField(" regex",
668
- envoy_api_v2_route_RouteMatch_regex(match), &fields,
669
- /*add_if_empty=*/true);
670
- } else if (envoy_api_v2_route_RouteMatch_has_safe_regex(match)) {
671
- fields.emplace_back(" safe_regex: <not printed>");
672
- } else {
673
- fields.emplace_back(" <unknown path matching type>");
674
- }
675
- // header matching
676
- size_t num_headers;
677
- envoy_api_v2_route_RouteMatch_headers(match, &num_headers);
678
- if (num_headers > 0) {
679
- fields.emplace_back(
680
- absl::StrCat(" headers: <", num_headers, " element(s)>"));
681
- }
682
- fields.emplace_back(" }");
683
- }
684
- // action
685
- if (envoy_api_v2_route_Route_has_route(route)) {
686
- const envoy_api_v2_route_RouteAction* action =
687
- envoy_api_v2_route_Route_route(route);
688
- fields.emplace_back(" route {");
689
- if (envoy_api_v2_route_RouteAction_has_cluster(action)) {
690
- AddStringField(" cluster",
691
- envoy_api_v2_route_RouteAction_cluster(action),
692
- &fields);
693
- } else if (envoy_api_v2_route_RouteAction_has_cluster_header(
694
- action)) {
695
- AddStringField(
696
- " cluster_header",
697
- envoy_api_v2_route_RouteAction_cluster_header(action), &fields);
698
- } else if (envoy_api_v2_route_RouteAction_has_weighted_clusters(
699
- action)) {
700
- const envoy_api_v2_route_WeightedCluster* weighted_clusters =
701
- envoy_api_v2_route_RouteAction_weighted_clusters(action);
702
- fields.emplace_back(" weighted_clusters {");
703
- size_t num_cluster_weights;
704
- const envoy_api_v2_route_WeightedCluster_ClusterWeight* const*
705
- cluster_weights = envoy_api_v2_route_WeightedCluster_clusters(
706
- weighted_clusters, &num_cluster_weights);
707
- for (size_t i = 0; i < num_cluster_weights; ++i) {
708
- const envoy_api_v2_route_WeightedCluster_ClusterWeight*
709
- cluster_weight = cluster_weights[i];
710
- fields.emplace_back(" clusters {");
711
- AddStringField(
712
- " name",
713
- envoy_api_v2_route_WeightedCluster_ClusterWeight_name(
714
- cluster_weight),
715
- &fields);
716
- AddUInt32ValueField(
717
- " weight",
718
- envoy_api_v2_route_WeightedCluster_ClusterWeight_weight(
719
- cluster_weight),
720
- &fields);
721
- fields.emplace_back(" }");
722
- }
723
- AddUInt32ValueField(" total_weight",
724
- envoy_api_v2_route_WeightedCluster_total_weight(
725
- weighted_clusters),
726
- &fields);
727
- fields.emplace_back(" }");
728
- }
729
- fields.emplace_back(" }");
730
- } else if (envoy_api_v2_route_Route_has_redirect(route)) {
731
- fields.emplace_back(" redirect: <not printed>");
732
- } else if (envoy_api_v2_route_Route_has_direct_response(route)) {
733
- fields.emplace_back(" direct_response: <not printed>");
734
- } else if (envoy_api_v2_route_Route_has_filter_action(route)) {
735
- fields.emplace_back(" filter_action: <not printed>");
736
- }
737
- fields.push_back(" }");
738
- }
739
- fields.push_back("}");
740
- }
741
- gpr_log(GPR_DEBUG, "[xds_client %p] RouteConfiguration: %s", client,
742
- absl::StrJoin(fields, "\n").c_str());
743
- }
744
- }
745
-
746
- void MaybeLogCluster(XdsClient* client, TraceFlag* tracer,
747
- const envoy_api_v2_Cluster* cluster) {
748
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
749
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
750
- // TODO(roth): When we can upgrade upb, use upb textformat code to dump
751
- // the raw proto instead of doing this manually.
752
- std::vector<std::string> fields;
753
- // name
754
- AddStringField("name", envoy_api_v2_Cluster_name(cluster), &fields);
755
- // type
756
- if (envoy_api_v2_Cluster_has_type(cluster)) {
757
- fields.emplace_back(
758
- absl::StrCat("type: ", envoy_api_v2_Cluster_type(cluster)));
759
- } else if (envoy_api_v2_Cluster_has_cluster_type(cluster)) {
760
- fields.emplace_back("cluster_type: <not printed>");
761
- } else {
762
- fields.emplace_back("<unknown type>");
763
- }
764
- // eds_cluster_config
765
- const envoy_api_v2_Cluster_EdsClusterConfig* eds_cluster_config =
766
- envoy_api_v2_Cluster_eds_cluster_config(cluster);
767
- if (eds_cluster_config != nullptr) {
768
- fields.emplace_back("eds_cluster_config {");
769
- // eds_config
770
- const struct envoy_api_v2_core_ConfigSource* eds_config =
771
- envoy_api_v2_Cluster_EdsClusterConfig_eds_config(eds_cluster_config);
772
- if (eds_config != nullptr) {
773
- if (envoy_api_v2_core_ConfigSource_has_ads(eds_config)) {
774
- fields.emplace_back(" eds_config { ads {} }");
775
- } else {
776
- fields.emplace_back(" eds_config: <non-ADS type>");
777
- }
778
- }
779
- // service_name
780
- AddStringField(" service_name",
781
- envoy_api_v2_Cluster_EdsClusterConfig_service_name(
782
- eds_cluster_config),
783
- &fields);
784
- fields.emplace_back("}");
785
- }
786
- // lb_policy
787
- fields.emplace_back(
788
- absl::StrCat("lb_policy: ", envoy_api_v2_Cluster_lb_policy(cluster)));
789
- // lrs_server
790
- const envoy_api_v2_core_ConfigSource* lrs_server =
791
- envoy_api_v2_Cluster_lrs_server(cluster);
792
- if (lrs_server != nullptr) {
793
- if (envoy_api_v2_core_ConfigSource_has_self(lrs_server)) {
794
- fields.emplace_back("lrs_server { self {} }");
795
- } else {
796
- fields.emplace_back("lrs_server: <non-self type>");
797
- }
798
- }
799
- gpr_log(GPR_DEBUG, "[xds_client %p] Cluster: %s", client,
800
- absl::StrJoin(fields, "\n").c_str());
801
- }
802
- }
803
-
804
- void MaybeLogClusterLoadAssignment(
805
- XdsClient* client, TraceFlag* tracer,
806
- const envoy_api_v2_ClusterLoadAssignment* cla) {
807
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
808
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
809
- // TODO(roth): When we can upgrade upb, use upb textformat code to dump
810
- // the raw proto instead of doing this manually.
811
- std::vector<std::string> fields;
812
- // cluster_name
813
- AddStringField("cluster_name",
814
- envoy_api_v2_ClusterLoadAssignment_cluster_name(cla),
815
- &fields);
816
- // endpoints
817
- size_t num_localities;
818
- const struct envoy_api_v2_endpoint_LocalityLbEndpoints* const*
819
- locality_endpoints =
820
- envoy_api_v2_ClusterLoadAssignment_endpoints(cla, &num_localities);
821
- for (size_t i = 0; i < num_localities; ++i) {
822
- const auto* locality_endpoint = locality_endpoints[i];
823
- fields.emplace_back("endpoints {");
824
- // locality
825
- const auto* locality =
826
- envoy_api_v2_endpoint_LocalityLbEndpoints_locality(locality_endpoint);
827
- if (locality != nullptr) {
828
- fields.emplace_back(" locality {");
829
- AddLocalityField(2, locality, &fields);
830
- fields.emplace_back(" }");
831
- }
832
- // lb_endpoints
833
- size_t num_lb_endpoints;
834
- const envoy_api_v2_endpoint_LbEndpoint* const* lb_endpoints =
835
- envoy_api_v2_endpoint_LocalityLbEndpoints_lb_endpoints(
836
- locality_endpoint, &num_lb_endpoints);
837
- for (size_t j = 0; j < num_lb_endpoints; ++j) {
838
- const auto* lb_endpoint = lb_endpoints[j];
839
- fields.emplace_back(" lb_endpoints {");
840
- // health_status
841
- uint32_t health_status =
842
- envoy_api_v2_endpoint_LbEndpoint_health_status(lb_endpoint);
843
- if (health_status > 0) {
844
- fields.emplace_back(
845
- absl::StrCat(" health_status: ", health_status));
846
- }
847
- // endpoint
848
- const envoy_api_v2_endpoint_Endpoint* endpoint =
849
- envoy_api_v2_endpoint_LbEndpoint_endpoint(lb_endpoint);
850
- if (endpoint != nullptr) {
851
- fields.emplace_back(" endpoint {");
852
- // address
853
- const auto* address =
854
- envoy_api_v2_endpoint_Endpoint_address(endpoint);
855
- if (address != nullptr) {
856
- fields.emplace_back(" address {");
857
- // socket_address
858
- const auto* socket_address =
859
- envoy_api_v2_core_Address_socket_address(address);
860
- if (socket_address != nullptr) {
861
- fields.emplace_back(" socket_address {");
862
- // address
863
- AddStringField(
864
- " address",
865
- envoy_api_v2_core_SocketAddress_address(socket_address),
866
- &fields);
867
- // port_value
868
- if (envoy_api_v2_core_SocketAddress_has_port_value(
869
- socket_address)) {
870
- fields.emplace_back(
871
- absl::StrCat(" port_value: ",
872
- envoy_api_v2_core_SocketAddress_port_value(
873
- socket_address)));
874
- } else {
875
- fields.emplace_back(" <non-numeric port>");
876
- }
877
- fields.emplace_back(" }");
878
- } else {
879
- fields.emplace_back(" <non-socket address>");
880
- }
881
- fields.emplace_back(" }");
882
- }
883
- fields.emplace_back(" }");
884
- }
885
- fields.emplace_back(" }");
886
- }
887
- // load_balancing_weight
888
- AddUInt32ValueField(
889
- " load_balancing_weight",
890
- envoy_api_v2_endpoint_LocalityLbEndpoints_load_balancing_weight(
891
- locality_endpoint),
892
- &fields);
893
- // priority
894
- uint32_t priority =
895
- envoy_api_v2_endpoint_LocalityLbEndpoints_priority(locality_endpoint);
896
- if (priority > 0) {
897
- fields.emplace_back(absl::StrCat(" priority: ", priority));
898
- }
899
- fields.emplace_back("}");
900
- }
901
- // policy
902
- const envoy_api_v2_ClusterLoadAssignment_Policy* policy =
903
- envoy_api_v2_ClusterLoadAssignment_policy(cla);
904
- if (policy != nullptr) {
905
- fields.emplace_back("policy {");
906
- // drop_overloads
907
- size_t num_drop_overloads;
908
- const envoy_api_v2_ClusterLoadAssignment_Policy_DropOverload* const*
909
- drop_overloads =
910
- envoy_api_v2_ClusterLoadAssignment_Policy_drop_overloads(
911
- policy, &num_drop_overloads);
912
- for (size_t i = 0; i < num_drop_overloads; ++i) {
913
- auto* drop_overload = drop_overloads[i];
914
- fields.emplace_back(" drop_overloads {");
915
- // category
916
- AddStringField(
917
- " category",
918
- envoy_api_v2_ClusterLoadAssignment_Policy_DropOverload_category(
919
- drop_overload),
920
- &fields);
921
- // drop_percentage
922
- const auto* drop_percentage =
923
- envoy_api_v2_ClusterLoadAssignment_Policy_DropOverload_drop_percentage(
924
- drop_overload);
925
- if (drop_percentage != nullptr) {
926
- fields.emplace_back(" drop_percentage {");
927
- fields.emplace_back(absl::StrCat(
928
- " numerator: ",
929
- envoy_type_FractionalPercent_numerator(drop_percentage)));
930
- fields.emplace_back(absl::StrCat(
931
- " denominator: ",
932
- envoy_type_FractionalPercent_denominator(drop_percentage)));
933
- fields.emplace_back(" }");
934
- }
935
- fields.emplace_back(" }");
936
- }
937
- // overprovisioning_factor
938
- fields.emplace_back("}");
939
- }
940
- gpr_log(GPR_DEBUG, "[xds_client %p] ClusterLoadAssignment: %s", client,
941
- absl::StrJoin(fields, "\n").c_str());
942
- }
943
- }
944
-
945
- // Better match type has smaller value.
946
- enum MatchType {
947
- EXACT_MATCH,
948
- SUFFIX_MATCH,
949
- PREFIX_MATCH,
950
- UNIVERSE_MATCH,
951
- INVALID_MATCH,
952
- };
953
-
954
- // Returns true if match succeeds.
955
- bool DomainMatch(MatchType match_type, std::string domain_pattern,
956
- std::string expected_host_name) {
957
- // Normalize the args to lower-case. Domain matching is case-insensitive.
958
- std::transform(domain_pattern.begin(), domain_pattern.end(),
959
- domain_pattern.begin(),
960
- [](unsigned char c) { return std::tolower(c); });
961
- std::transform(expected_host_name.begin(), expected_host_name.end(),
962
- expected_host_name.begin(),
963
- [](unsigned char c) { return std::tolower(c); });
964
- if (match_type == EXACT_MATCH) {
965
- return domain_pattern == expected_host_name;
966
- } else if (match_type == SUFFIX_MATCH) {
967
- // Asterisk must match at least one char.
968
- if (expected_host_name.size() < domain_pattern.size()) return false;
969
- absl::string_view pattern_suffix(domain_pattern.c_str() + 1);
970
- absl::string_view host_suffix(expected_host_name.c_str() +
971
- expected_host_name.size() -
972
- pattern_suffix.size());
973
- return pattern_suffix == host_suffix;
974
- } else if (match_type == PREFIX_MATCH) {
975
- // Asterisk must match at least one char.
976
- if (expected_host_name.size() < domain_pattern.size()) return false;
977
- absl::string_view pattern_prefix(domain_pattern.c_str(),
978
- domain_pattern.size() - 1);
979
- absl::string_view host_prefix(expected_host_name.c_str(),
980
- pattern_prefix.size());
981
- return pattern_prefix == host_prefix;
982
- } else {
983
- return match_type == UNIVERSE_MATCH;
984
- }
985
- }
986
-
987
- MatchType DomainPatternMatchType(const std::string& domain_pattern) {
988
- if (domain_pattern.empty()) return INVALID_MATCH;
989
- if (domain_pattern.find('*') == std::string::npos) return EXACT_MATCH;
990
- if (domain_pattern == "*") return UNIVERSE_MATCH;
991
- if (domain_pattern[0] == '*') return SUFFIX_MATCH;
992
- if (domain_pattern[domain_pattern.size() - 1] == '*') return PREFIX_MATCH;
993
- return INVALID_MATCH;
994
- }
995
-
996
- grpc_error* RoutePathMatchParse(const envoy_api_v2_route_RouteMatch* match,
997
- XdsApi::RdsUpdate::RdsRoute* rds_route,
998
- bool* ignore_route) {
999
- if (envoy_api_v2_route_RouteMatch_has_prefix(match)) {
1000
- upb_strview prefix = envoy_api_v2_route_RouteMatch_prefix(match);
1001
- // Empty prefix "" is accepted.
1002
- if (prefix.size > 0) {
1003
- // Prefix "/" is accepted.
1004
- if (prefix.data[0] != '/') {
1005
- // Prefix which does not start with a / will never match anything, so
1006
- // ignore this route.
1007
- *ignore_route = true;
1008
- return GRPC_ERROR_NONE;
1009
- }
1010
- std::vector<absl::string_view> prefix_elements =
1011
- absl::StrSplit(absl::string_view(prefix.data, prefix.size).substr(1),
1012
- absl::MaxSplits('/', 2));
1013
- if (prefix_elements.size() > 2) {
1014
- // Prefix cannot have more than 2 slashes.
1015
- *ignore_route = true;
1016
- return GRPC_ERROR_NONE;
1017
- } else if (prefix_elements.size() == 2 && prefix_elements[0].empty()) {
1018
- // Prefix contains empty string between the 2 slashes
1019
- *ignore_route = true;
1020
- return GRPC_ERROR_NONE;
1021
- }
1022
- }
1023
- rds_route->matchers.path_matcher.type = XdsApi::RdsUpdate::RdsRoute::
1024
- Matchers::PathMatcher::PathMatcherType::PREFIX;
1025
- rds_route->matchers.path_matcher.string_matcher =
1026
- UpbStringToStdString(prefix);
1027
- } else if (envoy_api_v2_route_RouteMatch_has_path(match)) {
1028
- upb_strview path = envoy_api_v2_route_RouteMatch_path(match);
1029
- if (path.size == 0) {
1030
- // Path that is empty will never match anything, so ignore this route.
1031
- *ignore_route = true;
1032
- return GRPC_ERROR_NONE;
1033
- }
1034
- if (path.data[0] != '/') {
1035
- // Path which does not start with a / will never match anything, so
1036
- // ignore this route.
1037
- *ignore_route = true;
1038
- return GRPC_ERROR_NONE;
1039
- }
1040
- std::vector<absl::string_view> path_elements =
1041
- absl::StrSplit(absl::string_view(path.data, path.size).substr(1),
1042
- absl::MaxSplits('/', 2));
1043
- if (path_elements.size() != 2) {
1044
- // Path not in the required format of /service/method will never match
1045
- // anything, so ignore this route.
1046
- *ignore_route = true;
1047
- return GRPC_ERROR_NONE;
1048
- } else if (path_elements[0].empty()) {
1049
- // Path contains empty service name will never match anything, so ignore
1050
- // this route.
1051
- *ignore_route = true;
1052
- return GRPC_ERROR_NONE;
1053
- } else if (path_elements[1].empty()) {
1054
- // Path contains empty method name will never match anything, so ignore
1055
- // this route.
1056
- *ignore_route = true;
1057
- return GRPC_ERROR_NONE;
1058
- }
1059
- rds_route->matchers.path_matcher.type = XdsApi::RdsUpdate::RdsRoute::
1060
- Matchers::PathMatcher::PathMatcherType::PATH;
1061
- rds_route->matchers.path_matcher.string_matcher =
1062
- UpbStringToStdString(path);
1063
- } else if (envoy_api_v2_route_RouteMatch_has_safe_regex(match)) {
1064
- const envoy_type_matcher_RegexMatcher* regex_matcher =
1065
- envoy_api_v2_route_RouteMatch_safe_regex(match);
1066
- GPR_ASSERT(regex_matcher != nullptr);
1067
- const std::string matcher = UpbStringToStdString(
1068
- envoy_type_matcher_RegexMatcher_regex(regex_matcher));
1069
- std::unique_ptr<RE2> regex = absl::make_unique<RE2>(matcher);
1070
- if (!regex->ok()) {
1071
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1072
- "Invalid regex string specified in path matcher.");
1073
- }
1074
- rds_route->matchers.path_matcher.type = XdsApi::RdsUpdate::RdsRoute::
1075
- Matchers::PathMatcher::PathMatcherType::REGEX;
1076
- rds_route->matchers.path_matcher.regex_matcher = std::move(regex);
1077
- } else {
1078
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1079
- "Invalid route path specifier specified.");
1080
- }
1081
- return GRPC_ERROR_NONE;
1082
- }
1083
-
1084
- grpc_error* RouteHeaderMatchersParse(const envoy_api_v2_route_RouteMatch* match,
1085
- XdsApi::RdsUpdate::RdsRoute* rds_route) {
1086
- size_t size;
1087
- const envoy_api_v2_route_HeaderMatcher* const* headers =
1088
- envoy_api_v2_route_RouteMatch_headers(match, &size);
1089
- for (size_t i = 0; i < size; ++i) {
1090
- const envoy_api_v2_route_HeaderMatcher* header = headers[i];
1091
- XdsApi::RdsUpdate::RdsRoute::Matchers::HeaderMatcher header_matcher;
1092
- header_matcher.name =
1093
- UpbStringToStdString(envoy_api_v2_route_HeaderMatcher_name(header));
1094
- if (envoy_api_v2_route_HeaderMatcher_has_exact_match(header)) {
1095
- header_matcher.type = XdsApi::RdsUpdate::RdsRoute::Matchers::
1096
- HeaderMatcher::HeaderMatcherType::EXACT;
1097
- header_matcher.string_matcher = UpbStringToStdString(
1098
- envoy_api_v2_route_HeaderMatcher_exact_match(header));
1099
- } else if (envoy_api_v2_route_HeaderMatcher_has_safe_regex_match(header)) {
1100
- const envoy_type_matcher_RegexMatcher* regex_matcher =
1101
- envoy_api_v2_route_HeaderMatcher_safe_regex_match(header);
1102
- GPR_ASSERT(regex_matcher != nullptr);
1103
- const std::string matcher = UpbStringToStdString(
1104
- envoy_type_matcher_RegexMatcher_regex(regex_matcher));
1105
- std::unique_ptr<RE2> regex = absl::make_unique<RE2>(matcher);
1106
- if (!regex->ok()) {
1107
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1108
- "Invalid regex string specified in header matcher.");
1109
- }
1110
- header_matcher.type = XdsApi::RdsUpdate::RdsRoute::Matchers::
1111
- HeaderMatcher::HeaderMatcherType::REGEX;
1112
- header_matcher.regex_match = std::move(regex);
1113
- } else if (envoy_api_v2_route_HeaderMatcher_has_range_match(header)) {
1114
- header_matcher.type = XdsApi::RdsUpdate::RdsRoute::Matchers::
1115
- HeaderMatcher::HeaderMatcherType::RANGE;
1116
- const envoy_type_Int64Range* range_matcher =
1117
- envoy_api_v2_route_HeaderMatcher_range_match(header);
1118
- header_matcher.range_start = envoy_type_Int64Range_start(range_matcher);
1119
- header_matcher.range_end = envoy_type_Int64Range_end(range_matcher);
1120
- if (header_matcher.range_end < header_matcher.range_start) {
1121
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1122
- "Invalid range header matcher specifier specified: end "
1123
- "cannot be smaller than start.");
1124
- }
1125
- } else if (envoy_api_v2_route_HeaderMatcher_has_present_match(header)) {
1126
- header_matcher.type = XdsApi::RdsUpdate::RdsRoute::Matchers::
1127
- HeaderMatcher::HeaderMatcherType::PRESENT;
1128
- header_matcher.present_match =
1129
- envoy_api_v2_route_HeaderMatcher_present_match(header);
1130
- } else if (envoy_api_v2_route_HeaderMatcher_has_prefix_match(header)) {
1131
- header_matcher.type = XdsApi::RdsUpdate::RdsRoute::Matchers::
1132
- HeaderMatcher::HeaderMatcherType::PREFIX;
1133
- header_matcher.string_matcher = UpbStringToStdString(
1134
- envoy_api_v2_route_HeaderMatcher_prefix_match(header));
1135
- } else if (envoy_api_v2_route_HeaderMatcher_has_suffix_match(header)) {
1136
- header_matcher.type = XdsApi::RdsUpdate::RdsRoute::Matchers::
1137
- HeaderMatcher::HeaderMatcherType::SUFFIX;
1138
- header_matcher.string_matcher = UpbStringToStdString(
1139
- envoy_api_v2_route_HeaderMatcher_suffix_match(header));
1140
- } else {
1141
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1142
- "Invalid route header matcher specified.");
1143
- }
1144
- header_matcher.invert_match =
1145
- envoy_api_v2_route_HeaderMatcher_invert_match(header);
1146
- rds_route->matchers.header_matchers.emplace_back(std::move(header_matcher));
1147
- }
1148
- return GRPC_ERROR_NONE;
1149
- }
1150
-
1151
- grpc_error* RouteRuntimeFractionParse(
1152
- const envoy_api_v2_route_RouteMatch* match,
1153
- XdsApi::RdsUpdate::RdsRoute* rds_route) {
1154
- const envoy_api_v2_core_RuntimeFractionalPercent* runtime_fraction =
1155
- envoy_api_v2_route_RouteMatch_runtime_fraction(match);
1156
- if (runtime_fraction != nullptr) {
1157
- const envoy_type_FractionalPercent* fraction =
1158
- envoy_api_v2_core_RuntimeFractionalPercent_default_value(
1159
- runtime_fraction);
1160
- if (fraction != nullptr) {
1161
- uint32_t numerator = envoy_type_FractionalPercent_numerator(fraction);
1162
- const auto denominator =
1163
- static_cast<envoy_type_FractionalPercent_DenominatorType>(
1164
- envoy_type_FractionalPercent_denominator(fraction));
1165
- // Normalize to million.
1166
- switch (denominator) {
1167
- case envoy_type_FractionalPercent_HUNDRED:
1168
- numerator *= 10000;
1169
- break;
1170
- case envoy_type_FractionalPercent_TEN_THOUSAND:
1171
- numerator *= 100;
1172
- break;
1173
- case envoy_type_FractionalPercent_MILLION:
1174
- break;
1175
- default:
1176
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1177
- "Unknown denominator type");
1178
- }
1179
- rds_route->matchers.fraction_per_million = numerator;
1180
- }
1181
- }
1182
- return GRPC_ERROR_NONE;
1183
- }
1184
-
1185
- grpc_error* RouteActionParse(const envoy_api_v2_route_Route* route,
1186
- XdsApi::RdsUpdate::RdsRoute* rds_route,
1187
- bool* ignore_route) {
1188
- if (!envoy_api_v2_route_Route_has_route(route)) {
1189
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1190
- "No RouteAction found in route.");
1191
- }
1192
- const envoy_api_v2_route_RouteAction* route_action =
1193
- envoy_api_v2_route_Route_route(route);
1194
- // Get the cluster or weighted_clusters in the RouteAction.
1195
- if (envoy_api_v2_route_RouteAction_has_cluster(route_action)) {
1196
- const upb_strview cluster_name =
1197
- envoy_api_v2_route_RouteAction_cluster(route_action);
1198
- if (cluster_name.size == 0) {
1199
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1200
- "RouteAction cluster contains empty cluster name.");
1201
- }
1202
- rds_route->cluster_name = UpbStringToStdString(cluster_name);
1203
- } else if (envoy_api_v2_route_RouteAction_has_weighted_clusters(
1204
- route_action)) {
1205
- const envoy_api_v2_route_WeightedCluster* weighted_cluster =
1206
- envoy_api_v2_route_RouteAction_weighted_clusters(route_action);
1207
- uint32_t total_weight = 100;
1208
- const google_protobuf_UInt32Value* weight =
1209
- envoy_api_v2_route_WeightedCluster_total_weight(weighted_cluster);
1210
- if (weight != nullptr) {
1211
- total_weight = google_protobuf_UInt32Value_value(weight);
1212
- }
1213
- size_t clusters_size;
1214
- const envoy_api_v2_route_WeightedCluster_ClusterWeight* const* clusters =
1215
- envoy_api_v2_route_WeightedCluster_clusters(weighted_cluster,
1216
- &clusters_size);
1217
- uint32_t sum_of_weights = 0;
1218
- for (size_t j = 0; j < clusters_size; ++j) {
1219
- const envoy_api_v2_route_WeightedCluster_ClusterWeight* cluster_weight =
1220
- clusters[j];
1221
- XdsApi::RdsUpdate::RdsRoute::ClusterWeight cluster;
1222
- cluster.name = UpbStringToStdString(
1223
- envoy_api_v2_route_WeightedCluster_ClusterWeight_name(
1224
- cluster_weight));
1225
- if (cluster.name.empty()) {
1226
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1227
- "RouteAction weighted_cluster cluster contains empty cluster "
1228
- "name.");
1229
- }
1230
- const google_protobuf_UInt32Value* weight =
1231
- envoy_api_v2_route_WeightedCluster_ClusterWeight_weight(
1232
- cluster_weight);
1233
- if (weight == nullptr) {
1234
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1235
- "RouteAction weighted_cluster cluster missing weight");
1236
- }
1237
- cluster.weight = google_protobuf_UInt32Value_value(weight);
1238
- sum_of_weights += cluster.weight;
1239
- rds_route->weighted_clusters.emplace_back(std::move(cluster));
1240
- }
1241
- if (total_weight != sum_of_weights) {
1242
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1243
- "RouteAction weighted_cluster has incorrect total weight");
1244
- }
1245
- if (rds_route->weighted_clusters.empty()) {
1246
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1247
- "RouteAction weighted_cluster has no valid clusters specified.");
1248
- }
1249
- } else {
1250
- // No cluster or weighted_clusters found in RouteAction, ignore this route.
1251
- *ignore_route = true;
1252
- return GRPC_ERROR_NONE;
1253
- }
1254
- return GRPC_ERROR_NONE;
1255
- }
1256
-
1257
- grpc_error* RouteConfigParse(
1258
- XdsClient* client, TraceFlag* tracer,
1259
- const envoy_api_v2_RouteConfiguration* route_config,
1260
- const std::string& expected_server_name, XdsApi::RdsUpdate* rds_update) {
1261
- MaybeLogRouteConfiguration(client, tracer, route_config);
1262
- // Get the virtual hosts.
1263
- size_t size;
1264
- const envoy_api_v2_route_VirtualHost* const* virtual_hosts =
1265
- envoy_api_v2_RouteConfiguration_virtual_hosts(route_config, &size);
1266
- // Find the best matched virtual host.
1267
- // The search order for 4 groups of domain patterns:
1268
- // 1. Exact match.
1269
- // 2. Suffix match (e.g., "*ABC").
1270
- // 3. Prefix match (e.g., "ABC*").
1271
- // 4. Universe match (i.e., "*").
1272
- // Within each group, longest match wins.
1273
- // If the same best matched domain pattern appears in multiple virtual hosts,
1274
- // the first matched virtual host wins.
1275
- const envoy_api_v2_route_VirtualHost* target_virtual_host = nullptr;
1276
- MatchType best_match_type = INVALID_MATCH;
1277
- size_t longest_match = 0;
1278
- // Check each domain pattern in each virtual host to determine the best
1279
- // matched virtual host.
1280
- for (size_t i = 0; i < size; ++i) {
1281
- size_t domain_size;
1282
- upb_strview const* domains =
1283
- envoy_api_v2_route_VirtualHost_domains(virtual_hosts[i], &domain_size);
1284
- for (size_t j = 0; j < domain_size; ++j) {
1285
- const std::string domain_pattern(domains[j].data, domains[j].size);
1286
- // Check the match type first. Skip the pattern if it's not better than
1287
- // current match.
1288
- const MatchType match_type = DomainPatternMatchType(domain_pattern);
1289
- if (match_type == INVALID_MATCH) {
1290
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid domain pattern.");
1291
- }
1292
- if (match_type > best_match_type) continue;
1293
- if (match_type == best_match_type &&
1294
- domain_pattern.size() <= longest_match) {
1295
- continue;
1296
- }
1297
- // Skip if match fails.
1298
- if (!DomainMatch(match_type, domain_pattern, expected_server_name)) {
1299
- continue;
1300
- }
1301
- // Choose this match.
1302
- target_virtual_host = virtual_hosts[i];
1303
- best_match_type = match_type;
1304
- longest_match = domain_pattern.size();
1305
- if (best_match_type == EXACT_MATCH) break;
1306
- }
1307
- if (best_match_type == EXACT_MATCH) break;
1308
- }
1309
- if (target_virtual_host == nullptr) {
1310
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1311
- "No matched virtual host found in the route config.");
1312
- }
1313
- // Get the route list from the matched virtual host.
1314
- const envoy_api_v2_route_Route* const* routes =
1315
- envoy_api_v2_route_VirtualHost_routes(target_virtual_host, &size);
1316
- if (size < 1) {
1317
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1318
- "No route found in the virtual host.");
1319
- }
1320
- // Loop over the whole list of routes
1321
- for (size_t i = 0; i < size; ++i) {
1322
- const envoy_api_v2_route_Route* route = routes[i];
1323
- const envoy_api_v2_route_RouteMatch* match =
1324
- envoy_api_v2_route_Route_match(route);
1325
- size_t query_parameters_size;
1326
- static_cast<void>(envoy_api_v2_route_RouteMatch_query_parameters(
1327
- match, &query_parameters_size));
1328
- if (query_parameters_size > 0) {
1329
- continue;
1330
- }
1331
- XdsApi::RdsUpdate::RdsRoute rds_route;
1332
- bool ignore_route = false;
1333
- grpc_error* error = RoutePathMatchParse(match, &rds_route, &ignore_route);
1334
- if (error != GRPC_ERROR_NONE) return error;
1335
- if (ignore_route) continue;
1336
- error = RouteHeaderMatchersParse(match, &rds_route);
1337
- if (error != GRPC_ERROR_NONE) return error;
1338
- error = RouteRuntimeFractionParse(match, &rds_route);
1339
- if (error != GRPC_ERROR_NONE) return error;
1340
- error = RouteActionParse(route, &rds_route, &ignore_route);
1341
- if (error != GRPC_ERROR_NONE) return error;
1342
- if (ignore_route) continue;
1343
- const google_protobuf_BoolValue* case_sensitive =
1344
- envoy_api_v2_route_RouteMatch_case_sensitive(match);
1345
- if (case_sensitive != nullptr &&
1346
- !google_protobuf_BoolValue_value(case_sensitive)) {
1347
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1348
- "case_sensitive if set must be set to true.");
1349
- }
1350
- rds_update->routes.emplace_back(std::move(rds_route));
1351
- }
1352
- if (rds_update->routes.empty()) {
1353
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No valid routes specified.");
1354
- }
1355
- return GRPC_ERROR_NONE;
1356
- }
1357
-
1358
- grpc_error* LdsResponseParse(XdsClient* client, TraceFlag* tracer,
1359
- const envoy_api_v2_DiscoveryResponse* response,
1360
- const std::string& expected_server_name,
1361
- absl::optional<XdsApi::LdsUpdate>* lds_update,
1362
- upb_arena* arena) {
1363
- // Get the resources from the response.
1364
- size_t size;
1365
- const google_protobuf_Any* const* resources =
1366
- envoy_api_v2_DiscoveryResponse_resources(response, &size);
1367
- for (size_t i = 0; i < size; ++i) {
1368
- // Check the type_url of the resource.
1369
- const upb_strview type_url = google_protobuf_Any_type_url(resources[i]);
1370
- if (!upb_strview_eql(type_url, upb_strview_makez(XdsApi::kLdsTypeUrl))) {
1371
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not LDS.");
1372
- }
1373
- // Decode the listener.
1374
- const upb_strview encoded_listener =
1375
- google_protobuf_Any_value(resources[i]);
1376
- const envoy_api_v2_Listener* listener = envoy_api_v2_Listener_parse(
1377
- encoded_listener.data, encoded_listener.size, arena);
1378
- if (listener == nullptr) {
1379
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode listener.");
1380
- }
1381
- // Check listener name. Ignore unexpected listeners.
1382
- const upb_strview name = envoy_api_v2_Listener_name(listener);
1383
- const upb_strview expected_name =
1384
- upb_strview_makez(expected_server_name.c_str());
1385
- if (!upb_strview_eql(name, expected_name)) continue;
1386
- // Get api_listener and decode it to http_connection_manager.
1387
- const envoy_config_listener_v2_ApiListener* api_listener =
1388
- envoy_api_v2_Listener_api_listener(listener);
1389
- if (api_listener == nullptr) {
1390
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1391
- "Listener has no ApiListener.");
1392
- }
1393
- const upb_strview encoded_api_listener = google_protobuf_Any_value(
1394
- envoy_config_listener_v2_ApiListener_api_listener(api_listener));
1395
- const envoy_config_filter_network_http_connection_manager_v2_HttpConnectionManager*
1396
- http_connection_manager =
1397
- envoy_config_filter_network_http_connection_manager_v2_HttpConnectionManager_parse(
1398
- encoded_api_listener.data, encoded_api_listener.size, arena);
1399
- // Found inlined route_config. Parse it to find the cluster_name.
1400
- if (envoy_config_filter_network_http_connection_manager_v2_HttpConnectionManager_has_route_config(
1401
- http_connection_manager)) {
1402
- const envoy_api_v2_RouteConfiguration* route_config =
1403
- envoy_config_filter_network_http_connection_manager_v2_HttpConnectionManager_route_config(
1404
- http_connection_manager);
1405
- XdsApi::RdsUpdate rds_update;
1406
- grpc_error* error = RouteConfigParse(client, tracer, route_config,
1407
- expected_server_name, &rds_update);
1408
- if (error != GRPC_ERROR_NONE) return error;
1409
- lds_update->emplace();
1410
- (*lds_update)->rds_update.emplace(std::move(rds_update));
1411
- return GRPC_ERROR_NONE;
1412
- }
1413
- // Validate that RDS must be used to get the route_config dynamically.
1414
- if (!envoy_config_filter_network_http_connection_manager_v2_HttpConnectionManager_has_rds(
1415
- http_connection_manager)) {
1416
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1417
- "HttpConnectionManager neither has inlined route_config nor RDS.");
1418
- }
1419
- const envoy_config_filter_network_http_connection_manager_v2_Rds* rds =
1420
- envoy_config_filter_network_http_connection_manager_v2_HttpConnectionManager_rds(
1421
- http_connection_manager);
1422
- // Check that the ConfigSource specifies ADS.
1423
- const envoy_api_v2_core_ConfigSource* config_source =
1424
- envoy_config_filter_network_http_connection_manager_v2_Rds_config_source(
1425
- rds);
1426
- if (config_source == nullptr) {
1427
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1428
- "HttpConnectionManager missing config_source for RDS.");
1429
- }
1430
- if (!envoy_api_v2_core_ConfigSource_has_ads(config_source)) {
1431
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1432
- "HttpConnectionManager ConfigSource for RDS does not specify ADS.");
1433
- }
1434
- // Get the route_config_name.
1435
- lds_update->emplace();
1436
- (*lds_update)->route_config_name = UpbStringToStdString(
1437
- envoy_config_filter_network_http_connection_manager_v2_Rds_route_config_name(
1438
- rds));
1439
- return GRPC_ERROR_NONE;
1440
- }
1441
- return GRPC_ERROR_NONE;
1442
- }
1443
-
1444
- grpc_error* RdsResponseParse(
1445
- XdsClient* client, TraceFlag* tracer,
1446
- const envoy_api_v2_DiscoveryResponse* response,
1447
- const std::string& expected_server_name,
1448
- const std::set<absl::string_view>& expected_route_configuration_names,
1449
- absl::optional<XdsApi::RdsUpdate>* rds_update, upb_arena* arena) {
1450
- // Get the resources from the response.
1451
- size_t size;
1452
- const google_protobuf_Any* const* resources =
1453
- envoy_api_v2_DiscoveryResponse_resources(response, &size);
1454
- for (size_t i = 0; i < size; ++i) {
1455
- // Check the type_url of the resource.
1456
- const upb_strview type_url = google_protobuf_Any_type_url(resources[i]);
1457
- if (!upb_strview_eql(type_url, upb_strview_makez(XdsApi::kRdsTypeUrl))) {
1458
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not RDS.");
1459
- }
1460
- // Decode the route_config.
1461
- const upb_strview encoded_route_config =
1462
- google_protobuf_Any_value(resources[i]);
1463
- const envoy_api_v2_RouteConfiguration* route_config =
1464
- envoy_api_v2_RouteConfiguration_parse(encoded_route_config.data,
1465
- encoded_route_config.size, arena);
1466
- if (route_config == nullptr) {
1467
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode route_config.");
1468
- }
1469
- // Check route_config_name. Ignore unexpected route_config.
1470
- const upb_strview route_config_name =
1471
- envoy_api_v2_RouteConfiguration_name(route_config);
1472
- absl::string_view route_config_name_strview(route_config_name.data,
1473
- route_config_name.size);
1474
- if (expected_route_configuration_names.find(route_config_name_strview) ==
1475
- expected_route_configuration_names.end()) {
1476
- continue;
1477
- }
1478
- // Parse the route_config.
1479
- XdsApi::RdsUpdate local_rds_update;
1480
- grpc_error* error = RouteConfigParse(
1481
- client, tracer, route_config, expected_server_name, &local_rds_update);
1482
- if (error != GRPC_ERROR_NONE) return error;
1483
- rds_update->emplace(std::move(local_rds_update));
1484
- return GRPC_ERROR_NONE;
1485
- }
1486
- return GRPC_ERROR_NONE;
1487
- }
1488
-
1489
- grpc_error* CdsResponseParse(
1490
- XdsClient* client, TraceFlag* tracer,
1491
- const envoy_api_v2_DiscoveryResponse* response,
1492
- const std::set<absl::string_view>& expected_cluster_names,
1493
- XdsApi::CdsUpdateMap* cds_update_map, upb_arena* arena) {
1494
- // Get the resources from the response.
1495
- size_t size;
1496
- const google_protobuf_Any* const* resources =
1497
- envoy_api_v2_DiscoveryResponse_resources(response, &size);
1498
- // Parse all the resources in the CDS response.
1499
- for (size_t i = 0; i < size; ++i) {
1500
- XdsApi::CdsUpdate cds_update;
1501
- // Check the type_url of the resource.
1502
- const upb_strview type_url = google_protobuf_Any_type_url(resources[i]);
1503
- if (!upb_strview_eql(type_url, upb_strview_makez(XdsApi::kCdsTypeUrl))) {
1504
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not CDS.");
1505
- }
1506
- // Decode the cluster.
1507
- const upb_strview encoded_cluster = google_protobuf_Any_value(resources[i]);
1508
- const envoy_api_v2_Cluster* cluster = envoy_api_v2_Cluster_parse(
1509
- encoded_cluster.data, encoded_cluster.size, arena);
1510
- if (cluster == nullptr) {
1511
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode cluster.");
1512
- }
1513
- MaybeLogCluster(client, tracer, cluster);
1514
- // Ignore unexpected cluster names.
1515
- upb_strview cluster_name = envoy_api_v2_Cluster_name(cluster);
1516
- absl::string_view cluster_name_strview(cluster_name.data,
1517
- cluster_name.size);
1518
- if (expected_cluster_names.find(cluster_name_strview) ==
1519
- expected_cluster_names.end()) {
1520
- continue;
1521
- }
1522
- // Check the cluster_discovery_type.
1523
- if (!envoy_api_v2_Cluster_has_type(cluster)) {
1524
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType not found.");
1525
- }
1526
- if (envoy_api_v2_Cluster_type(cluster) != envoy_api_v2_Cluster_EDS) {
1527
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType is not EDS.");
1528
- }
1529
- // Check the EDS config source.
1530
- const envoy_api_v2_Cluster_EdsClusterConfig* eds_cluster_config =
1531
- envoy_api_v2_Cluster_eds_cluster_config(cluster);
1532
- const envoy_api_v2_core_ConfigSource* eds_config =
1533
- envoy_api_v2_Cluster_EdsClusterConfig_eds_config(eds_cluster_config);
1534
- if (!envoy_api_v2_core_ConfigSource_has_ads(eds_config)) {
1535
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1536
- "EDS ConfigSource is not ADS.");
1537
- }
1538
- // Record EDS service_name (if any).
1539
- upb_strview service_name =
1540
- envoy_api_v2_Cluster_EdsClusterConfig_service_name(eds_cluster_config);
1541
- if (service_name.size != 0) {
1542
- cds_update.eds_service_name = UpbStringToStdString(service_name);
1543
- }
1544
- // Check the LB policy.
1545
- if (envoy_api_v2_Cluster_lb_policy(cluster) !=
1546
- envoy_api_v2_Cluster_ROUND_ROBIN) {
1547
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1548
- "LB policy is not ROUND_ROBIN.");
1549
- }
1550
- // Record LRS server name (if any).
1551
- const envoy_api_v2_core_ConfigSource* lrs_server =
1552
- envoy_api_v2_Cluster_lrs_server(cluster);
1553
- if (lrs_server != nullptr) {
1554
- if (!envoy_api_v2_core_ConfigSource_has_self(lrs_server)) {
1555
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1556
- "LRS ConfigSource is not self.");
1557
- }
1558
- cds_update.lrs_load_reporting_server_name.emplace("");
1559
- }
1560
- cds_update_map->emplace(UpbStringToStdString(cluster_name),
1561
- std::move(cds_update));
1562
- }
1563
- return GRPC_ERROR_NONE;
1564
- }
1565
-
1566
- grpc_error* ServerAddressParseAndAppend(
1567
- const envoy_api_v2_endpoint_LbEndpoint* lb_endpoint,
1568
- ServerAddressList* list) {
1569
- // If health_status is not HEALTHY or UNKNOWN, skip this endpoint.
1570
- const int32_t health_status =
1571
- envoy_api_v2_endpoint_LbEndpoint_health_status(lb_endpoint);
1572
- if (health_status != envoy_api_v2_core_UNKNOWN &&
1573
- health_status != envoy_api_v2_core_HEALTHY) {
1574
- return GRPC_ERROR_NONE;
1575
- }
1576
- // Find the ip:port.
1577
- const envoy_api_v2_endpoint_Endpoint* endpoint =
1578
- envoy_api_v2_endpoint_LbEndpoint_endpoint(lb_endpoint);
1579
- const envoy_api_v2_core_Address* address =
1580
- envoy_api_v2_endpoint_Endpoint_address(endpoint);
1581
- const envoy_api_v2_core_SocketAddress* socket_address =
1582
- envoy_api_v2_core_Address_socket_address(address);
1583
- upb_strview address_strview =
1584
- envoy_api_v2_core_SocketAddress_address(socket_address);
1585
- uint32_t port = envoy_api_v2_core_SocketAddress_port_value(socket_address);
1586
- if (GPR_UNLIKELY(port >> 16) != 0) {
1587
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid port.");
1588
- }
1589
- // Populate grpc_resolved_address.
1590
- grpc_resolved_address addr;
1591
- char* address_str = static_cast<char*>(gpr_malloc(address_strview.size + 1));
1592
- memcpy(address_str, address_strview.data, address_strview.size);
1593
- address_str[address_strview.size] = '\0';
1594
- grpc_string_to_sockaddr(&addr, address_str, port);
1595
- gpr_free(address_str);
1596
- // Append the address to the list.
1597
- list->emplace_back(addr, nullptr);
1598
- return GRPC_ERROR_NONE;
1599
- }
1600
-
1601
- grpc_error* LocalityParse(
1602
- const envoy_api_v2_endpoint_LocalityLbEndpoints* locality_lb_endpoints,
1603
- XdsApi::PriorityListUpdate::LocalityMap::Locality* output_locality) {
1604
- // Parse LB weight.
1605
- const google_protobuf_UInt32Value* lb_weight =
1606
- envoy_api_v2_endpoint_LocalityLbEndpoints_load_balancing_weight(
1607
- locality_lb_endpoints);
1608
- // If LB weight is not specified, it means this locality is assigned no load.
1609
- // TODO(juanlishen): When we support CDS to configure the inter-locality
1610
- // policy, we should change the LB weight handling.
1611
- output_locality->lb_weight =
1612
- lb_weight != nullptr ? google_protobuf_UInt32Value_value(lb_weight) : 0;
1613
- if (output_locality->lb_weight == 0) return GRPC_ERROR_NONE;
1614
- // Parse locality name.
1615
- const envoy_api_v2_core_Locality* locality =
1616
- envoy_api_v2_endpoint_LocalityLbEndpoints_locality(locality_lb_endpoints);
1617
- upb_strview region = envoy_api_v2_core_Locality_region(locality);
1618
- upb_strview zone = envoy_api_v2_core_Locality_region(locality);
1619
- upb_strview sub_zone = envoy_api_v2_core_Locality_sub_zone(locality);
1620
- output_locality->name = MakeRefCounted<XdsLocalityName>(
1621
- UpbStringToStdString(region), UpbStringToStdString(zone),
1622
- UpbStringToStdString(sub_zone));
1623
- // Parse the addresses.
1624
- size_t size;
1625
- const envoy_api_v2_endpoint_LbEndpoint* const* lb_endpoints =
1626
- envoy_api_v2_endpoint_LocalityLbEndpoints_lb_endpoints(
1627
- locality_lb_endpoints, &size);
1628
- for (size_t i = 0; i < size; ++i) {
1629
- grpc_error* error = ServerAddressParseAndAppend(
1630
- lb_endpoints[i], &output_locality->serverlist);
1631
- if (error != GRPC_ERROR_NONE) return error;
1632
- }
1633
- // Parse the priority.
1634
- output_locality->priority =
1635
- envoy_api_v2_endpoint_LocalityLbEndpoints_priority(locality_lb_endpoints);
1636
- return GRPC_ERROR_NONE;
1637
- }
1638
-
1639
- grpc_error* DropParseAndAppend(
1640
- const envoy_api_v2_ClusterLoadAssignment_Policy_DropOverload* drop_overload,
1641
- XdsApi::DropConfig* drop_config) {
1642
- // Get the category.
1643
- upb_strview category =
1644
- envoy_api_v2_ClusterLoadAssignment_Policy_DropOverload_category(
1645
- drop_overload);
1646
- if (category.size == 0) {
1647
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty drop category name");
1648
- }
1649
- // Get the drop rate (per million).
1650
- const envoy_type_FractionalPercent* drop_percentage =
1651
- envoy_api_v2_ClusterLoadAssignment_Policy_DropOverload_drop_percentage(
1652
- drop_overload);
1653
- uint32_t numerator = envoy_type_FractionalPercent_numerator(drop_percentage);
1654
- const auto denominator =
1655
- static_cast<envoy_type_FractionalPercent_DenominatorType>(
1656
- envoy_type_FractionalPercent_denominator(drop_percentage));
1657
- // Normalize to million.
1658
- switch (denominator) {
1659
- case envoy_type_FractionalPercent_HUNDRED:
1660
- numerator *= 10000;
1661
- break;
1662
- case envoy_type_FractionalPercent_TEN_THOUSAND:
1663
- numerator *= 100;
1664
- break;
1665
- case envoy_type_FractionalPercent_MILLION:
1666
- break;
1667
- default:
1668
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unknown denominator type");
1669
- }
1670
- // Cap numerator to 1000000.
1671
- numerator = GPR_MIN(numerator, 1000000);
1672
- drop_config->AddCategory(UpbStringToStdString(category), numerator);
1673
- return GRPC_ERROR_NONE;
1674
- }
1675
-
1676
- grpc_error* EdsResponseParse(
1677
- XdsClient* client, TraceFlag* tracer,
1678
- const envoy_api_v2_DiscoveryResponse* response,
1679
- const std::set<absl::string_view>& expected_eds_service_names,
1680
- XdsApi::EdsUpdateMap* eds_update_map, upb_arena* arena) {
1681
- // Get the resources from the response.
1682
- size_t size;
1683
- const google_protobuf_Any* const* resources =
1684
- envoy_api_v2_DiscoveryResponse_resources(response, &size);
1685
- for (size_t i = 0; i < size; ++i) {
1686
- XdsApi::EdsUpdate eds_update;
1687
- // Check the type_url of the resource.
1688
- upb_strview type_url = google_protobuf_Any_type_url(resources[i]);
1689
- if (!upb_strview_eql(type_url, upb_strview_makez(XdsApi::kEdsTypeUrl))) {
1690
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not EDS.");
1691
- }
1692
- // Get the cluster_load_assignment.
1693
- upb_strview encoded_cluster_load_assignment =
1694
- google_protobuf_Any_value(resources[i]);
1695
- envoy_api_v2_ClusterLoadAssignment* cluster_load_assignment =
1696
- envoy_api_v2_ClusterLoadAssignment_parse(
1697
- encoded_cluster_load_assignment.data,
1698
- encoded_cluster_load_assignment.size, arena);
1699
- if (cluster_load_assignment == nullptr) {
1700
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1701
- "Can't parse cluster_load_assignment.");
1702
- }
1703
- MaybeLogClusterLoadAssignment(client, tracer, cluster_load_assignment);
1704
- // Check the cluster name (which actually means eds_service_name). Ignore
1705
- // unexpected names.
1706
- upb_strview cluster_name = envoy_api_v2_ClusterLoadAssignment_cluster_name(
1707
- cluster_load_assignment);
1708
- absl::string_view cluster_name_strview(cluster_name.data,
1709
- cluster_name.size);
1710
- if (expected_eds_service_names.find(cluster_name_strview) ==
1711
- expected_eds_service_names.end()) {
1712
- continue;
1713
- }
1714
- // Get the endpoints.
1715
- size_t locality_size;
1716
- const envoy_api_v2_endpoint_LocalityLbEndpoints* const* endpoints =
1717
- envoy_api_v2_ClusterLoadAssignment_endpoints(cluster_load_assignment,
1718
- &locality_size);
1719
- for (size_t j = 0; j < locality_size; ++j) {
1720
- XdsApi::PriorityListUpdate::LocalityMap::Locality locality;
1721
- grpc_error* error = LocalityParse(endpoints[j], &locality);
1722
- if (error != GRPC_ERROR_NONE) return error;
1723
- // Filter out locality with weight 0.
1724
- if (locality.lb_weight == 0) continue;
1725
- eds_update.priority_list_update.Add(locality);
1726
- }
1727
- for (uint32_t priority = 0;
1728
- priority < eds_update.priority_list_update.size(); ++priority) {
1729
- auto* locality_map = eds_update.priority_list_update.Find(priority);
1730
- if (locality_map == nullptr || locality_map->size() == 0) {
1731
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1732
- "EDS update includes sparse priority list");
1733
- }
1734
- }
1735
- // Get the drop config.
1736
- eds_update.drop_config = MakeRefCounted<XdsApi::DropConfig>();
1737
- const envoy_api_v2_ClusterLoadAssignment_Policy* policy =
1738
- envoy_api_v2_ClusterLoadAssignment_policy(cluster_load_assignment);
1739
- if (policy != nullptr) {
1740
- size_t drop_size;
1741
- const envoy_api_v2_ClusterLoadAssignment_Policy_DropOverload* const*
1742
- drop_overload =
1743
- envoy_api_v2_ClusterLoadAssignment_Policy_drop_overloads(
1744
- policy, &drop_size);
1745
- for (size_t j = 0; j < drop_size; ++j) {
1746
- grpc_error* error =
1747
- DropParseAndAppend(drop_overload[j], eds_update.drop_config.get());
1748
- if (error != GRPC_ERROR_NONE) return error;
1749
- }
1750
- }
1751
- eds_update_map->emplace(UpbStringToStdString(cluster_name),
1752
- std::move(eds_update));
1753
- }
1754
- return GRPC_ERROR_NONE;
1755
- }
1756
-
1757
- } // namespace
1758
-
1759
- grpc_error* XdsApi::ParseAdsResponse(
1760
- const grpc_slice& encoded_response, const std::string& expected_server_name,
1761
- const std::set<absl::string_view>& expected_route_configuration_names,
1762
- const std::set<absl::string_view>& expected_cluster_names,
1763
- const std::set<absl::string_view>& expected_eds_service_names,
1764
- absl::optional<LdsUpdate>* lds_update,
1765
- absl::optional<RdsUpdate>* rds_update, CdsUpdateMap* cds_update_map,
1766
- EdsUpdateMap* eds_update_map, std::string* version, std::string* nonce,
1767
- std::string* type_url) {
1768
- upb::Arena arena;
1769
- // Decode the response.
1770
- const envoy_api_v2_DiscoveryResponse* response =
1771
- envoy_api_v2_DiscoveryResponse_parse(
1772
- reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(encoded_response)),
1773
- GRPC_SLICE_LENGTH(encoded_response), arena.ptr());
1774
- // If decoding fails, output an empty type_url and return.
1775
- if (response == nullptr) {
1776
- *type_url = "";
1777
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1778
- "Can't decode the whole response.");
1779
- }
1780
- MaybeLogDiscoveryResponse(client_, tracer_, response);
1781
- // Record the type_url, the version_info, and the nonce of the response.
1782
- upb_strview type_url_strview =
1783
- envoy_api_v2_DiscoveryResponse_type_url(response);
1784
- *type_url = UpbStringToStdString(type_url_strview);
1785
- upb_strview version_info =
1786
- envoy_api_v2_DiscoveryResponse_version_info(response);
1787
- *version = UpbStringToStdString(version_info);
1788
- upb_strview nonce_strview = envoy_api_v2_DiscoveryResponse_nonce(response);
1789
- *nonce = UpbStringToStdString(nonce_strview);
1790
- // Parse the response according to the resource type.
1791
- if (*type_url == kLdsTypeUrl) {
1792
- return LdsResponseParse(client_, tracer_, response, expected_server_name,
1793
- lds_update, arena.ptr());
1794
- } else if (*type_url == kRdsTypeUrl) {
1795
- return RdsResponseParse(client_, tracer_, response, expected_server_name,
1796
- expected_route_configuration_names, rds_update,
1797
- arena.ptr());
1798
- } else if (*type_url == kCdsTypeUrl) {
1799
- return CdsResponseParse(client_, tracer_, response, expected_cluster_names,
1800
- cds_update_map, arena.ptr());
1801
- } else if (*type_url == kEdsTypeUrl) {
1802
- return EdsResponseParse(client_, tracer_, response,
1803
- expected_eds_service_names, eds_update_map,
1804
- arena.ptr());
1805
- } else {
1806
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1807
- "Unsupported ADS resource type.");
1808
- }
1809
- }
1810
-
1811
- namespace {
1812
-
1813
- void MaybeLogLrsRequest(
1814
- XdsClient* client, TraceFlag* tracer,
1815
- const envoy_service_load_stats_v2_LoadStatsRequest* request) {
1816
- if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
1817
- gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1818
- // TODO(roth): When we can upgrade upb, use upb textformat code to dump
1819
- // the raw proto instead of doing this manually.
1820
- std::vector<std::string> fields;
1821
- // node
1822
- const auto* node =
1823
- envoy_service_load_stats_v2_LoadStatsRequest_node(request);
1824
- if (node != nullptr) {
1825
- AddNodeLogFields(node, &fields);
1826
- }
1827
- // cluster_stats
1828
- size_t num_cluster_stats;
1829
- const struct envoy_api_v2_endpoint_ClusterStats* const* cluster_stats =
1830
- envoy_service_load_stats_v2_LoadStatsRequest_cluster_stats(
1831
- request, &num_cluster_stats);
1832
- for (size_t i = 0; i < num_cluster_stats; ++i) {
1833
- const auto* cluster_stat = cluster_stats[i];
1834
- fields.emplace_back("cluster_stats {");
1835
- // cluster_name
1836
- AddStringField(
1837
- " cluster_name",
1838
- envoy_api_v2_endpoint_ClusterStats_cluster_name(cluster_stat),
1839
- &fields);
1840
- // cluster_service_name
1841
- AddStringField(
1842
- " cluster_service_name",
1843
- envoy_api_v2_endpoint_ClusterStats_cluster_service_name(cluster_stat),
1844
- &fields);
1845
- // upstream_locality_stats
1846
- size_t num_stats;
1847
- const envoy_api_v2_endpoint_UpstreamLocalityStats* const* stats =
1848
- envoy_api_v2_endpoint_ClusterStats_upstream_locality_stats(
1849
- cluster_stat, &num_stats);
1850
- for (size_t j = 0; j < num_stats; ++j) {
1851
- const auto* stat = stats[j];
1852
- fields.emplace_back(" upstream_locality_stats {");
1853
- // locality
1854
- const auto* locality =
1855
- envoy_api_v2_endpoint_UpstreamLocalityStats_locality(stat);
1856
- if (locality != nullptr) {
1857
- fields.emplace_back(" locality {");
1858
- AddLocalityField(3, locality, &fields);
1859
- fields.emplace_back(" }");
1860
- }
1861
- // total_successful_requests
1862
- fields.emplace_back(absl::StrCat(
1863
- " total_successful_requests: ",
1864
- envoy_api_v2_endpoint_UpstreamLocalityStats_total_successful_requests(
1865
- stat)));
1866
- // total_requests_in_progress
1867
- fields.emplace_back(absl::StrCat(
1868
- " total_requests_in_progress: ",
1869
- envoy_api_v2_endpoint_UpstreamLocalityStats_total_requests_in_progress(
1870
- stat)));
1871
- // total_error_requests
1872
- fields.emplace_back(absl::StrCat(
1873
- " total_error_requests: ",
1874
- envoy_api_v2_endpoint_UpstreamLocalityStats_total_error_requests(
1875
- stat)));
1876
- // total_issued_requests
1877
- fields.emplace_back(absl::StrCat(
1878
- " total_issued_requests: ",
1879
- envoy_api_v2_endpoint_UpstreamLocalityStats_total_issued_requests(
1880
- stat)));
1881
- fields.emplace_back(" }");
1882
- }
1883
- // total_dropped_requests
1884
- fields.emplace_back(absl::StrCat(
1885
- " total_dropped_requests: ",
1886
- envoy_api_v2_endpoint_ClusterStats_total_dropped_requests(
1887
- cluster_stat)));
1888
- // dropped_requests
1889
- size_t num_drops;
1890
- const envoy_api_v2_endpoint_ClusterStats_DroppedRequests* const* drops =
1891
- envoy_api_v2_endpoint_ClusterStats_dropped_requests(cluster_stat,
1892
- &num_drops);
1893
- for (size_t j = 0; j < num_drops; ++j) {
1894
- const auto* drop = drops[j];
1895
- fields.emplace_back(" dropped_requests {");
1896
- // category
1897
- AddStringField(
1898
- " category",
1899
- envoy_api_v2_endpoint_ClusterStats_DroppedRequests_category(drop),
1900
- &fields);
1901
- // dropped_count
1902
- fields.emplace_back(absl::StrCat(
1903
- " dropped_count: ",
1904
- envoy_api_v2_endpoint_ClusterStats_DroppedRequests_dropped_count(
1905
- drop)));
1906
- fields.emplace_back(" }");
1907
- }
1908
- // load_report_interval
1909
- const auto* load_report_interval =
1910
- envoy_api_v2_endpoint_ClusterStats_load_report_interval(cluster_stat);
1911
- if (load_report_interval != nullptr) {
1912
- fields.emplace_back(" load_report_interval {");
1913
- fields.emplace_back(absl::StrCat(
1914
- " seconds: ",
1915
- google_protobuf_Duration_seconds(load_report_interval)));
1916
- fields.emplace_back(
1917
- absl::StrCat(" nanos: ",
1918
- google_protobuf_Duration_nanos(load_report_interval)));
1919
- fields.emplace_back(" }");
1920
- }
1921
- fields.emplace_back("}");
1922
- }
1923
- gpr_log(GPR_DEBUG, "[xds_client %p] constructed LRS request: %s", client,
1924
- absl::StrJoin(fields, "\n").c_str());
1925
- }
1926
- }
1927
-
1928
- grpc_slice SerializeLrsRequest(
1929
- const envoy_service_load_stats_v2_LoadStatsRequest* request,
1930
- upb_arena* arena) {
1931
- size_t output_length;
1932
- char* output = envoy_service_load_stats_v2_LoadStatsRequest_serialize(
1933
- request, arena, &output_length);
1934
- return grpc_slice_from_copied_buffer(output, output_length);
1935
- }
1936
-
1937
- } // namespace
1938
-
1939
- grpc_slice XdsApi::CreateLrsInitialRequest(const std::string& server_name) {
1940
- upb::Arena arena;
1941
- // Create a request.
1942
- envoy_service_load_stats_v2_LoadStatsRequest* request =
1943
- envoy_service_load_stats_v2_LoadStatsRequest_new(arena.ptr());
1944
- // Populate node.
1945
- envoy_api_v2_core_Node* node_msg =
1946
- envoy_service_load_stats_v2_LoadStatsRequest_mutable_node(request,
1947
- arena.ptr());
1948
- PopulateNode(arena.ptr(), node_, build_version_, user_agent_name_,
1949
- server_name, node_msg);
1950
- envoy_api_v2_core_Node_add_client_features(
1951
- node_msg, upb_strview_makez("envoy.lrs.supports_send_all_clusters"),
1952
- arena.ptr());
1953
- MaybeLogLrsRequest(client_, tracer_, request);
1954
- return SerializeLrsRequest(request, arena.ptr());
1955
- }
1956
-
1957
- namespace {
1958
-
1959
- void LocalityStatsPopulate(envoy_api_v2_endpoint_UpstreamLocalityStats* output,
1960
- const XdsLocalityName& locality_name,
1961
- const XdsClusterLocalityStats::Snapshot& snapshot,
1962
- upb_arena* arena) {
1963
- // Set locality.
1964
- envoy_api_v2_core_Locality* locality =
1965
- envoy_api_v2_endpoint_UpstreamLocalityStats_mutable_locality(output,
1966
- arena);
1967
- if (!locality_name.region().empty()) {
1968
- envoy_api_v2_core_Locality_set_region(
1969
- locality, upb_strview_makez(locality_name.region().c_str()));
1970
- }
1971
- if (!locality_name.zone().empty()) {
1972
- envoy_api_v2_core_Locality_set_zone(
1973
- locality, upb_strview_makez(locality_name.zone().c_str()));
1974
- }
1975
- if (!locality_name.sub_zone().empty()) {
1976
- envoy_api_v2_core_Locality_set_sub_zone(
1977
- locality, upb_strview_makez(locality_name.sub_zone().c_str()));
1978
- }
1979
- // Set total counts.
1980
- envoy_api_v2_endpoint_UpstreamLocalityStats_set_total_successful_requests(
1981
- output, snapshot.total_successful_requests);
1982
- envoy_api_v2_endpoint_UpstreamLocalityStats_set_total_requests_in_progress(
1983
- output, snapshot.total_requests_in_progress);
1984
- envoy_api_v2_endpoint_UpstreamLocalityStats_set_total_error_requests(
1985
- output, snapshot.total_error_requests);
1986
- envoy_api_v2_endpoint_UpstreamLocalityStats_set_total_issued_requests(
1987
- output, snapshot.total_issued_requests);
1988
- // Add backend metrics.
1989
- for (const auto& p : snapshot.backend_metrics) {
1990
- const std::string& metric_name = p.first;
1991
- const XdsClusterLocalityStats::BackendMetric& metric_value = p.second;
1992
- envoy_api_v2_endpoint_EndpointLoadMetricStats* load_metric =
1993
- envoy_api_v2_endpoint_UpstreamLocalityStats_add_load_metric_stats(
1994
- output, arena);
1995
- envoy_api_v2_endpoint_EndpointLoadMetricStats_set_metric_name(
1996
- load_metric, upb_strview_make(metric_name.data(), metric_name.size()));
1997
- envoy_api_v2_endpoint_EndpointLoadMetricStats_set_num_requests_finished_with_metric(
1998
- load_metric, metric_value.num_requests_finished_with_metric);
1999
- envoy_api_v2_endpoint_EndpointLoadMetricStats_set_total_metric_value(
2000
- load_metric, metric_value.total_metric_value);
2001
- }
2002
- }
2003
-
2004
- } // namespace
2005
-
2006
- grpc_slice XdsApi::CreateLrsRequest(
2007
- ClusterLoadReportMap cluster_load_report_map) {
2008
- upb::Arena arena;
2009
- // Create a request.
2010
- envoy_service_load_stats_v2_LoadStatsRequest* request =
2011
- envoy_service_load_stats_v2_LoadStatsRequest_new(arena.ptr());
2012
- for (auto& p : cluster_load_report_map) {
2013
- const std::string& cluster_name = p.first.first;
2014
- const std::string& eds_service_name = p.first.second;
2015
- const ClusterLoadReport& load_report = p.second;
2016
- // Add cluster stats.
2017
- envoy_api_v2_endpoint_ClusterStats* cluster_stats =
2018
- envoy_service_load_stats_v2_LoadStatsRequest_add_cluster_stats(
2019
- request, arena.ptr());
2020
- // Set the cluster name.
2021
- envoy_api_v2_endpoint_ClusterStats_set_cluster_name(
2022
- cluster_stats,
2023
- upb_strview_make(cluster_name.data(), cluster_name.size()));
2024
- // Set EDS service name, if non-empty.
2025
- if (!eds_service_name.empty()) {
2026
- envoy_api_v2_endpoint_ClusterStats_set_cluster_service_name(
2027
- cluster_stats,
2028
- upb_strview_make(eds_service_name.data(), eds_service_name.size()));
2029
- }
2030
- // Add locality stats.
2031
- for (const auto& p : load_report.locality_stats) {
2032
- const XdsLocalityName& locality_name = *p.first;
2033
- const auto& snapshot = p.second;
2034
- envoy_api_v2_endpoint_UpstreamLocalityStats* locality_stats =
2035
- envoy_api_v2_endpoint_ClusterStats_add_upstream_locality_stats(
2036
- cluster_stats, arena.ptr());
2037
- LocalityStatsPopulate(locality_stats, locality_name, snapshot,
2038
- arena.ptr());
2039
- }
2040
- // Add dropped requests.
2041
- uint64_t total_dropped_requests = 0;
2042
- for (const auto& p : load_report.dropped_requests) {
2043
- const char* category = p.first.c_str();
2044
- const uint64_t count = p.second;
2045
- envoy_api_v2_endpoint_ClusterStats_DroppedRequests* dropped_requests =
2046
- envoy_api_v2_endpoint_ClusterStats_add_dropped_requests(cluster_stats,
2047
- arena.ptr());
2048
- envoy_api_v2_endpoint_ClusterStats_DroppedRequests_set_category(
2049
- dropped_requests, upb_strview_makez(category));
2050
- envoy_api_v2_endpoint_ClusterStats_DroppedRequests_set_dropped_count(
2051
- dropped_requests, count);
2052
- total_dropped_requests += count;
2053
- }
2054
- // Set total dropped requests.
2055
- envoy_api_v2_endpoint_ClusterStats_set_total_dropped_requests(
2056
- cluster_stats, total_dropped_requests);
2057
- // Set real load report interval.
2058
- gpr_timespec timespec =
2059
- grpc_millis_to_timespec(load_report.load_report_interval, GPR_TIMESPAN);
2060
- google_protobuf_Duration* load_report_interval =
2061
- envoy_api_v2_endpoint_ClusterStats_mutable_load_report_interval(
2062
- cluster_stats, arena.ptr());
2063
- google_protobuf_Duration_set_seconds(load_report_interval, timespec.tv_sec);
2064
- google_protobuf_Duration_set_nanos(load_report_interval, timespec.tv_nsec);
2065
- }
2066
- MaybeLogLrsRequest(client_, tracer_, request);
2067
- return SerializeLrsRequest(request, arena.ptr());
2068
- }
2069
-
2070
- grpc_error* XdsApi::ParseLrsResponse(const grpc_slice& encoded_response,
2071
- bool* send_all_clusters,
2072
- std::set<std::string>* cluster_names,
2073
- grpc_millis* load_reporting_interval) {
2074
- upb::Arena arena;
2075
- // Decode the response.
2076
- const envoy_service_load_stats_v2_LoadStatsResponse* decoded_response =
2077
- envoy_service_load_stats_v2_LoadStatsResponse_parse(
2078
- reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(encoded_response)),
2079
- GRPC_SLICE_LENGTH(encoded_response), arena.ptr());
2080
- // Parse the response.
2081
- if (decoded_response == nullptr) {
2082
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode response.");
2083
- }
2084
- // Check send_all_clusters.
2085
- if (envoy_service_load_stats_v2_LoadStatsResponse_send_all_clusters(
2086
- decoded_response)) {
2087
- *send_all_clusters = true;
2088
- } else {
2089
- // Store the cluster names.
2090
- size_t size;
2091
- const upb_strview* clusters =
2092
- envoy_service_load_stats_v2_LoadStatsResponse_clusters(decoded_response,
2093
- &size);
2094
- for (size_t i = 0; i < size; ++i) {
2095
- cluster_names->emplace(clusters[i].data, clusters[i].size);
2096
- }
2097
- }
2098
- // Get the load report interval.
2099
- const google_protobuf_Duration* load_reporting_interval_duration =
2100
- envoy_service_load_stats_v2_LoadStatsResponse_load_reporting_interval(
2101
- decoded_response);
2102
- gpr_timespec timespec{
2103
- google_protobuf_Duration_seconds(load_reporting_interval_duration),
2104
- google_protobuf_Duration_nanos(load_reporting_interval_duration),
2105
- GPR_TIMESPAN};
2106
- *load_reporting_interval = gpr_time_to_millis(timespec);
2107
- return GRPC_ERROR_NONE;
2108
- }
2109
-
2110
- } // namespace grpc_core