grpc 1.13.0 → 1.14.0

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

Potentially problematic release.


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

Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +403 -153
  3. data/include/grpc/grpc.h +0 -8
  4. data/include/grpc/grpc_security.h +59 -2
  5. data/include/grpc/impl/codegen/grpc_types.h +8 -2
  6. data/include/grpc/impl/codegen/log.h +112 -0
  7. data/include/grpc/module.modulemap +2 -0
  8. data/include/grpc/support/log.h +2 -88
  9. data/include/grpc/support/string_util.h +2 -0
  10. data/src/boringssl/err_data.c +597 -593
  11. data/src/core/ext/filters/client_channel/client_channel.cc +715 -770
  12. data/src/core/ext/filters/client_channel/client_channel.h +5 -0
  13. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +111 -0
  14. data/src/core/ext/filters/client_channel/client_channel_channelz.h +69 -0
  15. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +9 -0
  16. data/src/core/ext/filters/client_channel/http_proxy.cc +22 -5
  17. data/src/core/ext/filters/client_channel/lb_policy.h +15 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +3 -0
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +3 -3
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +3 -1
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c +19 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h +54 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c +19 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h +54 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +4 -17
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +37 -63
  27. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +79 -0
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -2
  29. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +8 -0
  30. data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -0
  31. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +2 -2
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +317 -0
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +48 -9
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +40 -293
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +106 -84
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +6 -2
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +6 -5
  38. data/src/core/ext/filters/client_channel/subchannel.cc +36 -6
  39. data/src/core/ext/filters/client_channel/subchannel.h +4 -0
  40. data/src/core/ext/filters/deadline/deadline_filter.cc +18 -15
  41. data/src/core/ext/filters/deadline/deadline_filter.h +5 -5
  42. data/src/core/ext/filters/http/client/http_client_filter.cc +10 -9
  43. data/src/core/ext/filters/http/server/http_server_filter.h +1 -1
  44. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  45. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +3 -2
  46. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +33 -22
  47. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +1 -1
  48. data/src/core/ext/transport/chttp2/transport/internal.h +10 -3
  49. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +17 -0
  50. data/src/core/ext/transport/chttp2/transport/writing.cc +21 -16
  51. data/src/core/ext/transport/inproc/inproc_transport.cc +46 -6
  52. data/src/core/lib/channel/channel_stack.cc +22 -24
  53. data/src/core/lib/channel/channel_trace.cc +28 -63
  54. data/src/core/lib/channel/channel_trace.h +13 -17
  55. data/src/core/lib/channel/channelz.cc +143 -0
  56. data/src/core/lib/channel/channelz.h +124 -0
  57. data/src/core/lib/channel/channelz_registry.cc +7 -24
  58. data/src/core/lib/channel/channelz_registry.h +12 -8
  59. data/src/core/lib/channel/connected_channel.cc +8 -1
  60. data/src/core/{ext/filters/load_reporting/server_load_reporting_filter.h → lib/gpr/alloc.h} +7 -9
  61. data/src/core/lib/gpr/arena.cc +8 -8
  62. data/src/core/lib/gpr/string.cc +28 -0
  63. data/src/core/lib/gpr/string.h +10 -0
  64. data/src/core/lib/gprpp/abstract.h +5 -2
  65. data/src/core/lib/gprpp/inlined_vector.h +57 -3
  66. data/src/core/lib/gprpp/memory.h +2 -2
  67. data/src/core/lib/gprpp/ref_counted_ptr.h +5 -0
  68. data/src/core/lib/gprpp/thd_posix.cc +1 -1
  69. data/src/core/lib/iomgr/call_combiner.h +80 -0
  70. data/src/core/lib/iomgr/closure.h +3 -2
  71. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  72. data/src/core/lib/iomgr/error.cc +12 -0
  73. data/src/core/lib/iomgr/error.h +5 -0
  74. data/src/core/lib/iomgr/ev_epoll1_linux.cc +36 -9
  75. data/src/core/lib/iomgr/ev_epollex_linux.cc +172 -46
  76. data/src/core/lib/iomgr/ev_epollsig_linux.cc +47 -21
  77. data/src/core/lib/iomgr/ev_poll_posix.cc +10 -4
  78. data/src/core/lib/iomgr/ev_posix.cc +17 -9
  79. data/src/core/lib/iomgr/ev_posix.h +20 -4
  80. data/src/core/lib/iomgr/executor.cc +196 -140
  81. data/src/core/lib/iomgr/executor.h +47 -14
  82. data/src/core/lib/iomgr/iomgr.cc +2 -0
  83. data/src/core/lib/iomgr/iomgr.h +5 -0
  84. data/src/core/lib/iomgr/is_epollexclusive_available.cc +1 -0
  85. data/src/core/lib/iomgr/socket_utils.h +9 -0
  86. data/src/core/lib/iomgr/socket_utils_common_posix.cc +4 -0
  87. data/src/core/lib/iomgr/socket_utils_uv.cc +4 -0
  88. data/src/core/lib/iomgr/socket_utils_windows.cc +4 -0
  89. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -5
  90. data/src/core/lib/iomgr/tcp_posix.cc +6 -1
  91. data/src/core/lib/iomgr/tcp_server_posix.cc +3 -3
  92. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +1 -1
  93. data/src/core/lib/iomgr/timer_manager.cc +0 -1
  94. data/src/core/lib/iomgr/udp_server.cc +2 -3
  95. data/src/core/lib/json/json.cc +10 -0
  96. data/src/core/lib/json/json.h +5 -0
  97. data/src/core/lib/security/context/security_context.cc +8 -8
  98. data/src/core/lib/security/context/security_context.h +6 -2
  99. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +2 -1
  100. data/src/core/lib/security/credentials/local/local_credentials.cc +77 -0
  101. data/src/core/lib/security/credentials/local/local_credentials.h +40 -0
  102. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +17 -3
  103. data/src/core/lib/security/security_connector/local_security_connector.cc +245 -0
  104. data/src/core/lib/security/security_connector/local_security_connector.h +58 -0
  105. data/src/core/lib/security/security_connector/security_connector.cc +30 -5
  106. data/src/core/lib/security/security_connector/security_connector.h +1 -0
  107. data/src/core/lib/security/transport/client_auth_filter.cc +5 -1
  108. data/src/core/lib/security/transport/server_auth_filter.cc +4 -5
  109. data/src/core/lib/surface/call.cc +75 -32
  110. data/src/core/lib/surface/call.h +2 -0
  111. data/src/core/lib/surface/channel.cc +32 -13
  112. data/src/core/lib/surface/channel.h +4 -0
  113. data/src/core/lib/surface/version.cc +1 -1
  114. data/src/core/lib/transport/transport.cc +20 -9
  115. data/src/core/lib/transport/transport.h +12 -10
  116. data/src/core/lib/transport/transport_op_string.cc +0 -7
  117. data/src/core/plugin_registry/grpc_plugin_registry.cc +0 -4
  118. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +2 -2
  119. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +2 -1
  120. data/src/core/tsi/alts/handshaker/altscontext.pb.c +0 -1
  121. data/src/core/tsi/alts/handshaker/altscontext.pb.h +1 -2
  122. data/src/core/tsi/alts/handshaker/handshaker.pb.c +0 -1
  123. data/src/core/tsi/alts/handshaker/handshaker.pb.h +1 -2
  124. data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +0 -1
  125. data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +1 -1
  126. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +2 -2
  127. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +47 -1
  128. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h +3 -1
  129. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +12 -11
  130. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h +7 -2
  131. data/src/core/tsi/local_transport_security.cc +209 -0
  132. data/src/core/tsi/local_transport_security.h +51 -0
  133. data/src/core/tsi/ssl_transport_security.cc +2 -3
  134. data/src/{core/ext → cpp/ext/filters}/census/grpc_context.cc +0 -0
  135. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -3
  136. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +18 -18
  137. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +29 -29
  138. data/src/ruby/lib/grpc/generic/active_call.rb +19 -23
  139. data/src/ruby/lib/grpc/version.rb +1 -1
  140. data/src/ruby/spec/call_credentials_spec.rb +1 -1
  141. data/src/ruby/spec/call_spec.rb +1 -1
  142. data/src/ruby/spec/channel_credentials_spec.rb +1 -1
  143. data/src/ruby/spec/channel_spec.rb +1 -1
  144. data/src/ruby/spec/client_auth_spec.rb +1 -12
  145. data/src/ruby/spec/client_server_spec.rb +1 -1
  146. data/src/ruby/spec/compression_options_spec.rb +1 -1
  147. data/src/ruby/spec/error_sanity_spec.rb +1 -1
  148. data/src/ruby/spec/generic/client_stub_spec.rb +13 -1
  149. data/src/ruby/spec/generic/rpc_desc_spec.rb +1 -1
  150. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +1 -1
  151. data/src/ruby/spec/generic/service_spec.rb +1 -1
  152. data/src/ruby/spec/google_rpc_status_utils_spec.rb +1 -12
  153. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +1 -0
  154. data/src/ruby/spec/pb/health/checker_spec.rb +1 -1
  155. data/src/ruby/spec/server_credentials_spec.rb +1 -1
  156. data/src/ruby/spec/server_spec.rb +1 -1
  157. data/src/ruby/spec/spec_helper.rb +1 -0
  158. data/src/ruby/spec/support/services.rb +1 -1
  159. data/src/ruby/spec/time_consts_spec.rb +1 -1
  160. data/third_party/boringssl/crypto/asn1/tasn_dec.c +40 -19
  161. data/third_party/boringssl/crypto/bytestring/cbs.c +1 -0
  162. data/third_party/boringssl/crypto/cipher_extra/e_aesccm.c +47 -15
  163. data/third_party/boringssl/crypto/ec_extra/ec_asn1.c +9 -10
  164. data/third_party/boringssl/crypto/ecdh/ecdh.c +4 -3
  165. data/third_party/boringssl/crypto/fipsmodule/bn/add.c +30 -54
  166. data/third_party/boringssl/crypto/fipsmodule/bn/bn.c +7 -1
  167. data/third_party/boringssl/crypto/fipsmodule/bn/cmp.c +8 -8
  168. data/third_party/boringssl/crypto/fipsmodule/bn/div.c +97 -11
  169. data/third_party/boringssl/crypto/fipsmodule/bn/gcd.c +274 -218
  170. data/third_party/boringssl/crypto/fipsmodule/bn/internal.h +111 -34
  171. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery.c +2 -2
  172. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery_inv.c +1 -1
  173. data/third_party/boringssl/crypto/fipsmodule/bn/mul.c +24 -6
  174. data/third_party/boringssl/crypto/fipsmodule/bn/prime.c +324 -63
  175. data/third_party/boringssl/crypto/fipsmodule/bn/random.c +74 -21
  176. data/third_party/boringssl/crypto/fipsmodule/bn/shift.c +128 -86
  177. data/third_party/boringssl/crypto/fipsmodule/bn/sqrt.c +1 -1
  178. data/third_party/boringssl/crypto/fipsmodule/ec/ec_key.c +67 -112
  179. data/third_party/boringssl/crypto/fipsmodule/ec/internal.h +8 -1
  180. data/third_party/boringssl/crypto/fipsmodule/ec/oct.c +5 -5
  181. data/third_party/boringssl/crypto/fipsmodule/ec/p224-64.c +9 -17
  182. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64-table.h +5378 -5418
  183. data/third_party/boringssl/crypto/fipsmodule/ec/simple.c +32 -32
  184. data/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.c +5 -11
  185. data/third_party/boringssl/crypto/fipsmodule/rsa/blinding.c +16 -40
  186. data/third_party/boringssl/crypto/fipsmodule/rsa/internal.h +1 -6
  187. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa.c +41 -29
  188. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.c +63 -49
  189. data/third_party/boringssl/crypto/x509/vpm_int.h +1 -0
  190. data/third_party/boringssl/crypto/x509/x509_vfy.c +4 -0
  191. data/third_party/boringssl/crypto/x509/x509_vpm.c +44 -22
  192. data/third_party/boringssl/include/openssl/aead.h +8 -2
  193. data/third_party/boringssl/include/openssl/asn1.h +1 -0
  194. data/third_party/boringssl/include/openssl/base.h +4 -0
  195. data/third_party/boringssl/include/openssl/bn.h +13 -3
  196. data/third_party/boringssl/include/openssl/bytestring.h +4 -4
  197. data/third_party/boringssl/include/openssl/ec.h +10 -4
  198. data/third_party/boringssl/include/openssl/ec_key.h +0 -3
  199. data/third_party/boringssl/include/openssl/rsa.h +1 -0
  200. data/third_party/boringssl/include/openssl/ssl.h +8 -3
  201. data/third_party/boringssl/include/openssl/ssl3.h +0 -1
  202. data/third_party/boringssl/include/openssl/x509.h +1 -0
  203. data/third_party/boringssl/include/openssl/x509v3.h +1 -0
  204. data/third_party/boringssl/ssl/handshake_client.cc +36 -64
  205. data/third_party/boringssl/ssl/ssl_cipher.cc +4 -0
  206. data/third_party/boringssl/ssl/ssl_lib.cc +1 -1
  207. metadata +45 -38
  208. data/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +0 -222
  209. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +0 -71
  210. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h +0 -61
  211. data/src/ruby/spec/pb/package_with_underscore/checker_spec.rb +0 -51
  212. data/src/ruby/spec/pb/package_with_underscore/data.proto +0 -23
  213. data/src/ruby/spec/pb/package_with_underscore/service.proto +0 -23
