grpc 1.15.0 → 1.16.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 (138) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +158 -80
  3. data/etc/roots.pem +23 -0
  4. data/include/grpc/grpc.h +13 -1
  5. data/include/grpc/grpc_security.h +2 -2
  6. data/include/grpc/grpc_security_constants.h +24 -19
  7. data/include/grpc/impl/codegen/grpc_types.h +23 -5
  8. data/include/grpc/impl/codegen/port_platform.h +1 -0
  9. data/src/core/ext/filters/client_channel/client_channel.cc +95 -10
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +71 -0
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +45 -11
  12. data/src/core/ext/filters/client_channel/connector.h +3 -0
  13. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +5 -3
  15. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +12 -32
  16. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +6 -5
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +20 -15
  18. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -4
  19. data/src/core/ext/filters/client_channel/parse_address.cc +27 -4
  20. data/src/core/ext/filters/client_channel/parse_address.h +3 -0
  21. data/src/core/ext/filters/client_channel/resolver.h +1 -12
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -11
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -19
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +9 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +5 -0
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +70 -0
  27. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -11
  28. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -16
  29. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
  30. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +0 -7
  31. data/src/core/ext/filters/client_channel/subchannel.cc +45 -7
  32. data/src/core/ext/filters/client_channel/subchannel.h +16 -1
  33. data/src/core/ext/filters/client_channel/subchannel_index.cc +2 -1
  34. data/src/core/ext/filters/client_channel/subchannel_index.h +1 -4
  35. data/src/core/ext/filters/http/client/http_client_filter.cc +32 -3
  36. data/src/core/ext/filters/http/server/http_server_filter.cc +59 -1
  37. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -2
  38. data/src/core/ext/filters/message_size/message_size_filter.cc +59 -3
  39. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -0
  40. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  41. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  42. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +286 -228
  43. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -0
  44. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -0
  45. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +14 -3
  46. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +29 -0
  47. data/src/core/ext/transport/chttp2/transport/hpack_table.h +9 -0
  48. data/src/core/ext/transport/chttp2/transport/internal.h +10 -0
  49. data/src/core/ext/transport/chttp2/transport/parsing.cc +85 -54
  50. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -0
  51. data/src/core/lib/channel/channel_trace.cc +51 -56
  52. data/src/core/lib/channel/channel_trace.h +30 -25
  53. data/src/core/lib/channel/channelz.cc +235 -61
  54. data/src/core/lib/channel/channelz.h +179 -48
  55. data/src/core/lib/channel/channelz_registry.cc +95 -23
  56. data/src/core/lib/channel/channelz_registry.h +15 -42
  57. data/src/core/lib/gpr/sync_posix.cc +42 -0
  58. data/src/core/lib/http/httpcli.cc +1 -1
  59. data/src/core/lib/iomgr/buffer_list.cc +134 -0
  60. data/src/core/lib/iomgr/buffer_list.h +96 -0
  61. data/src/core/lib/iomgr/endpoint.cc +2 -2
  62. data/src/core/lib/iomgr/endpoint.h +6 -2
  63. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  64. data/src/core/lib/iomgr/error.cc +29 -18
  65. data/src/core/lib/iomgr/error.h +8 -0
  66. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  67. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  68. data/src/core/lib/iomgr/ev_posix.cc +16 -10
  69. data/src/core/lib/iomgr/exec_ctx.h +0 -7
  70. data/src/core/lib/iomgr/{ev_epollsig_linux.h → internal_errqueue.cc} +13 -12
  71. data/src/core/lib/iomgr/internal_errqueue.h +83 -0
  72. data/src/core/lib/iomgr/port.h +11 -2
  73. data/src/core/lib/iomgr/socket_utils_common_posix.cc +90 -0
  74. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  75. data/src/core/lib/iomgr/tcp_client_posix.cc +4 -1
  76. data/src/core/lib/iomgr/tcp_custom.cc +1 -1
  77. data/src/core/lib/iomgr/tcp_posix.cc +306 -13
  78. data/src/core/lib/iomgr/tcp_posix.h +3 -0
  79. data/src/core/lib/iomgr/tcp_server_posix.cc +2 -2
  80. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +4 -1
  81. data/src/core/lib/iomgr/tcp_windows.cc +1 -1
  82. data/src/core/lib/iomgr/timer_generic.cc +13 -12
  83. data/src/core/lib/iomgr/timer_heap.cc +2 -2
  84. data/src/core/lib/iomgr/timer_heap.h +3 -3
  85. data/src/core/lib/iomgr/timer_manager.cc +28 -3
  86. data/src/core/lib/iomgr/timer_manager.h +2 -2
  87. data/src/core/lib/iomgr/udp_server.cc +1 -1
  88. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc +2 -1
  89. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +2 -1
  90. data/src/core/lib/security/security_connector/security_connector.cc +7 -7
  91. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  92. data/src/core/lib/security/transport/security_handshaker.cc +1 -1
  93. data/src/core/lib/security/transport/server_auth_filter.cc +53 -4
  94. data/src/core/lib/slice/slice.cc +8 -0
  95. data/src/core/lib/slice/slice_internal.h +5 -0
  96. data/src/core/lib/surface/call.cc +149 -253
  97. data/src/core/lib/surface/call.h +1 -0
  98. data/src/core/lib/surface/channel.cc +17 -13
  99. data/src/core/lib/surface/completion_queue.cc +21 -17
  100. data/src/core/lib/surface/completion_queue.h +1 -18
  101. data/src/core/lib/surface/completion_queue_factory.cc +3 -3
  102. data/src/core/lib/surface/init_secure.cc +1 -1
  103. data/src/core/lib/surface/server.cc +77 -4
  104. data/src/core/lib/surface/server.h +4 -0
  105. data/src/core/lib/surface/version.cc +2 -2
  106. data/src/core/lib/transport/metadata.cc +0 -18
  107. data/src/core/lib/transport/metadata.h +0 -3
  108. data/src/core/lib/transport/metadata_batch.cc +2 -2
  109. data/src/core/lib/transport/metadata_batch.h +2 -0
  110. data/src/core/lib/transport/static_metadata.cc +220 -249
  111. data/src/core/lib/transport/static_metadata.h +189 -191
  112. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +5 -4
  113. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +3 -1
  114. data/src/core/tsi/alts/handshaker/alts_tsi_event.cc +4 -2
  115. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +6 -5
  116. data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +3 -1
  117. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +2 -2
  118. data/src/core/tsi/alts_transport_security.cc +3 -1
  119. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +2 -1
  120. data/src/ruby/ext/grpc/rb_call.c +1 -0
  121. data/src/ruby/ext/grpc/rb_channel.c +3 -0
  122. data/src/ruby/ext/grpc/rb_grpc.c +31 -1
  123. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  124. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  125. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +12 -3
  126. data/src/ruby/ext/grpc/rb_server.c +2 -0
  127. data/src/ruby/lib/grpc/errors.rb +0 -1
  128. data/src/ruby/lib/grpc/generic/rpc_desc.rb +3 -3
  129. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  130. data/src/ruby/lib/grpc/version.rb +1 -1
  131. data/src/ruby/spec/channel_spec.rb +44 -0
  132. data/src/ruby/spec/client_auth_spec.rb +5 -5
  133. data/src/ruby/spec/generic/client_stub_spec.rb +13 -9
  134. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -3
  135. data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -0
  136. data/src/ruby/spec/support/services.rb +28 -22
  137. metadata +35 -31
  138. data/src/core/lib/iomgr/ev_epollsig_linux.cc +0 -1743
