grpc 1.49.1-x86_64-linux → 1.50.0.pre1-x86_64-linux

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 (275) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +54 -153
  3. data/include/grpc/event_engine/endpoint_config.h +11 -5
  4. data/include/grpc/event_engine/event_engine.h +1 -1
  5. data/include/grpc/impl/codegen/atm_gcc_atomic.h +19 -28
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +0 -2
  7. data/include/grpc/impl/codegen/atm_windows.h +0 -2
  8. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  9. data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +3 -3
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -6
  11. data/src/core/ext/filters/client_channel/client_channel.cc +33 -22
  12. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +0 -16
  14. data/src/core/ext/filters/client_channel/http_proxy.cc +12 -19
  15. data/src/core/ext/filters/client_channel/http_proxy.h +3 -2
  16. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
  17. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +5 -4
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +0 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +112 -96
  20. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +20 -11
  21. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +106 -108
  22. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +16 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +20 -13
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +165 -257
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +218 -231
  26. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -6
  27. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +389 -444
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +16 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -13
  30. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +84 -96
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +38 -37
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +106 -186
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +106 -93
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +170 -218
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +13 -15
  38. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +84 -37
  39. data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +11 -0
  40. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -0
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +5 -3
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +5 -4
  43. data/src/core/ext/filters/client_channel/retry_filter.cc +25 -29
  44. data/src/core/ext/filters/client_channel/subchannel.cc +38 -33
  45. data/src/core/ext/filters/client_channel/subchannel.h +12 -3
  46. data/src/core/ext/filters/client_channel/subchannel_stream_client.cc +1 -2
  47. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +23 -16
  48. data/src/core/ext/filters/fault_injection/fault_injection_filter.h +8 -0
  49. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -2
  50. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +2 -4
  51. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +0 -2
  52. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -2
  53. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +12 -8
  54. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +32 -26
  55. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +1 -1
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +25 -130
  57. data/src/core/ext/transport/chttp2/transport/decode_huff.cc +287 -0
  58. data/src/core/ext/transport/chttp2/transport/decode_huff.h +1018 -0
  59. data/src/core/ext/transport/chttp2/transport/flow_control.cc +83 -51
  60. data/src/core/ext/transport/chttp2/transport/flow_control.h +11 -6
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -2
  62. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -20
  63. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +28 -28
  64. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +1 -10
  65. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +11 -6
  66. data/src/core/ext/transport/chttp2/transport/internal.h +2 -0
  67. data/src/core/ext/transport/chttp2/transport/parsing.cc +44 -0
  68. data/src/core/ext/transport/chttp2/transport/writing.cc +3 -14
  69. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -3
  70. data/src/core/ext/xds/certificate_provider_store.cc +63 -3
  71. data/src/core/ext/xds/certificate_provider_store.h +9 -1
  72. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +5 -5
  73. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +1 -1
  74. data/src/core/ext/xds/xds_api.cc +21 -17
  75. data/src/core/ext/xds/xds_api.h +7 -0
  76. data/src/core/ext/xds/xds_bootstrap.cc +5 -537
  77. data/src/core/ext/xds/xds_bootstrap.h +39 -111
  78. data/src/core/ext/xds/xds_bootstrap_grpc.cc +370 -0
  79. data/src/core/ext/xds/xds_bootstrap_grpc.h +169 -0
  80. data/src/core/ext/xds/xds_client.cc +219 -145
  81. data/src/core/ext/xds/xds_client.h +19 -17
  82. data/src/core/ext/xds/xds_client_grpc.cc +18 -80
  83. data/src/core/ext/xds/xds_client_grpc.h +2 -25
  84. data/src/core/ext/xds/xds_client_stats.cc +4 -4
  85. data/src/core/ext/xds/xds_cluster.cc +87 -79
  86. data/src/core/ext/xds/xds_cluster.h +5 -5
  87. data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +3 -1
  88. data/src/core/ext/xds/xds_common_types.cc +13 -5
  89. data/src/core/ext/xds/xds_endpoint.cc +8 -6
  90. data/src/core/ext/xds/xds_endpoint.h +3 -4
  91. data/src/core/ext/xds/xds_lb_policy_registry.cc +4 -2
  92. data/src/core/ext/xds/xds_listener.cc +25 -20
  93. data/src/core/ext/xds/xds_listener.h +3 -4
  94. data/src/core/ext/xds/xds_resource_type.h +11 -8
  95. data/src/core/ext/xds/xds_route_config.cc +15 -16
  96. data/src/core/ext/xds/xds_route_config.h +3 -3
  97. data/src/core/ext/xds/xds_server_config_fetcher.cc +7 -5
  98. data/src/core/ext/xds/xds_transport_grpc.cc +15 -7
  99. data/src/core/lib/backoff/backoff.cc +2 -4
  100. data/src/core/lib/channel/call_finalization.h +1 -3
  101. data/src/core/lib/channel/channel_args.h +114 -14
  102. data/src/core/lib/channel/channel_trace.cc +3 -4
  103. data/src/core/lib/channel/promise_based_filter.cc +18 -19
  104. data/src/core/lib/channel/status_util.cc +27 -0
  105. data/src/core/lib/channel/status_util.h +10 -0
  106. data/src/core/lib/config/core_configuration.cc +5 -1
  107. data/src/core/lib/config/core_configuration.h +33 -0
  108. data/src/core/lib/debug/stats.cc +26 -30
  109. data/src/core/lib/debug/stats.h +2 -12
  110. data/src/core/lib/debug/stats_data.cc +118 -614
  111. data/src/core/lib/debug/stats_data.h +67 -465
  112. data/src/core/lib/debug/trace.cc +0 -2
  113. data/src/core/lib/event_engine/channel_args_endpoint_config.cc +12 -20
  114. data/src/core/lib/event_engine/channel_args_endpoint_config.h +13 -7
  115. data/src/core/lib/event_engine/forkable.cc +1 -1
  116. data/src/core/lib/event_engine/poller.h +14 -12
  117. data/src/core/lib/event_engine/posix_engine/timer_manager.cc +53 -32
  118. data/src/core/lib/event_engine/posix_engine/timer_manager.h +23 -1
  119. data/src/core/lib/event_engine/thread_pool.cc +131 -94
  120. data/src/core/lib/event_engine/thread_pool.h +56 -23
  121. data/src/core/lib/event_engine/time_util.cc +30 -0
  122. data/src/core/lib/event_engine/time_util.h +32 -0
  123. data/src/core/lib/event_engine/utils.cc +0 -5
  124. data/src/core/lib/event_engine/utils.h +0 -4
  125. data/src/core/lib/event_engine/windows/iocp.cc +13 -7
  126. data/src/core/lib/event_engine/windows/iocp.h +2 -1
  127. data/src/core/lib/event_engine/windows/win_socket.cc +1 -1
  128. data/src/core/lib/experiments/config.cc +146 -0
  129. data/src/core/lib/experiments/config.h +43 -0
  130. data/src/core/lib/experiments/experiments.cc +75 -0
  131. data/src/core/lib/experiments/experiments.h +56 -0
  132. data/src/core/lib/gpr/alloc.cc +1 -9
  133. data/src/core/lib/gpr/log_windows.cc +0 -1
  134. data/src/core/lib/gpr/string_util_windows.cc +3 -30
  135. data/src/core/lib/gpr/sync_abseil.cc +0 -14
  136. data/src/core/lib/gpr/sync_posix.cc +0 -14
  137. data/src/core/lib/gpr/time_posix.cc +0 -6
  138. data/src/core/lib/gpr/time_precise.h +1 -1
  139. data/src/core/lib/gpr/tmpfile_windows.cc +5 -7
  140. data/src/core/lib/gpr/useful.h +11 -0
  141. data/src/core/lib/{gpr → gprpp}/env.h +25 -12
  142. data/src/core/lib/{gpr → gprpp}/env_linux.cc +20 -15
  143. data/src/core/lib/{gpr → gprpp}/env_posix.cc +11 -10
  144. data/src/core/lib/gprpp/env_windows.cc +56 -0
  145. data/src/core/lib/gprpp/fork.cc +14 -22
  146. data/src/core/lib/gprpp/fork.h +0 -8
  147. data/src/core/lib/gprpp/global_config_env.cc +7 -6
  148. data/src/core/lib/gprpp/notification.h +67 -0
  149. data/src/core/lib/gprpp/packed_table.h +40 -0
  150. data/src/core/lib/gprpp/ref_counted_ptr.h +20 -33
  151. data/src/core/lib/gprpp/sorted_pack.h +98 -0
  152. data/src/core/lib/gprpp/status_helper.h +6 -0
  153. data/src/core/lib/gprpp/table.h +9 -1
  154. data/src/core/lib/gprpp/tchar.cc +49 -0
  155. data/src/core/lib/gprpp/tchar.h +33 -0
  156. data/src/core/lib/gprpp/time.cc +21 -0
  157. data/src/core/lib/gprpp/time.h +55 -0
  158. data/src/core/lib/gprpp/validation_errors.cc +61 -0
  159. data/src/core/lib/gprpp/validation_errors.h +110 -0
  160. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper.h +3 -3
  161. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper_registry.cc +14 -36
  162. data/src/core/lib/handshaker/proxy_mapper_registry.h +75 -0
  163. data/src/core/lib/iomgr/call_combiner.cc +0 -8
  164. data/src/core/lib/iomgr/closure.h +0 -1
  165. data/src/core/lib/iomgr/endpoint_pair_posix.cc +14 -10
  166. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  167. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -38
  168. data/src/core/lib/iomgr/ev_poll_posix.cc +2 -17
  169. data/src/core/lib/iomgr/exec_ctx.cc +0 -10
  170. data/src/core/lib/iomgr/exec_ctx.h +7 -31
  171. data/src/core/lib/iomgr/iocp_windows.cc +1 -2
  172. data/src/core/lib/iomgr/iomgr.cc +6 -8
  173. data/src/core/lib/iomgr/iomgr_fwd.h +1 -0
  174. data/src/core/lib/iomgr/pollset.h +1 -1
  175. data/src/core/lib/iomgr/pollset_set.h +0 -1
  176. data/src/core/lib/iomgr/resolve_address.h +1 -0
  177. data/src/core/lib/iomgr/resolve_address_impl.h +1 -0
  178. data/src/core/lib/iomgr/resolve_address_posix.cc +1 -0
  179. data/src/core/lib/iomgr/resolve_address_windows.cc +1 -0
  180. data/src/core/lib/iomgr/sockaddr_utils_posix.cc +2 -1
  181. data/src/core/lib/iomgr/socket_utils_common_posix.cc +12 -34
  182. data/src/core/lib/iomgr/socket_utils_posix.cc +83 -1
  183. data/src/core/lib/iomgr/socket_utils_posix.h +98 -6
  184. data/src/core/lib/iomgr/tcp_client.cc +6 -7
  185. data/src/core/lib/iomgr/tcp_client.h +11 -11
  186. data/src/core/lib/iomgr/tcp_client_cfstream.cc +6 -6
  187. data/src/core/lib/iomgr/tcp_client_posix.cc +33 -29
  188. data/src/core/lib/iomgr/tcp_client_posix.h +12 -9
  189. data/src/core/lib/iomgr/tcp_client_windows.cc +6 -6
  190. data/src/core/lib/iomgr/tcp_posix.cc +131 -114
  191. data/src/core/lib/iomgr/tcp_posix.h +3 -1
  192. data/src/core/lib/iomgr/tcp_server.cc +5 -4
  193. data/src/core/lib/iomgr/tcp_server.h +9 -6
  194. data/src/core/lib/iomgr/tcp_server_posix.cc +17 -28
  195. data/src/core/lib/iomgr/tcp_server_utils_posix.h +2 -2
  196. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +3 -3
  197. data/src/core/lib/iomgr/tcp_server_windows.cc +6 -7
  198. data/src/core/lib/iomgr/tcp_windows.cc +0 -1
  199. data/src/core/lib/iomgr/tcp_windows.h +0 -1
  200. data/src/core/lib/iomgr/timer_generic.cc +4 -4
  201. data/src/core/lib/iomgr/timer_manager.cc +1 -2
  202. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +0 -2
  203. data/src/core/lib/json/json_object_loader.cc +21 -52
  204. data/src/core/lib/json/json_object_loader.h +56 -76
  205. data/src/core/lib/json/json_util.cc +2 -1
  206. data/src/core/lib/load_balancing/lb_policy.h +5 -5
  207. data/src/core/lib/load_balancing/lb_policy_registry.cc +29 -55
  208. data/src/core/lib/load_balancing/lb_policy_registry.h +23 -11
  209. data/src/core/lib/promise/activity.h +2 -3
  210. data/src/core/lib/promise/context.h +1 -1
  211. data/src/core/lib/promise/sleep.cc +16 -4
  212. data/src/core/lib/promise/sleep.h +8 -2
  213. data/src/core/lib/resolver/resolver.h +13 -3
  214. data/src/core/lib/resource_quota/api.cc +9 -0
  215. data/src/core/lib/resource_quota/api.h +6 -0
  216. data/src/core/lib/resource_quota/arena.cc +1 -3
  217. data/src/core/lib/resource_quota/memory_quota.cc +8 -24
  218. data/src/core/lib/resource_quota/memory_quota.h +6 -19
  219. data/src/core/lib/resource_quota/periodic_update.cc +2 -3
  220. data/src/core/{ext/xds → lib/security/certificate_provider}/certificate_provider_factory.h +3 -3
  221. data/src/core/lib/security/certificate_provider/certificate_provider_registry.cc +60 -0
  222. data/src/core/lib/security/certificate_provider/certificate_provider_registry.h +70 -0
  223. data/src/core/lib/security/credentials/channel_creds_registry_init.cc +1 -0
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +15 -16
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +2 -1
  226. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +5 -8
  227. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +6 -6
  228. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  229. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +1 -1
  230. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -2
  231. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -3
  232. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +4 -2
  233. data/src/core/lib/security/credentials/tls/tls_utils.cc +3 -1
  234. data/src/core/lib/security/transport/client_auth_filter.cc +12 -1
  235. data/src/core/lib/security/transport/secure_endpoint.cc +0 -4
  236. data/src/core/lib/surface/call.cc +1 -11
  237. data/src/core/lib/surface/channel.cc +3 -2
  238. data/src/core/lib/surface/completion_queue.cc +16 -28
  239. data/src/core/lib/surface/completion_queue.h +1 -1
  240. data/src/core/lib/surface/completion_queue_factory.cc +5 -0
  241. data/src/core/lib/surface/init.cc +16 -11
  242. data/src/core/lib/surface/init_internally.cc +24 -0
  243. data/src/core/lib/surface/init_internally.h +28 -0
  244. data/src/core/lib/surface/server.cc +1 -7
  245. data/src/core/lib/surface/server.h +4 -6
  246. data/src/core/lib/surface/version.cc +2 -2
  247. data/src/core/lib/transport/bdp_estimator.cc +1 -3
  248. data/src/core/lib/transport/metadata_batch.cc +2 -3
  249. data/src/core/lib/transport/metadata_batch.h +9 -7
  250. data/src/core/lib/transport/parsed_metadata.h +4 -2
  251. data/src/core/lib/transport/status_conversion.cc +1 -3
  252. data/src/core/lib/transport/tcp_connect_handshaker.cc +9 -5
  253. data/src/core/lib/transport/transport.h +0 -1
  254. data/src/core/lib/transport/transport_impl.h +0 -1
  255. data/src/core/plugin_registry/grpc_plugin_registry.cc +23 -46
  256. data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +13 -25
  257. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  258. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  259. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  260. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  261. data/src/ruby/lib/grpc/grpc_c.so +0 -0
  262. data/src/ruby/lib/grpc/version.rb +1 -1
  263. data/src/ruby/spec/channel_spec.rb +5 -0
  264. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  265. data/src/ruby/spec/user_agent_spec.rb +1 -1
  266. metadata +33 -19
  267. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  268. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  269. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  270. data/src/core/lib/event_engine/promise.h +0 -78
  271. data/src/core/lib/gpr/env_windows.cc +0 -74
  272. data/src/core/lib/gpr/string_windows.h +0 -32
  273. data/src/core/lib/profiling/basic_timers.cc +0 -295
  274. data/src/core/lib/profiling/stap_timers.cc +0 -50
  275. data/src/core/lib/profiling/timers.h +0 -94