@@ -193,6 +193,7 @@ grpc_server_security_connector* grpc_fake_server_security_connector_create(
193
193
  typedef struct {
194
194
  tsi_ssl_pem_key_cert_pair* pem_key_cert_pair;
195
195
  char* pem_root_certs;
196
+ verify_peer_options verify_options;
196
197
  } grpc_ssl_config;
197
198
 
198
199
  /* Creates an SSL channel_security_connector.
@@ -42,6 +42,7 @@
42
42
  namespace {
43
43
  /* We can have a per-call credentials. */
44
44
  struct call_data {
45
+ gpr_arena* arena;
45
46
  grpc_call_stack* owning_call;
46
47
  grpc_call_combiner* call_combiner;
47
48
  grpc_call_credentials* creds;
@@ -276,10 +277,12 @@ static void auth_start_transport_stream_op_batch(
276
277
  channel_data* chand = static_cast<channel_data*>(elem->channel_data);
277
278
 
278
279
  if (!batch->cancel_stream) {
280
+ // TODO(hcaseyal): move this to init_call_elem once issue #15927 is
281
+ // resolved.
279
282
  GPR_ASSERT(batch->payload->context != nullptr);
280
283
  if (batch->payload->context[GRPC_CONTEXT_SECURITY].value == nullptr) {
281
284
  batch->payload->context[GRPC_CONTEXT_SECURITY].value =
282
- grpc_client_security_context_create();
285
+ grpc_client_security_context_create(calld->arena);
283
286
  batch->payload->context[GRPC_CONTEXT_SECURITY].destroy =
284
287
  grpc_client_security_context_destroy;
285
288
  }
@@ -335,6 +338,7 @@ static void auth_start_transport_stream_op_batch(
335
338
  static grpc_error* init_call_elem(grpc_call_element* elem,
336
339
  const grpc_call_element_args* args) {
337
340
  call_data* calld = static_cast<call_data*>(elem->call_data);
341
+ calld->arena = args->arena;
338
342
  calld->owning_call = args->call_stack;
339
343
  calld->call_combiner = args->call_combiner;
340
344
  calld->host = grpc_empty_slice();
@@ -44,7 +44,6 @@ struct call_data {
44
44
  grpc_metadata_array md;
45
45
  const grpc_metadata* consumed_md;
46
46
  size_t num_consumed_md;
47
- grpc_auth_context* auth_context;
48
47
  grpc_closure cancel_closure;
49
48
  gpr_atm state; // async_state
50
49
  };
@@ -178,7 +177,7 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) {
178
177
  calld->md = metadata_batch_to_md_array(
179
178
  batch->payload->recv_initial_metadata.recv_initial_metadata);
180
179
  chand->creds->processor.process(
181
- chand->creds->processor.state, calld->auth_context,
180
+ chand->creds->processor.state, chand->auth_context,
182
181
  calld->md.metadata, calld->md.count, on_md_processing_done, elem);
183
182
  return;
184
183
  }
@@ -214,9 +213,9 @@ static grpc_error* init_call_elem(grpc_call_element* elem,
214
213
  // Create server security context. Set its auth context from channel
215
214
  // data and save it in the call context.
216
215
  grpc_server_security_context* server_ctx =
217
- grpc_server_security_context_create();
218
- server_ctx->auth_context = grpc_auth_context_create(chand->auth_context);
219
- calld->auth_context = server_ctx->auth_context;
216
+ grpc_server_security_context_create(args->arena);
217
+ server_ctx->auth_context =
218
+ GRPC_AUTH_CONTEXT_REF(chand->auth_context, "server_auth_filter");
220
219
  if (args->context[GRPC_CONTEXT_SECURITY].value != nullptr) {
221
220
  args->context[GRPC_CONTEXT_SECURITY].destroy(
222
221
  args->context[GRPC_CONTEXT_SECURITY].value);
@@ -34,6 +34,7 @@
34
34
  #include "src/core/lib/channel/channel_stack.h"
35
35
  #include "src/core/lib/compression/algorithm_metadata.h"
36
36
  #include "src/core/lib/debug/stats.h"
37
+ #include "src/core/lib/gpr/alloc.h"
37
38
  #include "src/core/lib/gpr/arena.h"
38
39
  #include "src/core/lib/gpr/string.h"
39
40
  #include "src/core/lib/gpr/useful.h"
@@ -233,6 +234,7 @@ struct grpc_call {
233
234
  grpc_closure receiving_slice_ready;
234
235
  grpc_closure receiving_stream_ready;
235
236
  grpc_closure receiving_initial_metadata_ready;
237
+ grpc_closure receiving_trailing_metadata_ready;
236
238
  uint32_t test_only_last_message_flags;
237
239
 
238
240
  grpc_closure release_call;
@@ -270,8 +272,13 @@ struct grpc_call {
270
272
  grpc_core::TraceFlag grpc_call_error_trace(false, "call_error");
271
273
  grpc_core::TraceFlag grpc_compression_trace(false, "compression");
272
274
 
273
- #define CALL_STACK_FROM_CALL(call) ((grpc_call_stack*)((call) + 1))
274
- #define CALL_FROM_CALL_STACK(call_stack) (((grpc_call*)(call_stack)) - 1)
275
+ #define CALL_STACK_FROM_CALL(call) \
276
+ (grpc_call_stack*)((char*)(call) + \
277
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call)))
278
+ #define CALL_FROM_CALL_STACK(call_stack) \
279
+ (grpc_call*)(((char*)(call_stack)) - \
280
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call)))
281
+
275
282
  #define CALL_ELEM_FROM_CALL(call, idx) \
276
283
  grpc_call_stack_element(CALL_STACK_FROM_CALL(call), idx)
277
284
  #define CALL_FROM_TOP_ELEM(top_elem) \
@@ -342,8 +349,9 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
342
349
  size_t initial_size = grpc_channel_get_call_size_estimate(args->channel);
343
350
  GRPC_STATS_INC_CALL_INITIAL_SIZE(initial_size);
344
351
  gpr_arena* arena = gpr_arena_create(initial_size);
345
- call = static_cast<grpc_call*>(gpr_arena_alloc(
346
- arena, sizeof(grpc_call) + channel_stack->call_stack_size));
352
+ call = static_cast<grpc_call*>(
353
+ gpr_arena_alloc(arena, GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call)) +
354
+ channel_stack->call_stack_size));
347
355
  gpr_ref_init(&call->ext_ref, 1);
348
356
  call->arena = arena;
349
357
  grpc_call_combiner_init(&call->call_combiner);
@@ -478,6 +486,12 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
478
486
  &call->pollent);
479
487
  }
480
488
 
489
+ grpc_core::channelz::ChannelNode* channelz_channel =
490
+ grpc_channel_get_channelz_node(call->channel);
491
+ if (channelz_channel != nullptr) {
492
+ channelz_channel->RecordCallStarted();
493
+ }
494
+
481
495
  grpc_slice_unref_internal(path);
482
496
 
483
497
  return error;
@@ -520,7 +534,6 @@ static void release_call(void* call, grpc_error* error) {
520
534
  GRPC_CHANNEL_INTERNAL_UNREF(channel, "call");
521
535
  }
522
536
 
523
- static void set_status_value_directly(grpc_status_code status, void* dest);
524
537
  static void destroy_call(void* call, grpc_error* error) {
525
538
  GPR_TIMER_SCOPE("destroy_call", 0);
526
539
  size_t i;
@@ -1076,13 +1089,12 @@ static void recv_trailing_filter(void* args, grpc_metadata_batch* b) {
1076
1089
  if (b->idx.named.grpc_status != nullptr) {
1077
1090
  grpc_status_code status_code =
1078
1091
  grpc_get_status_code_from_metadata(b->idx.named.grpc_status->md);
1079
- grpc_error* error =
1080
- status_code == GRPC_STATUS_OK
1081
- ? GRPC_ERROR_NONE
1082
- : grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1083
- "Error received from peer"),
1084
- GRPC_ERROR_INT_GRPC_STATUS,
1085
- static_cast<intptr_t>(status_code));
1092
+ grpc_error* error = GRPC_ERROR_NONE;
1093
+ if (status_code != GRPC_STATUS_OK) {
1094
+ error = grpc_error_set_int(
1095
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error received from peer"),
1096
+ GRPC_ERROR_INT_GRPC_STATUS, static_cast<intptr_t>(status_code));
1097
+ }
1086
1098
  if (b->idx.named.grpc_message != nullptr) {
1087
1099
  error = grpc_error_set_str(
1088
1100
  error, GRPC_ERROR_STR_GRPC_MESSAGE,
@@ -1098,6 +1110,8 @@ static void recv_trailing_filter(void* args, grpc_metadata_batch* b) {
1098
1110
  publish_app_metadata(call, b, true);
1099
1111
  }
1100
1112
 
1113
+ gpr_arena* grpc_call_get_arena(grpc_call* call) { return call->arena; }
1114
+
1101
1115
  grpc_call_stack* grpc_call_get_call_stack(grpc_call* call) {
1102
1116
  return CALL_STACK_FROM_CALL(call);
1103
1117
  }
@@ -1209,7 +1223,6 @@ static void post_batch_completion(batch_control* bctl) {
1209
1223
 
1210
1224
  if (bctl->op.send_initial_metadata) {
1211
1225
  grpc_metadata_batch_destroy(
1212
-
1213
1226
  &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]);
1214
1227
  }
1215
1228
  if (bctl->op.send_message) {
@@ -1217,14 +1230,9 @@ static void post_batch_completion(batch_control* bctl) {
1217
1230
  }
1218
1231
  if (bctl->op.send_trailing_metadata) {
1219
1232
  grpc_metadata_batch_destroy(
1220
-
1221
1233
  &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]);
1222
1234
  }
1223
1235
  if (bctl->op.recv_trailing_metadata) {
1224
- grpc_metadata_batch* md =
1225
- &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */];
1226
- recv_trailing_filter(call, md);
1227
-
1228
1236
  /* propagate cancellation to any interested children */
1229
1237
  gpr_atm_rel_store(&call->received_final_op_atm, 1);
1230
1238
  parent_call* pc = get_parent_call(call);
@@ -1246,7 +1254,6 @@ static void post_batch_completion(batch_control* bctl) {
1246
1254
  }
1247
1255
  gpr_mu_unlock(&pc->child_list_mu);
1248
1256
  }
1249
-
1250
1257
  if (call->is_client) {
1251
1258
  get_final_status(call, set_status_value_directly,
1252
1259
  call->final_op.client.status,
@@ -1256,7 +1263,15 @@ static void post_batch_completion(batch_control* bctl) {
1256
1263
  get_final_status(call, set_cancelled_value,
1257
1264
  call->final_op.server.cancelled, nullptr, nullptr);
1258
1265
  }
1259
-
1266
+ grpc_core::channelz::ChannelNode* channelz_channel =
1267
+ grpc_channel_get_channelz_node(call->channel);
1268
+ if (channelz_channel != nullptr) {
1269
+ if (*call->final_op.client.status != GRPC_STATUS_OK) {
1270
+ channelz_channel->RecordCallFailed();
1271
+ } else {
1272
+ channelz_channel->RecordCallSucceeded();
1273
+ }
1274
+ }
1260
1275
  GRPC_ERROR_UNREF(error);
1261
1276
  error = GRPC_ERROR_NONE;
1262
1277
  }
@@ -1538,6 +1553,17 @@ static void receiving_initial_metadata_ready(void* bctlp, grpc_error* error) {
1538
1553
  finish_batch_step(bctl);
1539
1554
  }
1540
1555
 
1556
+ static void receiving_trailing_metadata_ready(void* bctlp, grpc_error* error) {
1557
+ batch_control* bctl = static_cast<batch_control*>(bctlp);
1558
+ grpc_call* call = bctl->call;
1559
+ GRPC_CALL_COMBINER_STOP(&call->call_combiner, "recv_trailing_metadata_ready");
1560
+ add_batch_error(bctl, GRPC_ERROR_REF(error), false);
1561
+ grpc_metadata_batch* md =
1562
+ &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */];
1563
+ recv_trailing_filter(call, md);
1564
+ finish_batch_step(bctl);
1565
+ }
1566
+
1541
1567
  static void finish_batch(void* bctlp, grpc_error* error) {
1542
1568
  batch_control* bctl = static_cast<batch_control*>(bctlp);
1543
1569
  grpc_call* call = bctl->call;
@@ -1558,7 +1584,8 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1558
1584
  size_t i;
1559
1585
  const grpc_op* op;
1560
1586
  batch_control* bctl;
1561
- int num_completion_callbacks_needed = 1;
1587
+ bool has_send_ops = false;
1588
+ int num_recv_ops = 0;
1562
1589
  grpc_call_error error = GRPC_CALL_OK;
1563
1590
  grpc_transport_stream_op_batch* stream_op;
1564
1591
  grpc_transport_stream_op_batch_payload* stream_op_payload;
@@ -1664,6 +1691,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1664
1691
  stream_op_payload->send_initial_metadata.peer_string =
1665
1692
  &call->peer_string;
1666
1693
  }
1694
+ has_send_ops = true;
1667
1695
  break;
1668
1696
  }
1669
1697
  case GRPC_OP_SEND_MESSAGE: {
@@ -1693,6 +1721,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1693
1721
  &op->data.send_message.send_message->data.raw.slice_buffer, flags);
1694
1722
  stream_op_payload->send_message.send_message.reset(
1695
1723
  call->sending_stream.get());
1724
+ has_send_ops = true;
1696
1725
  break;
1697
1726
  }
1698
1727
  case GRPC_OP_SEND_CLOSE_FROM_CLIENT: {
@@ -1713,6 +1742,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1713
1742
  call->sent_final_op = true;
1714
1743
  stream_op_payload->send_trailing_metadata.send_trailing_metadata =
1715
1744
  &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */];
1745
+ has_send_ops = true;
1716
1746
  break;
1717
1747
  }