@@ -39,38 +39,126 @@
39
39
  #define GRPC_ARG_CHANNELZ_CHANNEL_IS_INTERNAL_CHANNEL \
40
40
  "grpc.channelz_channel_is_internal_channel"
41
41
 
42
+ /** This is the default value for whether or not to enable channelz. If
43
+ * GRPC_ARG_ENABLE_CHANNELZ is set, it will override this default value. */
44
+ #define GRPC_ENABLE_CHANNELZ_DEFAULT false
45
+
46
+ /** This is the default value for the maximum amount of memory used by trace
47
+ * events per channel trace node. If
48
+ * GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE is set, it will override
49
+ * this default value. */
50
+ #define GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT 0
51
+
42
52
  namespace grpc_core {
43
53
  namespace channelz {
44
54
 
45
55
  namespace testing {
56
+ class CallCountingHelperPeer;
46
57
  class ChannelNodePeer;
47
- }
58
+ } // namespace testing
48
59
 
49
- class ChannelNode : public RefCounted<ChannelNode> {
60
+ // base class for all channelz entities
61
+ class BaseNode : public RefCounted<BaseNode> {
50
62
  public:
51
- static RefCountedPtr<ChannelNode> MakeChannelNode(
52
- grpc_channel* channel, size_t channel_tracer_max_nodes,
53
- bool is_top_level_channel);
63
+ // There are only four high level channelz entities. However, to support
64
+ // GetTopChannelsRequest, we split the Channel entity into two different
65
+ // types. All children of BaseNode must be one of these types.
66
+ enum class EntityType {
67
+ kTopLevelChannel,
68
+ kInternalChannel,
69
+ kSubchannel,
70
+ kServer,
71
+ kSocket,
72
+ };
54
73
 
55
- void RecordCallStarted();
56
- void RecordCallFailed() {
57
- gpr_atm_no_barrier_fetch_add(&calls_failed_, (gpr_atm(1)));
58
- }
59
- void RecordCallSucceeded() {
60
- gpr_atm_no_barrier_fetch_add(&calls_succeeded_, (gpr_atm(1)));
61
- }
74
+ explicit BaseNode(EntityType type);
75
+ virtual ~BaseNode();
76
+
77
+ // All children must implement this function.
78
+ virtual grpc_json* RenderJson() GRPC_ABSTRACT;
62
79
 
63
- grpc_json* RenderJson();
80
+ // Renders the json and returns allocated string that must be freed by the
81
+ // caller.
64
82
  char* RenderJsonString();
65
83
 
66
- // helper for getting and populating connectivity state. It is virtual
67
- // because it allows the client_channel specific code to live in ext/
68
- // instead of lib/
69
- virtual void PopulateConnectivityState(grpc_json* json);
84
+ EntityType type() const { return type_; }
85
+ intptr_t uuid() const { return uuid_; }
86
+
87
+ private:
88
+ const EntityType type_;
89
+ const intptr_t uuid_;
90
+ };
91
+
92
+ // This class is a helper class for channelz entities that deal with Channels,
93
+ // Subchannels, and Servers, since those have similar proto definitions.
94
+ // This class has the ability to:
95
+ // - track calls_{started,succeeded,failed}
96
+ // - track last_call_started_timestamp
97
+ // - perform rendering of the above items
98
+ class CallCountingHelper {
99
+ public:
100
+ CallCountingHelper();
101
+ ~CallCountingHelper();
102
+
103
+ void RecordCallStarted();
104
+ void RecordCallFailed();
105
+ void RecordCallSucceeded();
106
+
107
+ // Common rendering of the call count data and last_call_started_timestamp.
108
+ void PopulateCallCounts(grpc_json* json);
109
+
110
+ private:
111
+ // testing peer friend.
112
+ friend class testing::CallCountingHelperPeer;
113
+
114
+ struct AtomicCounterData {
115
+ gpr_atm calls_started = 0;
116
+ gpr_atm calls_succeeded = 0;
117
+ gpr_atm calls_failed = 0;
118
+ gpr_atm last_call_started_millis = 0;
119
+ };
120
+
121
+ struct CounterData {
122
+ intptr_t calls_started = 0;
123
+ intptr_t calls_succeeded = 0;
124
+ intptr_t calls_failed = 0;
125
+ intptr_t last_call_started_millis = 0;
126
+ };
127
+
128
+ // collects the sharded data into one CounterData struct.
129
+ void CollectData(CounterData* out);
130
+
131
+ AtomicCounterData* per_cpu_counter_data_storage_ = nullptr;
132
+ size_t num_cores_ = 0;
133
+ };
134
+
135
+ // Handles channelz bookkeeping for channels
136
+ class ChannelNode : public BaseNode {
137
+ public:
138
+ static RefCountedPtr<ChannelNode> MakeChannelNode(
139
+ grpc_channel* channel, size_t channel_tracer_max_nodes,
140
+ bool is_top_level_channel);
141
+
142
+ ChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes,
143
+ bool is_top_level_channel);
144
+ ~ChannelNode() override;
70
145
 
71
- virtual void PopulateChildRefs(grpc_json* json);
146
+ grpc_json* RenderJson() override;
72
147
 
73
- ChannelTrace* trace() { return trace_.get(); }
148
+ // template methods. RenderJSON uses these methods to render its JSON
149
+ // representation. These are virtual so that children classes may provide
150
+ // their specific mechanism for populating these parts of the channelz
151
+ // object.
152
+ //
153
+ // ChannelNode does not have a notion of connectivity state or child refs,
154
+ // so it leaves these implementations blank.
155
+ //
156
+ // This is utilizing the template method design pattern.
157
+ //
158
+ // TODO(ncteisen): remove these template methods in favor of manual traversal
159
+ // and mutation of the grpc_json object.
160
+ virtual void PopulateConnectivityState(grpc_json* json) {}
161
+ virtual void PopulateChildRefs(grpc_json* json) {}
74
162
 
75
163
  void MarkChannelDestroyed() {
76
164
  GPR_ASSERT(channel_ != nullptr);
@@ -79,47 +167,90 @@ class ChannelNode : public RefCounted<ChannelNode> {
79
167
 
80
168
  bool ChannelIsDestroyed() { return channel_ == nullptr; }
81
169
 
82
- intptr_t channel_uuid() { return channel_uuid_; }
83
- bool is_top_level_channel() { return is_top_level_channel_; }
84
-
85
- protected:
86
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
87
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
88
- ChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes,
89
- bool is_top_level_channel);
90
- virtual ~ChannelNode();
170
+ // proxy methods to composed classes.
171
+ void AddTraceEvent(ChannelTrace::Severity severity, grpc_slice data) {
172
+ trace_.AddTraceEvent(severity, data);
173
+ }
174
+ void AddTraceEventWithReference(ChannelTrace::Severity severity,
175
+ grpc_slice data,
176
+ RefCountedPtr<BaseNode> referenced_channel) {
177
+ trace_.AddTraceEventWithReference(severity, data,
178
+ std::move(referenced_channel));
179
+ }
180
+ void RecordCallStarted() { call_counter_.RecordCallStarted(); }
181
+ void RecordCallFailed() { call_counter_.RecordCallFailed(); }
182
+ void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
91
183
 
92
184
  private:
93
- // testing peer friend.
185
+ // to allow the channel trace test to access trace_.
94
186
  friend class testing::ChannelNodePeer;
95
-
96
187
  grpc_channel* channel_ = nullptr;
97
188
  UniquePtr<char> target_;
98
- gpr_atm calls_started_ = 0;
99
- gpr_atm calls_succeeded_ = 0;
100
- gpr_atm calls_failed_ = 0;
101
- gpr_atm last_call_started_millis_ = 0;
102
- intptr_t channel_uuid_;
103
- bool is_top_level_channel_ = true;
104
- ManualConstructor<ChannelTrace> trace_;
189
+ CallCountingHelper call_counter_;
190
+ ChannelTrace trace_;
105
191
  };
106
192
 
107
- // Placeholds channelz class for subchannels. All this can do now is track its
108
- // uuid (this information is needed by the parent channelz class).
109
- // TODO(ncteisen): build this out to support the GetSubchannel channelz request.
110
- class SubchannelNode : public RefCounted<SubchannelNode> {
193
+ // Handles channelz bookkeeping for servers
194
+ class ServerNode : public BaseNode {
111
195
  public:
112
- SubchannelNode();
113
- virtual ~SubchannelNode();
196
+ explicit ServerNode(size_t channel_tracer_max_nodes);
197
+ ~ServerNode() override;
198
+
199
+ grpc_json* RenderJson() override;
114
200
 
115
- intptr_t subchannel_uuid() { return subchannel_uuid_; }
201
+ // proxy methods to composed classes.
202
+ void AddTraceEvent(ChannelTrace::Severity severity, grpc_slice data) {
203
+ trace_.AddTraceEvent(severity, data);
204
+ }
205
+ void AddTraceEventWithReference(ChannelTrace::Severity severity,
206
+ grpc_slice data,
207
+ RefCountedPtr<BaseNode> referenced_channel) {
208
+ trace_.AddTraceEventWithReference(severity, data,
209
+ std::move(referenced_channel));
210
+ }
211
+ void RecordCallStarted() { call_counter_.RecordCallStarted(); }
212
+ void RecordCallFailed() { call_counter_.RecordCallFailed(); }
213
+ void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
214
+
215
+ private:
216
+ CallCountingHelper call_counter_;
217
+ ChannelTrace trace_;
218
+ };
116
219
 
117
- protected:
118
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
119
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
220
+ // Handles channelz bookkeeping for sockets
221
+ class SocketNode : public BaseNode {
222
+ public:
223
+ SocketNode();
224
+ ~SocketNode() override {}
225
+
226
+ grpc_json* RenderJson() override;
227
+
228
+ void RecordStreamStartedFromLocal();
229
+ void RecordStreamStartedFromRemote();
230
+ void RecordStreamSucceeded() {
231
+ gpr_atm_no_barrier_fetch_add(&streams_succeeded_, static_cast<gpr_atm>(1));
232
+ }
233
+ void RecordStreamFailed() {
234
+ gpr_atm_no_barrier_fetch_add(&streams_failed_, static_cast<gpr_atm>(1));
235
+ }
236
+ void RecordMessagesSent(uint32_t num_sent);
237
+ void RecordMessageReceived();
238
+ void RecordKeepaliveSent() {
239
+ gpr_atm_no_barrier_fetch_add(&keepalives_sent_, static_cast<gpr_atm>(1));
240
+ }
120
241
 
121
242
  private:
122
- intptr_t subchannel_uuid_;
243
+ gpr_atm streams_started_ = 0;
244
+ gpr_atm streams_succeeded_ = 0;
245
+ gpr_atm streams_failed_ = 0;
246
+ gpr_atm messages_sent_ = 0;
247
+ gpr_atm messages_received_ = 0;
248
+ gpr_atm keepalives_sent_ = 0;
249
+ gpr_atm last_local_stream_created_millis_ = 0;
250
+ gpr_atm last_remote_stream_created_millis_ = 0;
251
+ gpr_atm last_message_sent_millis_ = 0;
252
+ gpr_atm last_message_received_millis_ = 0;
253
+ UniquePtr<char> peer_string_;
123
254
  };
124
255
 
125
256
  // Creation functions
@@ -53,54 +53,46 @@ ChannelzRegistry::ChannelzRegistry() { gpr_mu_init(&mu_); }
53
53
 
54
54
  ChannelzRegistry::~ChannelzRegistry() { gpr_mu_destroy(&mu_); }
55
55
 
56
- intptr_t ChannelzRegistry::InternalRegisterEntry(const RegistryEntry& entry) {
56
+ intptr_t ChannelzRegistry::InternalRegister(BaseNode* node) {
57
57
  MutexLock lock(&mu_);
58
- entities_.push_back(entry);
58
+ entities_.push_back(node);
59
59
  intptr_t uuid = entities_.size();
60
60
  return uuid;
61
61
  }
62
62
 
63
- void ChannelzRegistry::InternalUnregisterEntry(intptr_t uuid, EntityType type) {
63
+ void ChannelzRegistry::InternalUnregister(intptr_t uuid) {
64
64
  GPR_ASSERT(uuid >= 1);
65
65
  MutexLock lock(&mu_);
66
66
  GPR_ASSERT(static_cast<size_t>(uuid) <= entities_.size());
67
- GPR_ASSERT(entities_[uuid - 1].type == type);
68
- entities_[uuid - 1].object = nullptr;
69
- entities_[uuid - 1].type = EntityType::kUnset;
67
+ entities_[uuid - 1] = nullptr;
70
68
  }
71
69
 
72
- void* ChannelzRegistry::InternalGetEntry(intptr_t uuid, EntityType type) {
70
+ BaseNode* ChannelzRegistry::InternalGet(intptr_t uuid) {
73
71
  MutexLock lock(&mu_);
74
72
  if (uuid < 1 || uuid > static_cast<intptr_t>(entities_.size())) {
75
73
  return nullptr;
76
74
  }
77
- if (entities_[uuid - 1].type == type) {
78
- return entities_[uuid - 1].object;
79
- } else {
80
- return nullptr;
81
- }
75
+ return entities_[uuid - 1];
82
76
  }
83
77
 
84
78
  char* ChannelzRegistry::InternalGetTopChannels(intptr_t start_channel_id) {
85
79
  grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
86
80
  grpc_json* json = top_level_json;
87
81
  grpc_json* json_iterator = nullptr;
88
- InlinedVector<ChannelNode*, 10> top_level_channels;
82
+ InlinedVector<BaseNode*, 10> top_level_channels;
89
83
  // uuids index into entities one-off (idx 0 is really uuid 1, since 0 is
90
84
  // reserved). However, we want to support requests coming in with
91
85
  // start_channel_id=0, which signifies "give me everything." Hence this
92
86
  // funky looking line below.
93
87
  size_t start_idx = start_channel_id == 0 ? 0 : start_channel_id - 1;
94
88
  for (size_t i = start_idx; i < entities_.size(); ++i) {
95
- if (entities_[i].type == EntityType::kChannelNode) {
96
- ChannelNode* channel_node =
97
- static_cast<ChannelNode*>(entities_[i].object);
98
- if (channel_node->is_top_level_channel()) {
99
- top_level_channels.push_back(channel_node);
100
- }
89
+ if (entities_[i] != nullptr &&
90
+ entities_[i]->type() ==
91
+ grpc_core::channelz::BaseNode::EntityType::kTopLevelChannel) {
92
+ top_level_channels.push_back(entities_[i]);
101
93
  }
102
94
  }
103
- if (top_level_channels.size() > 0) {
95
+ if (!top_level_channels.empty()) {
104
96
  // create list of channels
105
97
  grpc_json* array_parent = grpc_json_create_child(
106
98
  nullptr, json, "channel", nullptr, GRPC_JSON_ARRAY, false);
@@ -120,6 +112,42 @@ char* ChannelzRegistry::InternalGetTopChannels(intptr_t start_channel_id) {
120
112
  return json_str;
121
113
  }
122
114
 
115
+ char* ChannelzRegistry::InternalGetServers(intptr_t start_server_id) {
116
+ grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
117
+ grpc_json* json = top_level_json;
118
+ grpc_json* json_iterator = nullptr;
119
+ 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;
124
+ for (size_t i = start_idx; i < entities_.size(); ++i) {
125
+ if (entities_[i] != nullptr &&
126
+ entities_[i]->type() ==
127
+ grpc_core::channelz::BaseNode::EntityType::kServer) {
128
+ servers.push_back(entities_[i]);
129
+ }
130
+ }
131
+ if (!servers.empty()) {
132
+ // create list of servers
133
+ grpc_json* array_parent = grpc_json_create_child(
134
+ nullptr, json, "server", nullptr, GRPC_JSON_ARRAY, false);
135
+ for (size_t i = 0; i < servers.size(); ++i) {
136
+ grpc_json* server_json = servers[i]->RenderJson();
137
+ json_iterator =
138
+ grpc_json_link_child(array_parent, server_json, json_iterator);
139
+ }
140
+ }
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);
146
+ char* json_str = grpc_json_dump_to_string(top_level_json, 0);
147
+ grpc_json_destroy(top_level_json);
148
+ return json_str;
149
+ }
150
+
123
151
  } // namespace channelz
124
152
  } // namespace grpc_core
125
153
 
@@ -128,10 +156,18 @@ char* grpc_channelz_get_top_channels(intptr_t start_channel_id) {
128
156
  start_channel_id);
129
157
  }
130
158
 
159
+ char* grpc_channelz_get_servers(intptr_t start_server_id) {
160
+ return grpc_core::channelz::ChannelzRegistry::GetServers(start_server_id);
161
+ }
162
+
131
163
  char* grpc_channelz_get_channel(intptr_t channel_id) {
132
- grpc_core::channelz::ChannelNode* channel_node =
133
- grpc_core::channelz::ChannelzRegistry::GetChannelNode(channel_id);
134
- if (channel_node == nullptr) {
164
+ grpc_core::channelz::BaseNode* channel_node =
165
+ grpc_core::channelz::ChannelzRegistry::Get(channel_id);
166
+ if (channel_node == nullptr ||
167
+ (channel_node->type() !=
168
+ grpc_core::channelz::BaseNode::EntityType::kTopLevelChannel &&
169
+ channel_node->type() !=
170
+ grpc_core::channelz::BaseNode::EntityType::kInternalChannel)) {
135
171
  return nullptr;
136
172
  }
137
173
  grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
@@ -143,3 +179,39 @@ char* grpc_channelz_get_channel(intptr_t channel_id) {
143
179
  grpc_json_destroy(top_level_json);
144
180
  return json_str;
145
181
  }
182
+
183
+ char* grpc_channelz_get_subchannel(intptr_t subchannel_id) {
184
+ grpc_core::channelz::BaseNode* subchannel_node =
185
+ grpc_core::channelz::ChannelzRegistry::Get(subchannel_id);
186
+ if (subchannel_node == nullptr ||
187
+ subchannel_node->type() !=
188
+ grpc_core::channelz::BaseNode::EntityType::kSubchannel) {
189
+ return nullptr;
190
+ }
191
+ grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
192
+ grpc_json* json = top_level_json;
193
+ grpc_json* subchannel_json = subchannel_node->RenderJson();
194
+ subchannel_json->key = "subchannel";
195
+ grpc_json_link_child(json, subchannel_json, nullptr);
196
+ char* json_str = grpc_json_dump_to_string(top_level_json, 0);
197
+ grpc_json_destroy(top_level_json);
198
+ return json_str;
199
+ }
200
+
201
+ char* grpc_channelz_get_socket(intptr_t socket_id) {
202
+ grpc_core::channelz::BaseNode* socket_node =
203
+ grpc_core::channelz::ChannelzRegistry::Get(socket_id);
204
+ if (socket_node == nullptr ||
205
+ socket_node->type() !=
206
+ grpc_core::channelz::BaseNode::EntityType::kSocket) {
207
+ return nullptr;
208
+ }
209
+ grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
210
+ grpc_json* json = top_level_json;
211
+ grpc_json* socket_json = socket_node->RenderJson();
212
+ socket_json->key = "socket";
213
+ grpc_json_link_child(json, socket_json, nullptr);
214
+ char* json_str = grpc_json_dump_to_string(top_level_json, 0);
215
+ grpc_json_destroy(top_level_json);
216
+ return json_str;
217
+ }
@@ -40,32 +40,11 @@ class ChannelzRegistry {
40
40
  // To be called in grpc_shutdown();
41
41
  static void Shutdown();
42
42
 
43
- // Register/Unregister/Get for ChannelNode
44
- static intptr_t RegisterChannelNode(ChannelNode* channel_node) {
45
- RegistryEntry entry(channel_node, EntityType::kChannelNode);
46
- return Default()->InternalRegisterEntry(entry);
47
- }
48
- static void UnregisterChannelNode(intptr_t uuid) {
49
- Default()->InternalUnregisterEntry(uuid, EntityType::kChannelNode);
50
- }
51
- static ChannelNode* GetChannelNode(intptr_t uuid) {
52
- void* gotten = Default()->InternalGetEntry(uuid, EntityType::kChannelNode);
53
- return gotten == nullptr ? nullptr : static_cast<ChannelNode*>(gotten);
54
- }
55
-
56
- // Register/Unregister/Get for SubchannelNode
57
- static intptr_t RegisterSubchannelNode(SubchannelNode* channel_node) {
58
- RegistryEntry entry(channel_node, EntityType::kSubchannelNode);
59
- return Default()->InternalRegisterEntry(entry);
60
- }
61
- static void UnregisterSubchannelNode(intptr_t uuid) {
62
- Default()->InternalUnregisterEntry(uuid, EntityType::kSubchannelNode);
63
- }
64
- static SubchannelNode* GetSubchannelNode(intptr_t uuid) {
65
- void* gotten =
66
- Default()->InternalGetEntry(uuid, EntityType::kSubchannelNode);
67
- return gotten == nullptr ? nullptr : static_cast<SubchannelNode*>(gotten);
43
+ static intptr_t Register(BaseNode* node) {
44
+ return Default()->InternalRegister(node);
68
45
  }
46
+ static void Unregister(intptr_t uuid) { Default()->InternalUnregister(uuid); }
47
+ static BaseNode* Get(intptr_t uuid) { return Default()->InternalGet(uuid); }
69
48
 
70
49
  // Returns the allocated JSON string that represents the proto
71
50
  // GetTopChannelsResponse as per channelz.proto.
@@ -73,20 +52,13 @@ class ChannelzRegistry {
73
52
  return Default()->InternalGetTopChannels(start_channel_id);
74
53
  }
75
54
 
76
- private:
77
- enum class EntityType {
78
- kChannelNode,
79
- kSubchannelNode,
80
- kUnset,
81
- };
82
-
83
- struct RegistryEntry {
84
- RegistryEntry(void* object_in, EntityType type_in)
85
- : object(object_in), type(type_in) {}
86
- void* object;
87
- EntityType type;
88
- };
55
+ // Returns the allocated JSON string that represents the proto
56
+ // GetServersResponse as per channelz.proto.
57
+ static char* GetServers(intptr_t start_server_id) {
58
+ return Default()->InternalGetServers(start_server_id);
59
+ }
89
60
 
61
+ private:
90
62
  GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
91
63
  GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
92
64
 
@@ -97,21 +69,22 @@ class ChannelzRegistry {
97
69
  static ChannelzRegistry* Default();
98
70
 
99
71
  // globally registers an Entry. Returns its unique uuid
100
- intptr_t InternalRegisterEntry(const RegistryEntry& entry);
72
+ intptr_t InternalRegister(BaseNode* node);
101
73
 
102
74
  // globally unregisters the object that is associated to uuid. Also does
103
75
  // sanity check that an object doesn't try to unregister the wrong type.
104
- void InternalUnregisterEntry(intptr_t uuid, EntityType type);
76
+ void InternalUnregister(intptr_t uuid);
105
77
 
106
78
  // if object with uuid has previously been registered as the correct type,
107
79
  // returns the void* associated with that uuid. Else returns nullptr.
108
- void* InternalGetEntry(intptr_t uuid, EntityType type);
80
+ BaseNode* InternalGet(intptr_t uuid);
109
81
 
110
82
  char* InternalGetTopChannels(intptr_t start_channel_id);
83
+ char* InternalGetServers(intptr_t start_server_id);
111
84
 
112
85
  // protects entities_ and uuid_
113
86
  gpr_mu mu_;
114
- InlinedVector<RegistryEntry, 20> entities_;
87
+ InlinedVector<BaseNode*, 20> entities_;
115
88
  };
116
89
 
117
90
  } // namespace channelz