@@ -54,7 +54,7 @@ namespace grpc_core {
54
54
  // ChannelArgs to automatically derive a vtable from a T*.
55
55
  // To participate as a pointer, instances should expose the function:
56
56
  // // Gets the vtable for this type
57
- // static const grpc_channel_arg_vtable* VTable();
57
+ // static const grpc_arg_pointer_vtable* VTable();
58
58
  // // Performs any mutations required for channel args to own a pointer
59
59
  // // Only needed if ChannelArgs::Set is to be called with a raw pointer.
60
60
  // static void* TakeUnownedPointer(T* p);
@@ -117,6 +117,32 @@ struct ChannelArgTypeTraits<
117
117
  };
118
118
  };
119
119
 
120
+ // Specialization for shared_ptr
121
+ // Incurs an allocation because shared_ptr.release is not a thing.
122
+ template <typename T>
123
+ struct is_shared_ptr : std::false_type {};
124
+ template <typename T>
125
+ struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
126
+ template <typename T>
127
+ struct ChannelArgTypeTraits<T,
128
+ absl::enable_if_t<is_shared_ptr<T>::value, void>> {
129
+ static void* TakeUnownedPointer(T* p) { return p; }
130
+ static const grpc_arg_pointer_vtable* VTable() {
131
+ static const grpc_arg_pointer_vtable tbl = {
132
+ // copy
133
+ [](void* p) -> void* { return new T(*static_cast<T*>(p)); },
134
+ // destroy
135
+ [](void* p) { delete static_cast<T*>(p); },
136
+ // compare
137
+ [](void* p1, void* p2) {
138
+ return QsortCompare(static_cast<const T*>(p1)->get(),
139
+ static_cast<const T*>(p2)->get());
140
+ },
141
+ };
142
+ return &tbl;
143
+ };
144
+ };
145
+
120
146
  // If a type declares some member 'struct RawPointerChannelArgTag {}' then