1718
1748
  case GRPC_OP_SEND_STATUS_FROM_SERVER: {
@@ -1777,6 +1807,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1777
1807
  }
1778
1808
  stream_op_payload->send_trailing_metadata.send_trailing_metadata =
1779
1809
  &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */];
1810
+ has_send_ops = true;
1780
1811
  break;
1781
1812
  }
1782
1813
  case GRPC_OP_RECV_INITIAL_METADATA: {
@@ -1804,7 +1835,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1804
1835
  stream_op_payload->recv_initial_metadata.peer_string =
1805
1836
  &call->peer_string;
1806
1837
  }
1807
- num_completion_callbacks_needed++;
1838
+ ++num_recv_ops;
1808
1839
  break;
1809
1840
  }
1810
1841
  case GRPC_OP_RECV_MESSAGE: {
@@ -1826,7 +1857,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1826
1857
  grpc_schedule_on_exec_ctx);
1827
1858
  stream_op_payload->recv_message.recv_message_ready =
1828
1859
  &call->receiving_stream_ready;
1829
- num_completion_callbacks_needed++;
1860
+ ++num_recv_ops;
1830
1861
  break;
1831
1862
  }
1832
1863
  case GRPC_OP_RECV_STATUS_ON_CLIENT: {
@@ -1852,11 +1883,16 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1852
1883
  call->final_op.client.error_string =
1853
1884
  op->data.recv_status_on_client.error_string;
1854
1885
  stream_op->recv_trailing_metadata = true;
1855
- stream_op->collect_stats = true;
1856
1886
  stream_op_payload->recv_trailing_metadata.recv_trailing_metadata =
1857
1887
  &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */];
