grpc 1.16.0 → 1.17.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 (173) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +299 -133
  3. data/include/grpc/grpc.h +11 -1
  4. data/include/grpc/grpc_posix.h +0 -8
  5. data/include/grpc/impl/codegen/grpc_types.h +3 -0
  6. data/src/core/ext/filters/client_channel/client_channel.cc +336 -345
  7. data/src/core/ext/filters/client_channel/client_channel.h +6 -2
  8. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +3 -1
  9. data/src/core/ext/filters/client_channel/client_channel_channelz.h +0 -7
  10. data/src/core/ext/filters/client_channel/health/health.pb.c +23 -0
  11. data/src/core/ext/filters/client_channel/health/health.pb.h +73 -0
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +652 -0
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +173 -0
  14. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -1
  15. data/src/core/ext/filters/client_channel/http_proxy.cc +1 -1
  16. data/src/core/ext/filters/client_channel/lb_policy.h +17 -14
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +15 -11
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +21 -15
  19. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +18 -10
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +12 -9
  21. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +19 -8
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1832 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +36 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +36 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +107 -0
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc +85 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h +72 -0
  28. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +307 -0
  29. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +89 -0
  30. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +5 -0
  32. data/src/core/ext/filters/client_channel/lb_policy_registry.h +4 -0
  33. data/src/core/ext/filters/client_channel/parse_address.h +1 -1
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +19 -22
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +41 -39
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +3 -2
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -1
  38. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +15 -2
  39. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +5 -1
  40. data/src/core/ext/filters/client_channel/resolver_factory.h +1 -1
  41. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +384 -0
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +146 -0
  43. data/src/core/ext/filters/client_channel/subchannel.cc +361 -103
  44. data/src/core/ext/filters/client_channel/subchannel.h +14 -8
  45. data/src/core/ext/filters/deadline/deadline_filter.cc +19 -23
  46. data/src/core/ext/filters/deadline/deadline_filter.h +9 -13
  47. data/src/core/ext/filters/http/client/http_client_filter.cc +29 -19
  48. data/src/core/ext/filters/http/client_authority_filter.cc +2 -3
  49. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +28 -16
  50. data/src/core/ext/filters/http/server/http_server_filter.cc +31 -20
  51. data/src/core/ext/filters/message_size/message_size_filter.cc +50 -45
  52. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -6
  53. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +1 -1
  54. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +58 -8
  55. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +175 -173
  57. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -1
  58. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -10
  59. data/src/core/ext/transport/chttp2/transport/frame_data.h +10 -12
  60. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +1 -1
  61. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +28 -25
  62. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +0 -12
  63. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +12 -9
  64. data/src/core/ext/transport/chttp2/transport/internal.h +109 -94
  65. data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -2
  66. data/src/core/ext/transport/inproc/inproc_transport.cc +280 -300
  67. data/src/core/lib/channel/channel_stack.cc +5 -4
  68. data/src/core/lib/channel/channel_stack.h +4 -4
  69. data/src/core/lib/channel/channel_stack_builder.cc +14 -2
  70. data/src/core/lib/channel/channel_stack_builder.h +8 -0
  71. data/src/core/lib/channel/channel_trace.cc +6 -2
  72. data/src/core/lib/channel/channelz.cc +137 -5
  73. data/src/core/lib/channel/channelz.h +32 -6
  74. data/src/core/lib/channel/channelz_registry.cc +134 -28
  75. data/src/core/lib/channel/channelz_registry.h +25 -3
  76. data/src/core/lib/channel/context.h +4 -4
  77. data/src/core/lib/channel/handshaker.cc +7 -6
  78. data/src/core/lib/channel/handshaker.h +7 -8
  79. data/src/core/lib/channel/handshaker_factory.cc +3 -2
  80. data/src/core/lib/channel/handshaker_factory.h +2 -0
  81. data/src/core/lib/channel/handshaker_registry.cc +6 -2
  82. data/src/core/lib/channel/handshaker_registry.h +1 -0
  83. data/src/core/lib/gpr/arena.cc +84 -37
  84. data/src/core/lib/gpr/arena.h +2 -0
  85. data/src/core/lib/gpr/mpscq.h +4 -2
  86. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  87. data/src/core/lib/gprpp/ref_counted.h +105 -18
  88. data/src/core/lib/gprpp/ref_counted_ptr.h +11 -0
  89. data/src/core/lib/http/httpcli_security_connector.cc +7 -4
  90. data/src/core/lib/iomgr/call_combiner.cc +2 -0
  91. data/src/core/lib/iomgr/call_combiner.h +2 -2
  92. data/src/core/lib/iomgr/closure.h +1 -0
  93. data/src/core/lib/iomgr/error.cc +16 -31
  94. data/src/core/lib/iomgr/error.h +29 -4
  95. data/src/core/lib/iomgr/error_internal.h +0 -2
  96. data/src/core/lib/iomgr/ev_epoll1_linux.cc +7 -3
  97. data/src/core/lib/iomgr/ev_posix.cc +0 -2
  98. data/src/core/lib/iomgr/polling_entity.h +4 -4
  99. data/src/core/lib/iomgr/resource_quota.cc +64 -10
  100. data/src/core/lib/iomgr/resource_quota.h +21 -6
  101. data/src/core/lib/iomgr/socket_utils_common_posix.cc +11 -5
  102. data/src/core/lib/iomgr/tcp_client_custom.cc +14 -3
  103. data/src/core/lib/iomgr/tcp_client_posix.cc +2 -0
  104. data/src/core/lib/iomgr/tcp_posix.cc +4 -2
  105. data/src/core/lib/iomgr/timer_manager.cc +1 -1
  106. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +3 -4
  107. data/src/core/lib/security/context/security_context.cc +20 -13
  108. data/src/core/lib/security/context/security_context.h +27 -19
  109. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  110. data/src/core/lib/security/credentials/credentials.h +2 -2
  111. data/src/core/lib/security/credentials/fake/fake_credentials.cc +1 -0
  112. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +39 -54
  113. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +3 -2
  114. data/src/core/lib/security/credentials/local/local_credentials.cc +1 -1
  115. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -2
  116. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -0
  117. data/src/core/lib/security/security_connector/{alts_security_connector.cc → alts/alts_security_connector.cc} +10 -9
  118. data/src/core/lib/security/security_connector/{alts_security_connector.h → alts/alts_security_connector.h} +3 -3
  119. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +310 -0
  120. data/src/core/lib/security/security_connector/fake/fake_security_connector.h +42 -0
  121. data/src/core/lib/security/security_connector/{local_security_connector.cc → local/local_security_connector.cc} +4 -3
  122. data/src/core/lib/security/security_connector/{local_security_connector.h → local/local_security_connector.h} +3 -3
  123. data/src/core/lib/security/security_connector/security_connector.cc +4 -1039
  124. data/src/core/lib/security/security_connector/security_connector.h +6 -114
  125. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +474 -0
  126. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +77 -0
  127. data/src/core/lib/security/security_connector/ssl_utils.cc +345 -0
  128. data/src/core/lib/security/security_connector/ssl_utils.h +93 -0
  129. data/src/core/lib/security/transport/client_auth_filter.cc +28 -17
  130. data/src/core/lib/security/transport/secure_endpoint.cc +51 -41
  131. data/src/core/lib/security/transport/security_handshaker.cc +6 -7
  132. data/src/core/lib/security/transport/server_auth_filter.cc +39 -31
  133. data/src/core/lib/surface/call.cc +100 -80
  134. data/src/core/lib/surface/call.h +4 -0
  135. data/src/core/lib/surface/channel.cc +27 -13
  136. data/src/core/lib/surface/channel.h +4 -3
  137. data/src/core/lib/surface/completion_queue.cc +8 -1
  138. data/src/core/lib/surface/init.cc +1 -0
  139. data/src/core/lib/surface/server.cc +111 -46
  140. data/src/core/lib/surface/server.h +16 -2
  141. data/src/core/lib/surface/version.cc +2 -2
  142. data/src/core/lib/transport/error_utils.cc +4 -2
  143. data/src/core/lib/transport/metadata.cc +3 -2
  144. data/src/core/lib/transport/metadata.h +3 -2
  145. data/src/core/lib/transport/metadata_batch.cc +1 -0
  146. data/src/core/lib/transport/metadata_batch.h +4 -2
  147. data/src/core/lib/transport/static_metadata.cc +225 -221
  148. data/src/core/lib/transport/static_metadata.h +74 -71
  149. data/src/core/lib/transport/transport.h +44 -26
  150. data/src/core/{ext/filters/client_channel → lib/uri}/uri_parser.cc +1 -1
  151. data/src/core/{ext/filters/client_channel → lib/uri}/uri_parser.h +3 -3
  152. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -4
  153. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +356 -77
  154. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +46 -36
  155. data/src/core/tsi/alts/handshaker/alts_shared_resource.cc +83 -0
  156. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +73 -0
  157. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +122 -175
  158. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +33 -22
  159. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h +38 -10
  160. data/src/core/tsi/transport_security.cc +18 -1
  161. data/src/core/tsi/transport_security.h +2 -1
  162. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -2
  163. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -3
  164. data/src/ruby/lib/grpc/version.rb +1 -1
  165. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  166. data/src/ruby/spec/pb/codegen/package_option_spec.rb +2 -3
  167. metadata +58 -40
  168. data/src/core/ext/filters/client_channel/method_params.cc +0 -178
  169. data/src/core/ext/filters/client_channel/method_params.h +0 -78
  170. data/src/core/tsi/alts/handshaker/alts_tsi_event.cc +0 -75
  171. data/src/core/tsi/alts/handshaker/alts_tsi_event.h +0 -93
  172. data/src/core/tsi/alts_transport_security.cc +0 -65
  173. data/src/core/tsi/alts_transport_security.h +0 -47