121
147
  // we automatically generate a vtable for it that does not do any ownership
122
148
  // management and compares the type by pointer identity.
@@ -139,6 +165,55 @@ struct ChannelArgTypeTraits<T,
139
165
  };
140
166
  };
141
167
 
168
+ // GetObject support for shared_ptr and RefCountedPtr
169
+ template <typename T>
170
+ struct WrapInSharedPtr
171
+ : std::integral_constant<
172
+ bool, std::is_base_of<std::enable_shared_from_this<T>, T>::value> {};
173
+ template <typename T, typename Ignored = void /* for SFINAE */>
174
+ struct GetObjectImpl;
175
+ // std::shared_ptr implementation
176
+ template <typename T>
177
+ struct GetObjectImpl<T, absl::enable_if_t<WrapInSharedPtr<T>::value, void>> {
178
+ using Result = T*;
179
+ using ReffedResult = std::shared_ptr<T>;
180
+ using StoredType = std::shared_ptr<T>*;
181
+ static Result Get(StoredType p) { return p->get(); };
182
+ static ReffedResult GetReffed(StoredType p) { return ReffedResult(*p); };
183
+ static ReffedResult GetReffed(StoredType p,
184
+ const DebugLocation& /* location */,
185
+ const char* /* reason */) {
186
+ return GetReffed(*p);
187
+ };
188
+ };
189
+ // RefCountedPtr
190
+ template <typename T>
191
+ struct GetObjectImpl<T, absl::enable_if_t<!WrapInSharedPtr<T>::value, void>> {
192
+ using Result = T*;
193
+ using ReffedResult = RefCountedPtr<T>;
194
+ using StoredType = Result;
195
+ static Result Get(StoredType p) { return p; };
196
+ static ReffedResult GetReffed(StoredType p) {
197
+ if (p == nullptr) return nullptr;
198
+ return p->Ref();
199
+ };
200
+ static ReffedResult GetReffed(StoredType p, const DebugLocation& location,
201
+ const char* reason) {
202
+ if (p == nullptr) return nullptr;
203
+ return p->Ref(location, reason);
204
+ };
205
+ };
206
+
207
+ // Provide the canonical name for a type's channel arg key
208
+ template <typename T>
209
+ struct ChannelArgNameTraits {
210
+ static absl::string_view ChannelArgName() { return T::ChannelArgName(); }
211
+ };
212
+ template <typename T>
213
+ struct ChannelArgNameTraits<std::shared_ptr<T>> {
214
+ static absl::string_view ChannelArgName() { return T::ChannelArgName(); }
215
+ };
216
+
142
217
  class ChannelArgs {
143
218
  public:
144
219
  class Pointer {
@@ -243,6 +318,20 @@ class ChannelArgs {
243
318
  ChannelArgTypeTraits<absl::remove_cvref_t<T>>::VTable()));
244
319
  }