1858
- stream_op_payload->collect_stats.collect_stats =
1888
+ stream_op_payload->recv_trailing_metadata.collect_stats =
1859
1889
  &call->final_info.stats.transport_stream_stats;
1890
+ GRPC_CLOSURE_INIT(&call->receiving_trailing_metadata_ready,
1891
+ receiving_trailing_metadata_ready, bctl,
1892
+ grpc_schedule_on_exec_ctx);
1893
+ stream_op_payload->recv_trailing_metadata.recv_trailing_metadata_ready =
1894
+ &call->receiving_trailing_metadata_ready;
1895
+ ++num_recv_ops;
1860
1896
  break;
1861
1897
  }
1862
1898
  case GRPC_OP_RECV_CLOSE_ON_SERVER: {
@@ -1877,11 +1913,16 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1877
1913
  call->final_op.server.cancelled =
1878
1914
  op->data.recv_close_on_server.cancelled;
1879
1915
  stream_op->recv_trailing_metadata = true;
1880
- stream_op->collect_stats = true;
1881
1916
  stream_op_payload->recv_trailing_metadata.recv_trailing_metadata =
1882
1917
  &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */];
1883
- stream_op_payload->collect_stats.collect_stats =
1918
+ stream_op_payload->recv_trailing_metadata.collect_stats =
1884
1919
  &call->final_info.stats.transport_stream_stats;