@@ -157,7 +157,6 @@ grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack,
157
157
  size_t count = channel_stack->count;
158
158
  grpc_call_element* call_elems;
159
159
  char* user_data;
160
- size_t i;
161
160
 
162
161
  elem_args->call_stack->count = count;
163
162
  GRPC_STREAM_REF_INIT(&elem_args->call_stack->refcount, initial_refs, destroy,
@@ -168,10 +167,14 @@ grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack,
168
167
 
169
168
  /* init per-filter data */
170
169
  grpc_error* first_error = GRPC_ERROR_NONE;
171
- for (i = 0; i < count; i++) {
170
+ for (size_t i = 0; i < count; i++) {
172
171
  call_elems[i].filter = channel_elems[i].filter;
173
172
  call_elems[i].channel_data = channel_elems[i].channel_data;
174
173
  call_elems[i].call_data = user_data;
174
+ user_data +=
175
+ GPR_ROUND_UP_TO_ALIGNMENT_SIZE(call_elems[i].filter->sizeof_call_data);
176
+ }
177
+ for (size_t i = 0; i < count; i++) {
175
178
  grpc_error* error =
176
179
  call_elems[i].filter->init_call_elem(&call_elems[i], elem_args);
177
180
  if (error != GRPC_ERROR_NONE) {
@@ -181,8 +184,6 @@ grpc_error* grpc_call_stack_init(grpc_channel_stack* channel_stack,
181
184
  GRPC_ERROR_UNREF(error);
182
185
  }
183
186
  }
184
- user_data +=
185
- GPR_ROUND_UP_TO_ALIGNMENT_SIZE(call_elems[i].filter->sizeof_call_data);
186
187
  }
187
188
  return first_error;
188
189
  }
@@ -79,11 +79,11 @@ typedef struct {
79
79
  } grpc_call_stats;
80
80
 
81
81
  /** Information about the call upon completion. */
82
- typedef struct {
82
+ struct grpc_call_final_info {
83
83
  grpc_call_stats stats;
84
- grpc_status_code final_status;
85
- const char* error_string;
86
- } grpc_call_final_info;
84
+ grpc_status_code final_status = GRPC_STATUS_OK;
85
+ const char* error_string = nullptr;
86
+ };
87
87
 
88
88
  /* Channel filters specify:
89
89
  1. the amount of memory needed in the channel & call (via the sizeof_XXX
@@ -40,6 +40,7 @@ struct grpc_channel_stack_builder {
40
40
  // various set/get-able parameters
41
41
  grpc_channel_args* args;
42
42
  grpc_transport* transport;
43
+ grpc_resource_user* resource_user;
43
44
  char* target;
44
45
  const char* name;
45
46
  };
@@ -157,6 +158,11 @@ void grpc_channel_stack_builder_set_channel_arguments(
157
158
  builder->args = grpc_channel_args_copy(args);
158
159
  }
159
160
 
161
+ const grpc_channel_args* grpc_channel_stack_builder_get_channel_arguments(
162
+ grpc_channel_stack_builder* builder) {
163
+ return builder->args;
164
+ }
165
+
160
166
  void grpc_channel_stack_builder_set_transport(
161
167
  grpc_channel_stack_builder* builder, grpc_transport* transport) {
162
168
  GPR_ASSERT(builder->transport == nullptr);
@@ -168,9 +174,15 @@ grpc_transport* grpc_channel_stack_builder_get_transport(
168
174
  return builder->transport;
169
175
  }
170
176
 
171
- const grpc_channel_args* grpc_channel_stack_builder_get_channel_arguments(
177
+ void grpc_channel_stack_builder_set_resource_user(
178
+ grpc_channel_stack_builder* builder, grpc_resource_user* resource_user) {
179
+ GPR_ASSERT(builder->resource_user == nullptr);
180
+ builder->resource_user = resource_user;
181
+ }
182
+
183
+ grpc_resource_user* grpc_channel_stack_builder_get_resource_user(
172
184
  grpc_channel_stack_builder* builder) {
173
- return builder->args;
185
+ return builder->resource_user;
174
186
  }
175
187
 
176
188
  bool grpc_channel_stack_builder_append_filter(
@@ -54,6 +54,14 @@ void grpc_channel_stack_builder_set_transport(
54
54
  grpc_transport* grpc_channel_stack_builder_get_transport(
55
55
  grpc_channel_stack_builder* builder);
56
56
 
57
+ /// Attach \a resource_user to the builder (does not take ownership)
58
+ void grpc_channel_stack_builder_set_resource_user(
59
+ grpc_channel_stack_builder* builder, grpc_resource_user* resource_user);
60
+
61
+ /// Fetch attached resource user
62
+ grpc_resource_user* grpc_channel_stack_builder_get_resource_user(
63
+ grpc_channel_stack_builder* builder);
64
+
57
65
  /// Set channel arguments: copies args
58
66
  void grpc_channel_stack_builder_set_channel_arguments(
59
67
  grpc_channel_stack_builder* builder, const grpc_channel_args* args);
@@ -108,16 +108,20 @@ void ChannelTrace::AddTraceEventHelper(TraceEvent* new_trace_event) {
108
108
  }
109
109
 
110
110
  void ChannelTrace::AddTraceEvent(Severity severity, grpc_slice data) {
111
- if (max_event_memory_ == 0)
111
+ if (max_event_memory_ == 0) {
112
+ grpc_slice_unref_internal(data);
112
113
  return; // tracing is disabled if max_event_memory_ == 0
114
+ }
113
115
  AddTraceEventHelper(New<TraceEvent>(severity, data));
114
116
  }
115
117
 
116
118
  void ChannelTrace::AddTraceEventWithReference(
117
119
  Severity severity, grpc_slice data,
118
120
  RefCountedPtr<BaseNode> referenced_entity) {
119
- if (max_event_memory_ == 0)
121
+ if (max_event_memory_ == 0) {
122
+ grpc_slice_unref_internal(data);
120
123
  return; // tracing is disabled if max_event_memory_ == 0
124
+ }
121
125
  // create and fill up the new event
122
126
  AddTraceEventHelper(
123
127
  New<TraceEvent>(severity, data, std::move(referenced_entity)));
@@ -30,20 +30,26 @@
30
30
 
31
31
  #include "src/core/lib/channel/channelz_registry.h"
32
32
  #include "src/core/lib/channel/status_util.h"
33
+ #include "src/core/lib/gpr/host_port.h"
33
34
  #include "src/core/lib/gpr/string.h"
34
35
  #include "src/core/lib/gpr/useful.h"
35
36
  #include "src/core/lib/gprpp/memory.h"
36
37
  #include "src/core/lib/iomgr/error.h"
37
38
  #include "src/core/lib/iomgr/exec_ctx.h"
39
+ #include "src/core/lib/slice/b64.h"
38
40
  #include "src/core/lib/slice/slice_internal.h"
39
41
  #include "src/core/lib/surface/channel.h"
42
+ #include "src/core/lib/surface/server.h"
40
43
  #include "src/core/lib/transport/error_utils.h"
44
+ #include "src/core/lib/uri/uri_parser.h"
41
45
 
42
46
  namespace grpc_core {
43
47
  namespace channelz {
44
48
 
45
- BaseNode::BaseNode(EntityType type)
46
- : type_(type), uuid_(ChannelzRegistry::Register(this)) {}
49
+ BaseNode::BaseNode(EntityType type) : type_(type), uuid_(-1) {
50
+ // The registry will set uuid_ under its lock.
51
+ ChannelzRegistry::Register(this);
52
+ }
47
53
 
48
54
  BaseNode::~BaseNode() { ChannelzRegistry::Unregister(uuid_); }
49
55
 
@@ -190,11 +196,45 @@ RefCountedPtr<ChannelNode> ChannelNode::MakeChannelNode(
190
196
  channel, channel_tracer_max_nodes, is_top_level_channel);
191
197
  }
192
198
 
193
- ServerNode::ServerNode(size_t channel_tracer_max_nodes)
194
- : BaseNode(EntityType::kServer), trace_(channel_tracer_max_nodes) {}
199
+ ServerNode::ServerNode(grpc_server* server, size_t channel_tracer_max_nodes)
200
+ : BaseNode(EntityType::kServer),
201
+ server_(server),
202
+ trace_(channel_tracer_max_nodes) {}
195
203
 
196
204
  ServerNode::~ServerNode() {}
197
205
 
206
+ char* ServerNode::RenderServerSockets(intptr_t start_socket_id) {
207
+ grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
208
+ grpc_json* json = top_level_json;
209
+ grpc_json* json_iterator = nullptr;
210
+ ChildRefsList socket_refs;
211
+ // uuids index into entities one-off (idx 0 is really uuid 1, since 0 is
212
+ // reserved). However, we want to support requests coming in with
213
+ // start_server_id=0, which signifies "give me everything."
214
+ size_t start_idx = start_socket_id == 0 ? 0 : start_socket_id - 1;
215
+ grpc_server_populate_server_sockets(server_, &socket_refs, start_idx);
216
+ if (!socket_refs.empty()) {
217
+ // create list of socket refs
218
+ grpc_json* array_parent = grpc_json_create_child(
219
+ nullptr, json, "socketRef", nullptr, GRPC_JSON_ARRAY, false);
220
+ for (size_t i = 0; i < socket_refs.size(); ++i) {
221
+ json_iterator =
222
+ grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr,
223
+ GRPC_JSON_OBJECT, false);
224
+ grpc_json_add_number_string_child(json_iterator, nullptr, "socketId",
225
+ socket_refs[i]);
226
+ }
227
+ }
228
+ // For now we do not have any pagination rules. In the future we could
229
+ // pick a constant for max_channels_sent for a GetServers request.
230
+ // Tracking: https://github.com/grpc/grpc/issues/16019.
231
+ json_iterator = grpc_json_create_child(nullptr, json, "end", nullptr,
232
+ GRPC_JSON_TRUE, false);
233
+ char* json_str = grpc_json_dump_to_string(top_level_json, 0);
234
+ grpc_json_destroy(top_level_json);
235
+ return json_str;
236
+ }
237
+
198
238
  grpc_json* ServerNode::RenderJson() {
199
239
  // We need to track these three json objects to build our object
200
240
  grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
@@ -223,10 +263,78 @@ grpc_json* ServerNode::RenderJson() {
223
263
  }
224
264
  // ask CallCountingHelper to populate trace and call count data.
225
265
  call_counter_.PopulateCallCounts(json);
266
+ json = top_level_json;
267
+ ChildRefsList listen_sockets;
268
+ grpc_server_populate_listen_sockets(server_, &listen_sockets);
269
+ if (!listen_sockets.empty()) {
270
+ grpc_json* array_parent = grpc_json_create_child(
271
+ nullptr, json, "listenSocket", nullptr, GRPC_JSON_ARRAY, false);
272
+ for (size_t i = 0; i < listen_sockets.size(); ++i) {
273
+ json_iterator =
274
+ grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr,
275
+ GRPC_JSON_OBJECT, false);
276
+ grpc_json_add_number_string_child(json_iterator, nullptr, "socketId",
277
+ listen_sockets[i]);
278
+ }
279
+ }
226
280
  return top_level_json;
227
281
  }
228
282
 
229
- SocketNode::SocketNode() : BaseNode(EntityType::kSocket) {}
283
+ static void PopulateSocketAddressJson(grpc_json* json, const char* name,
284
+ const char* addr_str) {
285
+ if (addr_str == nullptr) return;
286
+ grpc_json* json_iterator = nullptr;
287
+ json_iterator = grpc_json_create_child(json_iterator, json, name, nullptr,
288
+ GRPC_JSON_OBJECT, false);
289
+ json = json_iterator;
290
+ json_iterator = nullptr;
291
+ grpc_uri* uri = grpc_uri_parse(addr_str, true);
292
+ if ((uri != nullptr) && ((strcmp(uri->scheme, "ipv4") == 0) ||
293
+ (strcmp(uri->scheme, "ipv6") == 0))) {
294
+ const char* host_port = uri->path;
295
+ if (*host_port == '/') ++host_port;
296
+ char* host = nullptr;
297
+ char* port = nullptr;
298
+ GPR_ASSERT(gpr_split_host_port(host_port, &host, &port));
299
+ int port_num = -1;
300
+ if (port != nullptr) {
301
+ port_num = atoi(port);
302
+ }
303
+ char* b64_host = grpc_base64_encode(host, strlen(host), false, false);
304
+ json_iterator = grpc_json_create_child(json_iterator, json, "tcpip_address",
305
+ nullptr, GRPC_JSON_OBJECT, false);
306
+ json = json_iterator;
307
+ json_iterator = nullptr;
308
+ json_iterator = grpc_json_add_number_string_child(json, json_iterator,
309
+ "port", port_num);
310
+ json_iterator = grpc_json_create_child(json_iterator, json, "ip_address",
311
+ b64_host, GRPC_JSON_STRING, true);
312
+ gpr_free(host);
313
+ gpr_free(port);
314
+
315
+ } else if (uri != nullptr && strcmp(uri->scheme, "unix") == 0) {
316
+ json_iterator = grpc_json_create_child(json_iterator, json, "uds_address",
317
+ nullptr, GRPC_JSON_OBJECT, false);
318
+ json = json_iterator;
319
+ json_iterator = nullptr;
320
+ json_iterator =
321
+ grpc_json_create_child(json_iterator, json, "filename",
322
+ gpr_strdup(uri->path), GRPC_JSON_STRING, true);
323
+ } else {
324
+ json_iterator = grpc_json_create_child(json_iterator, json, "other_address",
325
+ nullptr, GRPC_JSON_OBJECT, false);
326
+ json = json_iterator;
327
+ json_iterator = nullptr;
328
+ json_iterator = grpc_json_create_child(json_iterator, json, "name",
329
+ addr_str, GRPC_JSON_STRING, false);
330
+ }
331
+ grpc_uri_destroy(uri);
332
+ }
333
+
334
+ SocketNode::SocketNode(UniquePtr<char> local, UniquePtr<char> remote)
335
+ : BaseNode(EntityType::kSocket),
336
+ local_(std::move(local)),
337
+ remote_(std::move(remote)) {}
230
338
 
231
339
  void SocketNode::RecordStreamStartedFromLocal() {
232
340
  gpr_atm_no_barrier_fetch_add(&streams_started_, static_cast<gpr_atm>(1));
@@ -264,6 +372,9 @@ grpc_json* SocketNode::RenderJson() {
264
372
  json_iterator = nullptr;
265
373
  json_iterator = grpc_json_add_number_string_child(json, json_iterator,
266
374
  "socketId", uuid());
375
+ json = top_level_json;
376
+ PopulateSocketAddressJson(json, "remote", remote_.get());
377
+ PopulateSocketAddressJson(json, "local", local_.get());
267
378
  // reset json iterators to top level object
268
379
  json = top_level_json;
269
380
  json_iterator = nullptr;
@@ -323,5 +434,26 @@ grpc_json* SocketNode::RenderJson() {
323
434
  return top_level_json;
324
435
  }
325
436
 
437
+ ListenSocketNode::ListenSocketNode(UniquePtr<char> local_addr)
438
+ : BaseNode(EntityType::kSocket), local_addr_(std::move(local_addr)) {}
439
+
440
+ grpc_json* ListenSocketNode::RenderJson() {
441
+ // We need to track these three json objects to build our object
442
+ grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
443
+ grpc_json* json = top_level_json;
444
+ grpc_json* json_iterator = nullptr;
445
+ // create and fill the ref child
446
+ json_iterator = grpc_json_create_child(json_iterator, json, "ref", nullptr,
447
+ GRPC_JSON_OBJECT, false);
448
+ json = json_iterator;
449
+ json_iterator = nullptr;
450
+ json_iterator = grpc_json_add_number_string_child(json, json_iterator,
451
+ "socketId", uuid());
452
+ json = top_level_json;
453
+ PopulateSocketAddressJson(json, "local", local_addr_.get());
454
+
455
+ return top_level_json;
456
+ }
457
+
326
458
  } // namespace channelz
327
459
  } // namespace grpc_core
@@ -24,6 +24,7 @@
24
24
  #include <grpc/grpc.h>
25
25
 
26
26
  #include "src/core/lib/channel/channel_trace.h"
27
+ #include "src/core/lib/gprpp/inlined_vector.h"
27
28
  #include "src/core/lib/gprpp/manual_constructor.h"
28
29
  #include "src/core/lib/gprpp/ref_counted.h"
29
30
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
@@ -41,17 +42,23 @@
41
42
 
42
43
  /** This is the default value for whether or not to enable channelz. If
43
44
  * GRPC_ARG_ENABLE_CHANNELZ is set, it will override this default value. */
44
- #define GRPC_ENABLE_CHANNELZ_DEFAULT false
45
+ #define GRPC_ENABLE_CHANNELZ_DEFAULT true
45
46
 
46
47
  /** This is the default value for the maximum amount of memory used by trace
47
48
  * events per channel trace node. If
48
49
  * GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE is set, it will override
49
50
  * this default value. */
50
- #define GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT 0
51
+ #define GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT 1024 * 4
51
52
 
52
53
  namespace grpc_core {
54
+
53
55
  namespace channelz {
54
56
 
57
+ // TODO(ncteisen), this only contains the uuids of the children for now,
58
+ // since that is all that is strictly needed. In a future enhancement we will
59
+ // add human readable names as in the channelz.proto
60
+ typedef InlinedVector<intptr_t, 10> ChildRefsList;
61
+
55
62
  namespace testing {
56
63
  class CallCountingHelperPeer;
57
64
  class ChannelNodePeer;
@@ -85,8 +92,10 @@ class BaseNode : public RefCounted<BaseNode> {
85
92
  intptr_t uuid() const { return uuid_; }
86
93
 
87
94
  private:
95
+ // to allow the ChannelzRegistry to set uuid_ under its lock.
96
+ friend class ChannelzRegistry;
88
97
  const EntityType type_;
89
- const intptr_t uuid_;
98
+ intptr_t uuid_;
90
99
  };
91
100
 
92
101
  // This class is a helper class for channelz entities that deal with Channels,
@@ -193,11 +202,13 @@ class ChannelNode : public BaseNode {
193
202
  // Handles channelz bookkeeping for servers
194
203
  class ServerNode : public BaseNode {
195
204
  public:
196
- explicit ServerNode(size_t channel_tracer_max_nodes);
205
+ ServerNode(grpc_server* server, size_t channel_tracer_max_nodes);
197
206
  ~ServerNode() override;
198
207
 
199
208
  grpc_json* RenderJson() override;
200
209
 
210
+ char* RenderServerSockets(intptr_t start_socket_id);
211
+
201
212
  // proxy methods to composed classes.
202
213
  void AddTraceEvent(ChannelTrace::Severity severity, grpc_slice data) {
203
214
  trace_.AddTraceEvent(severity, data);
@@ -213,6 +224,7 @@ class ServerNode : public BaseNode {
213
224
  void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
214
225
 
215
226
  private:
227
+ grpc_server* server_;
216
228
  CallCountingHelper call_counter_;
217
229
  ChannelTrace trace_;
218
230
  };
@@ -220,7 +232,7 @@ class ServerNode : public BaseNode {
220
232
  // Handles channelz bookkeeping for sockets
221
233
  class SocketNode : public BaseNode {
222
234
  public:
223
- SocketNode();
235
+ SocketNode(UniquePtr<char> local, UniquePtr<char> remote);
224
236
  ~SocketNode() override {}
225
237
 
226
238
  grpc_json* RenderJson() override;
@@ -250,7 +262,21 @@ class SocketNode : public BaseNode {
250
262
  gpr_atm last_remote_stream_created_millis_ = 0;
251
263
  gpr_atm last_message_sent_millis_ = 0;
252
264
  gpr_atm last_message_received_millis_ = 0;
253
- UniquePtr<char> peer_string_;
265
+ UniquePtr<char> local_;
266
+ UniquePtr<char> remote_;
267
+ };
268
+
269
+ // Handles channelz bookkeeping for listen sockets
270
+ class ListenSocketNode : public BaseNode {
271
+ public:
272
+ // ListenSocketNode takes ownership of host.
273
+ explicit ListenSocketNode(UniquePtr<char> local_addr);
274
+ ~ListenSocketNode() override {}
275
+
276
+ grpc_json* RenderJson() override;
277
+
278
+ private:
279
+ UniquePtr<char> local_addr_;
254
280
  };
255
281
 
256
282
  // Creation functions
@@ -38,6 +38,8 @@ namespace {
38
38
  // singleton instance of the registry.
39
39
  ChannelzRegistry* g_channelz_registry = nullptr;
40
40
 
41
+ const int kPaginationLimit = 100;
42
+
41
43
  } // anonymous namespace
42
44
 
43
45
  void ChannelzRegistry::Init() { g_channelz_registry = New<ChannelzRegistry>(); }
@@ -53,42 +55,97 @@ ChannelzRegistry::ChannelzRegistry() { gpr_mu_init(&mu_); }
53
55
 
54
56
  ChannelzRegistry::~ChannelzRegistry() { gpr_mu_destroy(&mu_); }
55
57
 
56
- intptr_t ChannelzRegistry::InternalRegister(BaseNode* node) {
58
+ void ChannelzRegistry::InternalRegister(BaseNode* node) {
57
59
  MutexLock lock(&mu_);
58
60
  entities_.push_back(node);
59
- intptr_t uuid = entities_.size();
60
- return uuid;
61
+ node->uuid_ = ++uuid_generator_;
62
+ }
63
+
64
+ void ChannelzRegistry::MaybePerformCompactionLocked() {
65
+ constexpr double kEmptinessTheshold = 1 / 3;
66
+ double emptiness_ratio =
67
+ double(num_empty_slots_) / double(entities_.capacity());
68
+ if (emptiness_ratio > kEmptinessTheshold) {
69
+ int front = 0;
70
+ for (size_t i = 0; i < entities_.size(); ++i) {
71
+ if (entities_[i] != nullptr) {
72
+ entities_[front++] = entities_[i];
73
+ }
74
+ }
75
+ for (int i = 0; i < num_empty_slots_; ++i) {
76
+ entities_.pop_back();
77
+ }
78
+ num_empty_slots_ = 0;
79
+ }
80
+ }
81
+
82
+ int ChannelzRegistry::FindByUuidLocked(intptr_t target_uuid,
83
+ bool direct_hit_needed) {
84
+ int left = 0;
85
+ int right = int(entities_.size() - 1);
86
+ while (left <= right) {
87
+ int true_middle = left + (right - left) / 2;
88
+ int first_non_null = true_middle;
89
+ while (first_non_null < right && entities_[first_non_null] == nullptr) {
90
+ first_non_null++;
91
+ }
92
+ if (entities_[first_non_null] == nullptr) {
93
+ right = true_middle - 1;
94
+ continue;
95
+ }
96
+ intptr_t uuid = entities_[first_non_null]->uuid();
97
+ if (uuid == target_uuid) {
98
+ return int(first_non_null);
99
+ }
100
+ if (uuid < target_uuid) {
101
+ left = first_non_null + 1;
102
+ } else {
103
+ right = true_middle - 1;
104
+ }
105
+ }
106
+ return direct_hit_needed ? -1 : left;
61
107
  }
62
108
 
63
109
  void ChannelzRegistry::InternalUnregister(intptr_t uuid) {
64
110
  GPR_ASSERT(uuid >= 1);
65
111
  MutexLock lock(&mu_);
66
- GPR_ASSERT(static_cast<size_t>(uuid) <= entities_.size());
67
- entities_[uuid - 1] = nullptr;
112
+ GPR_ASSERT(uuid <= uuid_generator_);
113
+ int idx = FindByUuidLocked(uuid, true);
114
+ GPR_ASSERT(idx >= 0);
115
+ entities_[idx] = nullptr;
116
+ num_empty_slots_++;
117
+ MaybePerformCompactionLocked();
68
118
  }
69
119
 
70
120
  BaseNode* ChannelzRegistry::InternalGet(intptr_t uuid) {
71
121
  MutexLock lock(&mu_);
72
- if (uuid < 1 || uuid > static_cast<intptr_t>(entities_.size())) {
122
+ if (uuid < 1 || uuid > uuid_generator_) {
73
123
  return nullptr;
74
124
  }
75
- return entities_[uuid - 1];
125
+ int idx = FindByUuidLocked(uuid, true);
126
+ return idx < 0 ? nullptr : entities_[idx];
76
127
  }
77
128
 
78
129
  char* ChannelzRegistry::InternalGetTopChannels(intptr_t start_channel_id) {
130
+ MutexLock lock(&mu_);
79
131
  grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
80
132
  grpc_json* json = top_level_json;
81
133
  grpc_json* json_iterator = nullptr;
82
134
  InlinedVector<BaseNode*, 10> top_level_channels;
83
- // uuids index into entities one-off (idx 0 is really uuid 1, since 0 is
84
- // reserved). However, we want to support requests coming in with
85
- // start_channel_id=0, which signifies "give me everything." Hence this
86
- // funky looking line below.
87
- size_t start_idx = start_channel_id == 0 ? 0 : start_channel_id - 1;
135
+ bool reached_pagination_limit = false;
136
+ int start_idx = GPR_MAX(FindByUuidLocked(start_channel_id, false), 0);
88
137
  for (size_t i = start_idx; i < entities_.size(); ++i) {
89
138
  if (entities_[i] != nullptr &&
90
139
  entities_[i]->type() ==
91
- grpc_core::channelz::BaseNode::EntityType::kTopLevelChannel) {
140
+ grpc_core::channelz::BaseNode::EntityType::kTopLevelChannel &&
141
+ entities_[i]->uuid() >= start_channel_id) {
142
+ // check if we are over pagination limit to determine if we need to set
143
+ // the "end" element. If we don't go through this block, we know that
144
+ // when the loop terminates, we have <= to kPaginationLimit.
145
+ if (top_level_channels.size() == kPaginationLimit) {
146
+ reached_pagination_limit = true;
147
+ break;
148
+ }
92
149
  top_level_channels.push_back(entities_[i]);
93
150
  }
94
151
  }
@@ -102,29 +159,35 @@ char* ChannelzRegistry::InternalGetTopChannels(intptr_t start_channel_id) {
102
159
  grpc_json_link_child(array_parent, channel_json, json_iterator);
103
160
  }
104
161
  }
105
- // For now we do not have any pagination rules. In the future we could
106
- // pick a constant for max_channels_sent for a GetTopChannels request.
107
- // Tracking: https://github.com/grpc/grpc/issues/16019.
108
- json_iterator = grpc_json_create_child(nullptr, json, "end", nullptr,
109
- GRPC_JSON_TRUE, false);
162
+ if (!reached_pagination_limit) {
163
+ grpc_json_create_child(nullptr, json, "end", nullptr, GRPC_JSON_TRUE,
164
+ false);
165
+ }
110
166
  char* json_str = grpc_json_dump_to_string(top_level_json, 0);
111
167
  grpc_json_destroy(top_level_json);
112
168
  return json_str;
113
169
  }
114
170
 
115
171
  char* ChannelzRegistry::InternalGetServers(intptr_t start_server_id) {
172
+ MutexLock lock(&mu_);
116
173
  grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
117
174
  grpc_json* json = top_level_json;
118
175
  grpc_json* json_iterator = nullptr;
119
176
  InlinedVector<BaseNode*, 10> servers;
120
- // uuids index into entities one-off (idx 0 is really uuid 1, since 0 is
121
- // reserved). However, we want to support requests coming in with
122
- // start_server_id=0, which signifies "give me everything."
123
- size_t start_idx = start_server_id == 0 ? 0 : start_server_id - 1;
177
+ bool reached_pagination_limit = false;
178
+ int start_idx = GPR_MAX(FindByUuidLocked(start_server_id, false), 0);
124
179
  for (size_t i = start_idx; i < entities_.size(); ++i) {
125
180
  if (entities_[i] != nullptr &&
126
181
  entities_[i]->type() ==
127
- grpc_core::channelz::BaseNode::EntityType::kServer) {
182
+ grpc_core::channelz::BaseNode::EntityType::kServer &&
183
+ entities_[i]->uuid() >= start_server_id) {
184
+ // check if we are over pagination limit to determine if we need to set
185
+ // the "end" element. If we don't go through this block, we know that
186
+ // when the loop terminates, we have <= to kPaginationLimit.
187
+ if (servers.size() == kPaginationLimit) {
188
+ reached_pagination_limit = true;
189
+ break;
190
+ }
128
191
  servers.push_back(entities_[i]);
129
192
  }
130
193
  }
@@ -138,16 +201,26 @@ char* ChannelzRegistry::InternalGetServers(intptr_t start_server_id) {
138
201
  grpc_json_link_child(array_parent, server_json, json_iterator);
139
202
  }
140
203
  }
141
- // For now we do not have any pagination rules. In the future we could
142
- // pick a constant for max_channels_sent for a GetServers request.
143
- // Tracking: https://github.com/grpc/grpc/issues/16019.
144
- json_iterator = grpc_json_create_child(nullptr, json, "end", nullptr,
145
- GRPC_JSON_TRUE, false);
204
+ if (!reached_pagination_limit) {
205
+ grpc_json_create_child(nullptr, json, "end", nullptr, GRPC_JSON_TRUE,
206
+ false);
207
+ }
146
208
  char* json_str = grpc_json_dump_to_string(top_level_json, 0);
147
209
  grpc_json_destroy(top_level_json);
148
210
  return json_str;
149
211
  }
150
212
 
213
+ void ChannelzRegistry::InternalLogAllEntities() {
214
+ MutexLock lock(&mu_);
215
+ for (size_t i = 0; i < entities_.size(); ++i) {
216
+ if (entities_[i] != nullptr) {
217
+ char* json = entities_[i]->RenderJsonString();
218
+ gpr_log(GPR_INFO, "%s", json);
219
+ gpr_free(json);
220
+ }
221
+ }
222
+ }
223
+
151
224
  } // namespace channelz
152
225
  } // namespace grpc_core
153
226
 
@@ -160,6 +233,39 @@ char* grpc_channelz_get_servers(intptr_t start_server_id) {
160
233
  return grpc_core::channelz::ChannelzRegistry::GetServers(start_server_id);
161
234
  }
162
235
 
236
+ char* grpc_channelz_get_server(intptr_t server_id) {
237
+ grpc_core::channelz::BaseNode* server_node =
238
+ grpc_core::channelz::ChannelzRegistry::Get(server_id);
239
+ if (server_node == nullptr ||
240
+ server_node->type() !=
241
+ grpc_core::channelz::BaseNode::EntityType::kServer) {
242
+ return nullptr;
243
+ }
244
+ grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
245
+ grpc_json* json = top_level_json;
246
+ grpc_json* channel_json = server_node->RenderJson();
247
+ channel_json->key = "server";
248
+ grpc_json_link_child(json, channel_json, nullptr);
249
+ char* json_str = grpc_json_dump_to_string(top_level_json, 0);
250
+ grpc_json_destroy(top_level_json);
251
+ return json_str;
252
+ }
253
+
254
+ char* grpc_channelz_get_server_sockets(intptr_t server_id,
255
+ intptr_t start_socket_id) {
256
+ grpc_core::channelz::BaseNode* base_node =
257
+ grpc_core::channelz::ChannelzRegistry::Get(server_id);
258
+ if (base_node == nullptr ||
259
+ base_node->type() != grpc_core::channelz::BaseNode::EntityType::kServer) {
260
+ return nullptr;
261
+ }
262
+ // This cast is ok since we have just checked to make sure base_node is
263
+ // actually a server node
264
+ grpc_core::channelz::ServerNode* server_node =
265
+ static_cast<grpc_core::channelz::ServerNode*>(base_node);
266
+ return server_node->RenderServerSockets(start_socket_id);
267
+ }
268
+
163
269
  char* grpc_channelz_get_channel(intptr_t channel_id) {
164
270
  grpc_core::channelz::BaseNode* channel_node =
165
271
  grpc_core::channelz::ChannelzRegistry::Get(channel_id);