245
320
  template <typename T>
321
+ GRPC_MUST_USE_RESULT absl::enable_if_t<
322
+ std::is_same<
323
+ const grpc_arg_pointer_vtable*,
324
+ decltype(ChannelArgTypeTraits<std::shared_ptr<T>>::VTable())>::value,
325
+ ChannelArgs>
326
+ Set(absl::string_view name, std::shared_ptr<T> value) const {
327
+ auto* store_value = new std::shared_ptr<T>(value);
328
+ return Set(
329
+ name,
330
+ Pointer(ChannelArgTypeTraits<std::shared_ptr<T>>::TakeUnownedPointer(
331
+ store_value),
332
+ ChannelArgTypeTraits<std::shared_ptr<T>>::VTable()));
333
+ }
334
+ template <typename T>
246
335
  GRPC_MUST_USE_RESULT ChannelArgs SetIfUnset(absl::string_view name,
247
336
  T value) const {
248
337
  if (Contains(name)) return *this;
@@ -251,13 +340,20 @@ class ChannelArgs {
251
340
  GRPC_MUST_USE_RESULT ChannelArgs Remove(absl::string_view name) const;
252
341
  bool Contains(absl::string_view name) const;
253
342
 
343
+ template <typename T>
344
+ bool ContainsObject() const {
345
+ return Get(ChannelArgNameTraits<T>::ChannelArgName()) != nullptr;
346
+ }
347
+
254
348
  absl::optional<int> GetInt(absl::string_view name) const;
255
349
  absl::optional<absl::string_view> GetString(absl::string_view name) const;
256
350
  absl::optional<std::string> GetOwnedString(absl::string_view name) const;
257
351
  void* GetVoidPointer(absl::string_view name) const;
258
352
  template <typename T>
259
- T* GetPointer(absl::string_view name) const {
260
- return static_cast<T*>(GetVoidPointer(name));
353
+ typename GetObjectImpl<T>::StoredType GetPointer(
354
+ absl::string_view name) const {
355
+ return static_cast<typename GetObjectImpl<T>::StoredType>(
356
+ GetVoidPointer(name));
261
357
  }
262
358
  absl::optional<Duration> GetDurationFromIntMillis(
263
359
  absl::string_view name) const;
@@ -277,21 +373,25 @@ class ChannelArgs {
277
373
  return Set(T::ChannelArgName(), std::move(p));
278
374
  }
279
375
  template <typename T>
280
- T* GetObject() const {
281
- return GetPointer<T>(T::ChannelArgName());
376
+ GRPC_MUST_USE_RESULT ChannelArgs SetObject(std::shared_ptr<T> p) const {
377
+ return Set(ChannelArgNameTraits<T>::ChannelArgName(), std::move(p));
282
378
  }
283
379
  template <typename T>
284
- RefCountedPtr<T> GetObjectRef() const {
285
- auto* p = GetObject<T>();
286
- if (p == nullptr) return nullptr;
287
- return p->Ref(DEBUG_LOCATION, "ChannelArgs GetObjectRef()");
380
+ typename GetObjectImpl<T>::Result GetObject() const {
381
+ return GetObjectImpl<T>::Get(
382
+ GetPointer<T>(ChannelArgNameTraits<T>::ChannelArgName()));
288
383
  }
289
384
  template <typename T>
290
- RefCountedPtr<T> GetObjectRef(const DebugLocation& location,
291
- const char* reason) const {
292
- auto* p = GetObject<T>();
293
- if (p == nullptr) return nullptr;
294
- return p->Ref(location, reason);
385
+ typename GetObjectImpl<T>::ReffedResult GetObjectRef() const {
386
+ return GetObjectImpl<T>::GetReffed(
387
+ GetPointer<T>(ChannelArgNameTraits<T>::ChannelArgName()));
388
+ }
389
+ template <typename T>
390
+ typename GetObjectImpl<T>::ReffedResult GetObjectRef(
391
+ const DebugLocation& location, const char* reason) const {
392
+ return GetObjectImpl<T>::GetReffed(
393
+ GetPointer<T>(ChannelArgNameTraits<T>::ChannelArgName()), location,
394
+ reason);
295
395
  }
296
396
 
297
397
  bool operator!=(const ChannelArgs& other) const;
@@ -30,7 +30,6 @@
30
30
  #include "src/core/lib/channel/channelz.h"
31
31
  #include "src/core/lib/gpr/string.h"
32
32
  #include "src/core/lib/gprpp/time.h"
33
- #include "src/core/lib/iomgr/exec_ctx.h"
34
33
  #include "src/core/lib/slice/slice_internal.h"
35
34
  #include "src/core/lib/slice/slice_refcount.h"
36
35
 
@@ -41,7 +40,7 @@ ChannelTrace::TraceEvent::TraceEvent(Severity severity, const grpc_slice& data,
41
40
  RefCountedPtr<BaseNode> referenced_entity)
42
41
  : severity_(severity),
43
42
  data_(data),
44
- timestamp_(ExecCtx::Get()->Now().as_timespec(GPR_CLOCK_REALTIME)),
43
+ timestamp_(Timestamp::Now().as_timespec(GPR_CLOCK_REALTIME)),
45
44
  next_(nullptr),
46
45
  referenced_entity_(std::move(referenced_entity)),
47
46
  memory_usage_(sizeof(TraceEvent) + grpc_slice_memory_usage(data)) {}
@@ -49,7 +48,7 @@ ChannelTrace::TraceEvent::TraceEvent(Severity severity, const grpc_slice& data,
49
48
  ChannelTrace::TraceEvent::TraceEvent(Severity severity, const grpc_slice& data)
50
49
  : severity_(severity),
51
50
  data_(data),
52
- timestamp_(ExecCtx::Get()->Now().as_timespec(GPR_CLOCK_REALTIME)),
51
+ timestamp_(Timestamp::Now().as_timespec(GPR_CLOCK_REALTIME)),
53
52
  next_(nullptr),
54
53
  memory_usage_(sizeof(TraceEvent) + grpc_slice_memory_usage(data)) {}
55
54
 
@@ -65,7 +64,7 @@ ChannelTrace::ChannelTrace(size_t max_event_memory)
65
64
  return; // tracing is disabled if max_event_memory_ == 0
66
65
  }
67
66
  gpr_mu_init(&tracer_mu_);
68
- time_created_ = ExecCtx::Get()->Now().as_timespec(GPR_CLOCK_REALTIME);
67
+ time_created_ = Timestamp::Now().as_timespec(GPR_CLOCK_REALTIME);
69
68
  }
70
69
 
71
70
  ChannelTrace::~ChannelTrace() {
@@ -22,7 +22,6 @@
22
22
  #include "absl/base/attributes.h"
23
23
  #include "absl/memory/memory.h"
24
24
  #include "absl/types/variant.h"
25
- #include "absl/utility/utility.h"
26
25
 
27
26
  #include <grpc/status.h>
28
27
 
@@ -134,7 +133,7 @@ BaseCallData::CapturedBatch& BaseCallData::CapturedBatch::operator=(
134
133
  }
135
134
 
136
135
  void BaseCallData::CapturedBatch::ResumeWith(Flusher* releaser) {
137
- auto* batch = absl::exchange(batch_, nullptr);
136
+ auto* batch = std::exchange(batch_, nullptr);
138
137
  GPR_ASSERT(batch != nullptr);
139
138
  uintptr_t& refcnt = *RefCountField(batch);
140
139
  if (refcnt == 0) return; // refcnt==0 ==> cancelled
@@ -144,7 +143,7 @@ void BaseCallData::CapturedBatch::ResumeWith(Flusher* releaser) {
144
143
  }
145
144
 
146
145
  void BaseCallData::CapturedBatch::CompleteWith(Flusher* releaser) {
147
- auto* batch = absl::exchange(batch_, nullptr);
146
+ auto* batch = std::exchange(batch_, nullptr);
148
147
  GPR_ASSERT(batch != nullptr);
149
148
  uintptr_t& refcnt = *RefCountField(batch);
150
149
  if (refcnt == 0) return; // refcnt==0 ==> cancelled
@@ -155,7 +154,7 @@ void BaseCallData::CapturedBatch::CompleteWith(Flusher* releaser) {
155
154
 
156
155
  void BaseCallData::CapturedBatch::CancelWith(grpc_error_handle error,
157
156
  Flusher* releaser) {
158
- auto* batch = absl::exchange(batch_, nullptr);
157
+ auto* batch = std::exchange(batch_, nullptr);
159
158
  GPR_ASSERT(batch != nullptr);
160
159
  uintptr_t& refcnt = *RefCountField(batch);
161
160
  if (refcnt == 0) {
@@ -282,8 +281,8 @@ class ClientCallData::PollContext {
282
281
  self_->recv_initial_metadata_->state =
283
282
  RecvInitialMetadata::kResponded;
284
283
  flusher_->AddClosure(
285
- absl::exchange(self_->recv_initial_metadata_->original_on_ready,
286
- nullptr),
284
+ std::exchange(self_->recv_initial_metadata_->original_on_ready,
285
+ nullptr),
287
286
  GRPC_ERROR_NONE,
288
287
  "wake_inside_combiner:recv_initial_metadata_ready");
289
288
  }
@@ -310,8 +309,8 @@ class ClientCallData::PollContext {
310
309
  }
311
310
  self_->recv_trailing_state_ = RecvTrailingState::kResponded;
312
311
  flusher_->AddClosure(
313
- absl::exchange(self_->original_recv_trailing_metadata_ready_,
314
- nullptr),
312
+ std::exchange(self_->original_recv_trailing_metadata_ready_,
313
+ nullptr),
315
314
  GRPC_ERROR_NONE, "wake_inside_combiner:recv_trailing_ready:1");
316
315
  if (self_->recv_initial_metadata_ != nullptr) {
317
316
  switch (self_->recv_initial_metadata_->state) {
@@ -334,7 +333,7 @@ class ClientCallData::PollContext {
334
333
  self_->recv_initial_metadata_->state =
335
334
  RecvInitialMetadata::kResponded;
336
335
  flusher_->AddClosure(
337
- absl::exchange(
336
+ std::exchange(
338
337
  self_->recv_initial_metadata_->original_on_ready,
339
338
  nullptr),
340
339
  GRPC_ERROR_CANCELLED,
@@ -376,7 +375,7 @@ class ClientCallData::PollContext {
376
375
  self_->recv_initial_metadata_->state =
377
376
  RecvInitialMetadata::kResponded;
378
377
  flusher_->AddClosure(
379
- absl::exchange(
378
+ std::exchange(
380
379
  self_->recv_initial_metadata_->original_on_ready,
381
380
  nullptr),
382
381
  GRPC_ERROR_REF(error),
@@ -419,8 +418,8 @@ class ClientCallData::PollContext {
419
418
  if (self_->recv_trailing_state_ == RecvTrailingState::kComplete) {
420
419
  self_->recv_trailing_state_ = RecvTrailingState::kResponded;
421
420
  flusher_->AddClosure(
422
- absl::exchange(self_->original_recv_trailing_metadata_ready_,
423
- nullptr),
421
+ std::exchange(self_->original_recv_trailing_metadata_ready_,
422
+ nullptr),
424
423
  GRPC_ERROR_NONE, "wake_inside_combiner:recv_trailing_ready:2");
425
424
  }
426
425
  break;
@@ -646,7 +645,7 @@ void ClientCallData::Cancel(grpc_error_handle error) {
646
645
  recv_initial_metadata_->state = RecvInitialMetadata::kResponded;
647
646
  GRPC_CALL_COMBINER_START(
648
647
  call_combiner(),
649
- absl::exchange(recv_initial_metadata_->original_on_ready, nullptr),
648
+ std::exchange(recv_initial_metadata_->original_on_ready, nullptr),
650
649
  GRPC_ERROR_REF(error), "propagate cancellation");
651
650
  break;
652
651
  case RecvInitialMetadata::kInitial:
@@ -701,13 +700,13 @@ void ClientCallData::RecvInitialMetadataReady(grpc_error_handle error) {
701
700
  if (!GRPC_ERROR_IS_NONE(error)) {
702
701
  recv_initial_metadata_->state = RecvInitialMetadata::kResponded;
703
702
  flusher.AddClosure(
704
- absl::exchange(recv_initial_metadata_->original_on_ready, nullptr),
703
+ std::exchange(recv_initial_metadata_->original_on_ready, nullptr),
705
704
  GRPC_ERROR_REF(error), "propagate cancellation");
706
705
  } else if (send_initial_state_ == SendInitialState::kCancelled ||
707
706
  recv_trailing_state_ == RecvTrailingState::kResponded) {
708
707
  recv_initial_metadata_->state = RecvInitialMetadata::kResponded;
709
708
  flusher.AddClosure(
710
- absl::exchange(recv_initial_metadata_->original_on_ready, nullptr),
709
+ std::exchange(recv_initial_metadata_->original_on_ready, nullptr),
711
710
  GRPC_ERROR_REF(cancelled_error_), "propagate cancellation");
712
711
  }
713
712
  WakeInsideCombiner(&flusher);
@@ -827,7 +826,7 @@ void ClientCallData::RecvTrailingMetadataReady(grpc_error_handle error) {
827
826
  // forward the callback up with the same error.
828
827
  if (recv_trailing_state_ == RecvTrailingState::kCancelled) {
829
828
  if (grpc_closure* call_closure =
830
- absl::exchange(original_recv_trailing_metadata_ready_, nullptr)) {
829
+ std::exchange(original_recv_trailing_metadata_ready_, nullptr)) {
831
830
  flusher.AddClosure(call_closure, GRPC_ERROR_REF(error),
832
831
  "propagate failure");
833
832
  }
@@ -1080,7 +1079,7 @@ void ServerCallData::Cancel(grpc_error_handle error, Flusher* flusher) {
1080
1079
  send_initial_metadata_->state = SendInitialMetadata::kCancelled;
1081
1080
  }
1082
1081
  if (auto* closure =
1083
- absl::exchange(original_recv_initial_metadata_ready_, nullptr)) {
1082
+ std::exchange(original_recv_initial_metadata_ready_, nullptr)) {
1084
1083
  flusher->AddClosure(closure, GRPC_ERROR_REF(error),
1085
1084
  "original_recv_initial_metadata");
1086
1085
  }
@@ -1158,7 +1157,7 @@ void ServerCallData::RecvInitialMetadataReady(grpc_error_handle error) {
1158
1157
  if (!GRPC_ERROR_IS_NONE(error)) {
1159
1158
  recv_initial_state_ = RecvInitialState::kResponded;
1160
1159
  flusher.AddClosure(
1161
- absl::exchange(original_recv_initial_metadata_ready_, nullptr),
1160
+ std::exchange(original_recv_initial_metadata_ready_, nullptr),
1162
1161
  GRPC_ERROR_REF(error), "propagate error");
1163
1162
  return;
1164
1163
  }
@@ -1178,7 +1177,7 @@ void ServerCallData::RecvInitialMetadataReady(grpc_error_handle error) {
1178
1177
  // Poll once.
1179
1178
  WakeInsideCombiner(&flusher);
1180
1179
  if (auto* closure =
1181
- absl::exchange(original_recv_initial_metadata_ready_, nullptr)) {
1180
+ std::exchange(original_recv_initial_metadata_ready_, nullptr)) {
1182
1181
  flusher.AddClosure(closure, GRPC_ERROR_NONE,
1183
1182
  "original_recv_initial_metadata");
1184
1183
  }
@@ -22,6 +22,8 @@
22
22
 
23
23
  #include <string.h>
24
24
 
25
+ #include "absl/strings/str_cat.h"
26
+
25
27
  #include "src/core/lib/gpr/useful.h"
26
28
 
27
29
  struct status_string_entry {
@@ -109,3 +111,28 @@ bool grpc_status_code_from_int(int status_int, grpc_status_code* status) {
109
111
  *status = static_cast<grpc_status_code>(status_int);
110
112
  return true;
111
113
  }
114
+
115
+ namespace grpc_core {
116
+
117
+ absl::Status MaybeRewriteIllegalStatusCode(absl::Status status,
118
+ absl::string_view source) {
119
+ switch (status.code()) {
120
+ // The set of disallowed codes, as per
121
+ // https://github.com/grpc/proposal/blob/master/A54-restrict-control-plane-status-codes.md.
122
+ case absl::StatusCode::kInvalidArgument:
123
+ case absl::StatusCode::kNotFound:
124
+ case absl::StatusCode::kAlreadyExists:
125
+ case absl::StatusCode::kFailedPrecondition:
126
+ case absl::StatusCode::kAborted:
127
+ case absl::StatusCode::kOutOfRange:
128
+ case absl::StatusCode::kDataLoss: {
129
+ return absl::InternalError(
130
+ absl::StrCat("Illegal status code from ", source,
131
+ "; original status: ", status.ToString()));
132
+ }
133
+ default:
134
+ return status;
135
+ }
136
+ }
137
+
138
+ } // namespace grpc_core
@@ -21,6 +21,9 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
+ #include "absl/status/status.h"
25
+ #include "absl/strings/string_view.h"
26
+
24
27
  #include <grpc/status.h>
25
28
 
26
29
  /// If \a status_str is a valid status string, sets \a status to the
@@ -59,6 +62,13 @@ class StatusCodeSet {
59
62
  };
60
63
 
61
64
  } // namespace internal
65
+
66
+ // Optionally rewrites a status as per
67
+ // https://github.com/grpc/proposal/blob/master/A54-restrict-control-plane-status-codes.md.
68
+ // The source parameter indicates where the status came from.
69
+ absl::Status MaybeRewriteIllegalStatusCode(absl::Status status,
70
+ absl::string_view source);
71
+
62
72
  } // namespace grpc_core
63
73
 
64
74
  #endif /* GRPC_CORE_LIB_CHANNEL_STATUS_UTIL_H */
@@ -43,7 +43,11 @@ CoreConfiguration::CoreConfiguration(Builder* builder)
43
43
  handshaker_registry_(builder->handshaker_registry_.Build()),
44
44
  channel_creds_registry_(builder->channel_creds_registry_.Build()),
45
45
  service_config_parser_(builder->service_config_parser_.Build()),
46
- resolver_registry_(builder->resolver_registry_.Build()) {}
46
+ resolver_registry_(builder->resolver_registry_.Build()),
47
+ lb_policy_registry_(builder->lb_policy_registry_.Build()),
48
+ proxy_mapper_registry_(builder->proxy_mapper_registry_.Build()),
49
+ certificate_provider_registry_(
50
+ builder->certificate_provider_registry_.Build()) {}
47
51
 
48
52
  void CoreConfiguration::RegisterBuilder(std::function<void(Builder*)> builder) {
49
53
  GPR_ASSERT(config_.load(std::memory_order_relaxed) == nullptr &&
@@ -23,7 +23,10 @@
23
23
  #include <grpc/support/log.h>
24
24
 
25
25
  #include "src/core/lib/channel/channel_args_preconditioning.h"
26
+ #include "src/core/lib/handshaker/proxy_mapper_registry.h"
27
+ #include "src/core/lib/load_balancing/lb_policy_registry.h"
26
28
  #include "src/core/lib/resolver/resolver_registry.h"
29
+ #include "src/core/lib/security/certificate_provider/certificate_provider_registry.h"
27
30
  #include "src/core/lib/security/credentials/channel_creds_registry.h"
28
31
  #include "src/core/lib/service_config/service_config_parser.h"
29
32
  #include "src/core/lib/surface/channel_init.h"
@@ -64,6 +67,18 @@ class CoreConfiguration {
64
67
  return &resolver_registry_;
65
68
  }
66
69
 
70
+ LoadBalancingPolicyRegistry::Builder* lb_policy_registry() {
71
+ return &lb_policy_registry_;
72
+ }
73
+
74
+ ProxyMapperRegistry::Builder* proxy_mapper_registry() {
75
+ return &proxy_mapper_registry_;
76
+ }
77
+
78
+ CertificateProviderRegistry::Builder* certificate_provider_registry() {
79
+ return &certificate_provider_registry_;
80
+ }
81
+
67
82
  private:
68
83
  friend class CoreConfiguration;
69
84
 
@@ -73,6 +88,9 @@ class CoreConfiguration {
73
88
  ChannelCredsRegistry<>::Builder channel_creds_registry_;
74
89
  ServiceConfigParser::Builder service_config_parser_;
75
90
  ResolverRegistry::Builder resolver_registry_;
91
+ LoadBalancingPolicyRegistry::Builder lb_policy_registry_;
92
+ ProxyMapperRegistry::Builder proxy_mapper_registry_;
93
+ CertificateProviderRegistry::Builder certificate_provider_registry_;
76
94
 
77
95
  Builder();
78
96
  CoreConfiguration* Build();
@@ -177,6 +195,18 @@ class CoreConfiguration {
177
195
  return resolver_registry_;
178
196
  }
179
197
 
198
+ const LoadBalancingPolicyRegistry& lb_policy_registry() const {
199
+ return lb_policy_registry_;
200
+ }
201
+
202
+ const ProxyMapperRegistry& proxy_mapper_registry() const {
203
+ return proxy_mapper_registry_;
204
+ }
205
+
206
+ const CertificateProviderRegistry& certificate_provider_registry() const {
207
+ return certificate_provider_registry_;
208
+ }
209
+
180
210
  static void SetDefaultBuilder(void (*builder)(CoreConfiguration::Builder*)) {
181
211
  default_builder_ = builder;
182
212
  }
@@ -201,6 +231,9 @@ class CoreConfiguration {
201
231
  ChannelCredsRegistry<> channel_creds_registry_;
202
232
  ServiceConfigParser service_config_parser_;
203
233
  ResolverRegistry resolver_registry_;
234
+ LoadBalancingPolicyRegistry lb_policy_registry_;
235
+ ProxyMapperRegistry proxy_mapper_registry_;
236
+ CertificateProviderRegistry certificate_provider_registry_;
204
237
  };
205
238
 
206
239
  extern void BuildCoreConfiguration(CoreConfiguration::Builder* builder);
@@ -26,6 +26,7 @@
26
26
  #include <algorithm>
27
27
  #include <vector>
28
28
 
29
+ #include "absl/strings/str_cat.h"
29
30
  #include "absl/strings/str_format.h"
30
31
  #include "absl/strings/str_join.h"
31
32
 
@@ -66,21 +67,12 @@ void grpc_stats_diff(const grpc_stats_data* b, const grpc_stats_data* a,
66
67
  }
67
68
  }
68
69
 
69
- int grpc_stats_histo_find_bucket_slow(int value, const int* table,
70
- int table_size) {
71
- GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS();
72
- const int* const start = table;
73
- while (table_size > 0) {
74
- int step = table_size / 2;
75
- const int* it = table + step;
76
- if (value >= *it) {
77
- table = it + 1;
78
- table_size -= step + 1;
79
- } else {
80
- table_size = step;
81
- }
82
- }
83
- return static_cast<int>(table - start) - 1;
70
+ void grpc_stats_inc_histogram_value(int histogram, int value) {
71
+ const int bucket = grpc_stats_get_bucket[histogram](value);
72
+ gpr_atm_no_barrier_fetch_add(
73
+ &GRPC_THREAD_STATS_DATA()
74
+ ->histograms[grpc_stats_histo_start[histogram] + bucket],
75
+ 1);
84
76
  }
85
77
 
86
78
  size_t grpc_stats_histo_count(const grpc_stats_data* stats,
@@ -142,28 +134,32 @@ double grpc_stats_histo_percentile(const grpc_stats_data* stats,
142
134
  static_cast<double>(count) * percentile / 100.0);
143
135
  }
144
136
 
137
+ namespace {
138
+ template <typename I>
139
+ std::string ArrayToJson(const I* values, size_t count) {
140
+ std::vector<std::string> parts;
141
+ for (size_t i = 0; i < count; i++) {
142
+ parts.push_back(absl::StrFormat("%d", values[i]));
143
+ }
144
+ return absl::StrCat("[", absl::StrJoin(parts, ","), "]");
145
+ }
146
+ } // namespace
147
+
145
148
  std::string grpc_stats_data_as_json(const grpc_stats_data* data) {
146
149
  std::vector<std::string> parts;
147
- parts.push_back("{");
148
150
  for (size_t i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) {
149
151
  parts.push_back(absl::StrFormat(
150
152
  "\"%s\": %" PRIdPTR, grpc_stats_counter_name[i], data->counters[i]));
151
153
  }
152
154
  for (size_t i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) {
153
- parts.push_back(absl::StrFormat("\"%s\": [", grpc_stats_histogram_name[i]));
154
- for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) {
155
- parts.push_back(
156
- absl::StrFormat("%s%" PRIdPTR, j == 0 ? "" : ",",
157
- data->histograms[grpc_stats_histo_start[i] + j]));
158
- }
155
+ parts.push_back(absl::StrFormat(
156
+ "\"%s\": %s", grpc_stats_histogram_name[i],
157
+ ArrayToJson(data->histograms + grpc_stats_histo_start[i],
158
+ grpc_stats_histo_buckets[i])));
159
159
  parts.push_back(
160
- absl::StrFormat("], \"%s_bkt\": [", grpc_stats_histogram_name[i]));
161
- for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) {
162
- parts.push_back(absl::StrFormat(
163
- "%s%d", j == 0 ? "" : ",", grpc_stats_histo_bucket_boundaries[i][j]));
164
- }
165
- parts.push_back("]");
160
+ absl::StrFormat("\"%s_bkt\": %s", grpc_stats_histogram_name[i],
161
+ ArrayToJson(grpc_stats_histo_bucket_boundaries[i],
162
+ grpc_stats_histo_buckets[i])));
166
163
  }
167
- parts.push_back("}");
168
- return absl::StrJoin(parts, "");
164
+ return absl::StrCat("{", absl::StrJoin(parts, ", "), "}");
169
165
  }
@@ -27,7 +27,7 @@
27
27
 
28
28
  #include <grpc/support/atm.h>
29
29
 
30
- #include "src/core/lib/debug/stats_data.h"
30
+ #include "src/core/lib/debug/stats_data.h" // IWYU pragma: export
31
31
  #include "src/core/lib/iomgr/exec_ctx.h"
32
32
 
33
33
  typedef struct grpc_stats_data {
@@ -47,9 +47,6 @@ extern Stats* const g_stats_data;
47
47
  (&::grpc_core::g_stats_data \
48
48
  ->per_cpu[grpc_core::ExecCtx::Get()->starting_cpu()])
49
49
 
50
- /* Only collect stats if GRPC_COLLECT_STATS is defined or it is a debug build.
51
- */
52
- #if defined(GRPC_COLLECT_STATS) || !defined(NDEBUG)
53
50
  #define GRPC_STATS_INC_COUNTER(ctr) \
54
51
  (gpr_atm_no_barrier_fetch_add(&GRPC_THREAD_STATS_DATA()->counters[(ctr)], 1))
55
52
 
@@ -57,24 +54,17 @@ extern Stats* const g_stats_data;
57
54
  (gpr_atm_no_barrier_fetch_add( \
58
55
  &GRPC_THREAD_STATS_DATA()->histograms[histogram##_FIRST_SLOT + (index)], \
59
56
  1))
60
- #else /* defined(GRPC_COLLECT_STATS) || !defined(NDEBUG) */
61
- #define GRPC_STATS_INC_COUNTER(ctr)
62
- #define GRPC_STATS_INC_HISTOGRAM(histogram, index)
63
- #endif /* defined(GRPC_COLLECT_STATS) || !defined(NDEBUG) */
64
57
 
65
- GRPC_DEPRECATED("function is no longer needed")
66
- inline void grpc_stats_init(void) {}
67
58
  void grpc_stats_collect(grpc_stats_data* output);
68
59
  // c = b-a
69
60
  void grpc_stats_diff(const grpc_stats_data* b, const grpc_stats_data* a,
70
61
  grpc_stats_data* c);
71
62
  std::string grpc_stats_data_as_json(const grpc_stats_data* data);
72
- int grpc_stats_histo_find_bucket_slow(int value, const int* table,
73
- int table_size);
74
63
  double grpc_stats_histo_percentile(const grpc_stats_data* stats,
75
64
  grpc_stats_histograms histogram,
76
65
  double percentile);
77
66
  size_t grpc_stats_histo_count(const grpc_stats_data* stats,
78
67
  grpc_stats_histograms histogram);
68
+ void grpc_stats_inc_histogram_value(int histogram, int value);
79
69
 
80
70
  #endif // GRPC_CORE_LIB_DEBUG_STATS_H