1920
+ GRPC_CLOSURE_INIT(&call->receiving_trailing_metadata_ready,
1921
+ receiving_trailing_metadata_ready, bctl,
1922
+ grpc_schedule_on_exec_ctx);
1923
+ stream_op_payload->recv_trailing_metadata.recv_trailing_metadata_ready =
1924
+ &call->receiving_trailing_metadata_ready;
1925
+ ++num_recv_ops;
1885
1926
  break;
1886
1927
  }
1887
1928
  }
@@ -1891,13 +1932,15 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
1891
1932
  if (!is_notify_tag_closure) {
1892
1933
  GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag));
1893
1934
  }
1894
- gpr_ref_init(&bctl->steps_to_complete, num_completion_callbacks_needed);
1935
+ gpr_ref_init(&bctl->steps_to_complete, (has_send_ops ? 1 : 0) + num_recv_ops);
1895
1936
 
1896
- GRPC_CLOSURE_INIT(&bctl->finish_batch, finish_batch, bctl,
1897
- grpc_schedule_on_exec_ctx);
1898
- stream_op->on_complete = &bctl->finish_batch;
1899
- gpr_atm_rel_store(&call->any_ops_sent_atm, 1);
1937
+ if (has_send_ops) {
1938
+ GRPC_CLOSURE_INIT(&bctl->finish_batch, finish_batch, bctl,
1939
+ grpc_schedule_on_exec_ctx);
1940
+ stream_op->on_complete = &bctl->finish_batch;
1941
+ }
1900
1942
 
1943
+ gpr_atm_rel_store(&call->any_ops_sent_atm, 1);
1901
1944
  execute_batch(call, stream_op, &bctl->start_batch);
1902
1945
 
1903
1946
  done:
@@ -71,6 +71,8 @@ void grpc_call_internal_unref(grpc_call* call);
71
71
  #define GRPC_CALL_INTERNAL_UNREF(call, reason) grpc_call_internal_unref(call)
72
72
  #endif
73
73
 
74
+ gpr_arena* grpc_call_get_arena(grpc_call* call);
75
+
74
76
  grpc_call_stack* grpc_call_get_call_stack(grpc_call* call);
75
77
 
76
78
  grpc_call_error grpc_call_start_batch_and_execute(grpc_call* call,
@@ -32,6 +32,7 @@
32
32
 
33
33
  #include "src/core/lib/channel/channel_args.h"
34
34
  #include "src/core/lib/channel/channel_trace.h"
35
+ #include "src/core/lib/channel/channelz.h"
35
36
  #include "src/core/lib/debug/stats.h"
36
37
  #include "src/core/lib/gpr/string.h"
37
38
  #include "src/core/lib/gprpp/manual_constructor.h"
@@ -66,7 +67,7 @@ struct grpc_channel {
66
67
  gpr_mu registered_call_mu;
67
68
  registered_call* registered_calls;
68
69
 
69
- grpc_core::RefCountedPtr<grpc_core::ChannelTrace> tracer;
70
+ grpc_core::RefCountedPtr<grpc_core::channelz::ChannelNode> channelz_channel;
70
71
 
71
72
  char* target;
72
73
  };
@@ -103,6 +104,11 @@ grpc_channel* grpc_channel_create_with_builder(
103
104
  channel->target = target;
104
105
  channel->is_client = grpc_channel_stack_type_is_client(channel_stack_type);
105
106
  size_t channel_tracer_max_nodes = 0; // default to off
107
+ bool channelz_enabled = false;
108
+ // this creates the default ChannelNode. Different types of channels may
109
+ // override this to ensure a correct ChannelNode is created.
110
+ grpc_core::channelz::ChannelNodeCreationFunc channel_node_create_func =
111
+ grpc_core::channelz::ChannelNode::MakeChannelNode;
106
112
  gpr_mu_init(&channel->registered_call_mu);
107
113
  channel->registered_calls = nullptr;
108
114
 
@@ -141,15 +147,28 @@ grpc_channel* grpc_channel_create_with_builder(
141
147
  const grpc_integer_options options = {0, 0, INT_MAX};
142
148
  channel_tracer_max_nodes =
143
149
  (size_t)grpc_channel_arg_get_integer(&args->args[i], options);
150
+ } else if (0 == strcmp(args->args[i].key, GRPC_ARG_ENABLE_CHANNELZ)) {
151
+ // channelz will not be enabled by default until all concerns in
152
+ // https://github.com/grpc/grpc/issues/15986 are addressed.
153
+ channelz_enabled = grpc_channel_arg_get_bool(&args->args[i], false);
154
+ } else if (0 == strcmp(args->args[i].key,
155
+ GRPC_ARG_CHANNELZ_CHANNEL_NODE_CREATION_FUNC)) {
156
+ GPR_ASSERT(args->args[i].type == GRPC_ARG_POINTER);
157
+ GPR_ASSERT(args->args[i].value.pointer.p != nullptr);
158
+ channel_node_create_func =
159
+ reinterpret_cast<grpc_core::channelz::ChannelNodeCreationFunc>(
160
+ args->args[i].value.pointer.p);
144
161
  }
145
162
  }
146
163
 
147
164
  grpc_channel_args_destroy(args);
148
- channel->tracer = grpc_core::MakeRefCounted<grpc_core::ChannelTrace>(
149
- channel_tracer_max_nodes);
150
- channel->tracer->AddTraceEvent(
151
- grpc_core::ChannelTrace::Severity::Info,
152
- grpc_slice_from_static_string("Channel created"));
165
+ if (channelz_enabled) {
166
+ channel->channelz_channel =
167
+ channel_node_create_func(channel, channel_tracer_max_nodes);
168
+ channel->channelz_channel->trace()->AddTraceEvent(
169
+ grpc_core::channelz::ChannelTrace::Severity::Info,
170
+ grpc_slice_from_static_string("Channel created"));
171
+ }
153
172
  return channel;
154
173
  }
155
174
 
@@ -184,12 +203,9 @@ static grpc_channel_args* build_channel_args(
184
203
  return grpc_channel_args_copy_and_add(input_args, new_args, num_new_args);
185
204
  }
186
205
 
187
- char* grpc_channel_get_trace(grpc_channel* channel) {
188
- return channel->tracer->RenderTrace();
189
- }
190
-
191
- intptr_t grpc_channel_get_uuid(grpc_channel* channel) {
192
- return channel->tracer->GetUuid();
206
+ grpc_core::channelz::ChannelNode* grpc_channel_get_channelz_node(
207
+ grpc_channel* channel) {
208
+ return channel->channelz_channel.get();
193
209
  }
194
210
 
195
211
  grpc_channel* grpc_channel_create(const char* target,
@@ -395,6 +411,10 @@ void grpc_channel_internal_unref(grpc_channel* c REF_ARG) {
395
411
 
396
412
  static void destroy_channel(void* arg, grpc_error* error) {
397
413
  grpc_channel* channel = static_cast<grpc_channel*>(arg);
414
+ if (channel->channelz_channel != nullptr) {
415
+ channel->channelz_channel->MarkChannelDestroyed();
416
+ channel->channelz_channel.reset();
417
+ }
398
418
  grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel));
399
419
  while (channel->registered_calls) {
400
420
  registered_call* rc = channel->registered_calls;
@@ -403,7 +423,6 @@ static void destroy_channel(void* arg, grpc_error* error) {
403
423
  GRPC_MDELEM_UNREF(rc->authority);
404
424
  gpr_free(rc);
405
425
  }
406
- channel->tracer.reset();
407
426
  gpr_mu_destroy(&channel->registered_call_mu);
408
427
  gpr_free(channel->target);
409
428
  gpr_free(channel);
@@ -23,6 +23,7 @@
23
23
 
24
24
  #include "src/core/lib/channel/channel_stack.h"
25
25
  #include "src/core/lib/channel/channel_stack_builder.h"
26
+ #include "src/core/lib/channel/channelz.h"
26
27
  #include "src/core/lib/surface/channel_stack_type.h"
27
28
 
28
29
  grpc_channel* grpc_channel_create(const char* target,
@@ -50,6 +51,9 @@ grpc_call* grpc_channel_create_pollset_set_call(
50
51
  /** Get a (borrowed) pointer to this channels underlying channel stack */
51
52
  grpc_channel_stack* grpc_channel_get_channel_stack(grpc_channel* channel);
52
53
 
54
+ grpc_core::channelz::ChannelNode* grpc_channel_get_channelz_node(
55
+ grpc_channel* channel);
56
+
53
57
  /** Get a grpc_mdelem of grpc-status: X where X is the numeric value of
54
58
  status_code.
55
59