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.
- checksums.yaml +4 -4
- data/Makefile +158 -80
- data/etc/roots.pem +23 -0
- data/include/grpc/grpc.h +13 -1
- data/include/grpc/grpc_security.h +2 -2
- data/include/grpc/grpc_security_constants.h +24 -19
- data/include/grpc/impl/codegen/grpc_types.h +23 -5
- data/include/grpc/impl/codegen/port_platform.h +1 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +95 -10
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +71 -0
- data/src/core/ext/filters/client_channel/client_channel_channelz.h +45 -11
- data/src/core/ext/filters/client_channel/connector.h +3 -0
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +5 -3
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +12 -32
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +6 -5
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +20 -15
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -4
- data/src/core/ext/filters/client_channel/parse_address.cc +27 -4
- data/src/core/ext/filters/client_channel/parse_address.h +3 -0
- data/src/core/ext/filters/client_channel/resolver.h +1 -12
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -11
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -19
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +9 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +5 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +70 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -11
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -16
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +0 -7
- data/src/core/ext/filters/client_channel/subchannel.cc +45 -7
- data/src/core/ext/filters/client_channel/subchannel.h +16 -1
- data/src/core/ext/filters/client_channel/subchannel_index.cc +2 -1
- data/src/core/ext/filters/client_channel/subchannel_index.h +1 -4
- data/src/core/ext/filters/http/client/http_client_filter.cc +32 -3
- data/src/core/ext/filters/http/server/http_server_filter.cc +59 -1
- data/src/core/ext/filters/max_age/max_age_filter.cc +1 -2
- data/src/core/ext/filters/message_size/message_size_filter.cc +59 -3
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +286 -228
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +14 -3
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +29 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +9 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +10 -0
- data/src/core/ext/transport/chttp2/transport/parsing.cc +85 -54
- data/src/core/ext/transport/chttp2/transport/writing.cc +6 -0
- data/src/core/lib/channel/channel_trace.cc +51 -56
- data/src/core/lib/channel/channel_trace.h +30 -25
- data/src/core/lib/channel/channelz.cc +235 -61
- data/src/core/lib/channel/channelz.h +179 -48
- data/src/core/lib/channel/channelz_registry.cc +95 -23
- data/src/core/lib/channel/channelz_registry.h +15 -42
- data/src/core/lib/gpr/sync_posix.cc +42 -0
- data/src/core/lib/http/httpcli.cc +1 -1
- data/src/core/lib/iomgr/buffer_list.cc +134 -0
- data/src/core/lib/iomgr/buffer_list.h +96 -0
- data/src/core/lib/iomgr/endpoint.cc +2 -2
- data/src/core/lib/iomgr/endpoint.h +6 -2
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
- data/src/core/lib/iomgr/error.cc +29 -18
- data/src/core/lib/iomgr/error.h +8 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_posix.cc +16 -10
- data/src/core/lib/iomgr/exec_ctx.h +0 -7
- data/src/core/lib/iomgr/{ev_epollsig_linux.h → internal_errqueue.cc} +13 -12
- data/src/core/lib/iomgr/internal_errqueue.h +83 -0
- data/src/core/lib/iomgr/port.h +11 -2
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +90 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
- data/src/core/lib/iomgr/tcp_client_posix.cc +4 -1
- data/src/core/lib/iomgr/tcp_custom.cc +1 -1
- data/src/core/lib/iomgr/tcp_posix.cc +306 -13
- data/src/core/lib/iomgr/tcp_posix.h +3 -0
- data/src/core/lib/iomgr/tcp_server_posix.cc +2 -2
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +4 -1
- data/src/core/lib/iomgr/tcp_windows.cc +1 -1
- data/src/core/lib/iomgr/timer_generic.cc +13 -12
- data/src/core/lib/iomgr/timer_heap.cc +2 -2
- data/src/core/lib/iomgr/timer_heap.h +3 -3
- data/src/core/lib/iomgr/timer_manager.cc +28 -3
- data/src/core/lib/iomgr/timer_manager.h +2 -2
- data/src/core/lib/iomgr/udp_server.cc +1 -1
- data/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc +2 -1
- data/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +2 -1
- data/src/core/lib/security/security_connector/security_connector.cc +7 -7
- data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
- data/src/core/lib/security/transport/security_handshaker.cc +1 -1
- data/src/core/lib/security/transport/server_auth_filter.cc +53 -4
- data/src/core/lib/slice/slice.cc +8 -0
- data/src/core/lib/slice/slice_internal.h +5 -0
- data/src/core/lib/surface/call.cc +149 -253
- data/src/core/lib/surface/call.h +1 -0
- data/src/core/lib/surface/channel.cc +17 -13
- data/src/core/lib/surface/completion_queue.cc +21 -17
- data/src/core/lib/surface/completion_queue.h +1 -18
- data/src/core/lib/surface/completion_queue_factory.cc +3 -3
- data/src/core/lib/surface/init_secure.cc +1 -1
- data/src/core/lib/surface/server.cc +77 -4
- data/src/core/lib/surface/server.h +4 -0
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +0 -18
- data/src/core/lib/transport/metadata.h +0 -3
- data/src/core/lib/transport/metadata_batch.cc +2 -2
- data/src/core/lib/transport/metadata_batch.h +2 -0
- data/src/core/lib/transport/static_metadata.cc +220 -249
- data/src/core/lib/transport/static_metadata.h +189 -191
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +5 -4
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +3 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_event.cc +4 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +6 -5
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +3 -1
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +2 -2
- data/src/core/tsi/alts_transport_security.cc +3 -1
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +2 -1
- data/src/ruby/ext/grpc/rb_call.c +1 -0
- data/src/ruby/ext/grpc/rb_channel.c +3 -0
- data/src/ruby/ext/grpc/rb_grpc.c +31 -1
- data/src/ruby/ext/grpc/rb_grpc.h +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +12 -3
- data/src/ruby/ext/grpc/rb_server.c +2 -0
- data/src/ruby/lib/grpc/errors.rb +0 -1
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +3 -3
- data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/channel_spec.rb +44 -0
- data/src/ruby/spec/client_auth_spec.rb +5 -5
- data/src/ruby/spec/generic/client_stub_spec.rb +13 -9
- data/src/ruby/spec/generic/rpc_server_spec.rb +3 -3
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -0
- data/src/ruby/spec/support/services.rb +28 -22
- metadata +35 -31
- 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
|
60
|
+
// base class for all channelz entities
|
61
|
+
class BaseNode : public RefCounted<BaseNode> {
|
50
62
|
public:
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
80
|
+
// Renders the json and returns allocated string that must be freed by the
|
81
|
+
// caller.
|
64
82
|
char* RenderJsonString();
|
65
83
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
146
|
+
grpc_json* RenderJson() override;
|
72
147
|
|
73
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
//
|
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
|
-
|
99
|
-
|
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
|
-
//
|
108
|
-
|
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
|
-
|
113
|
-
|
196
|
+
explicit ServerNode(size_t channel_tracer_max_nodes);
|
197
|
+
~ServerNode() override;
|
198
|
+
|
199
|
+
grpc_json* RenderJson() override;
|
114
200
|
|
115
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
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::
|
56
|
+
intptr_t ChannelzRegistry::InternalRegister(BaseNode* node) {
|
57
57
|
MutexLock lock(&mu_);
|
58
|
-
entities_.push_back(
|
58
|
+
entities_.push_back(node);
|
59
59
|
intptr_t uuid = entities_.size();
|
60
60
|
return uuid;
|
61
61
|
}
|
62
62
|
|
63
|
-
void ChannelzRegistry::
|
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
|
-
|
68
|
-
entities_[uuid - 1].object = nullptr;
|
69
|
-
entities_[uuid - 1].type = EntityType::kUnset;
|
67
|
+
entities_[uuid - 1] = nullptr;
|
70
68
|
}
|
71
69
|
|
72
|
-
|
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
|
-
|
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<
|
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]
|
96
|
-
|
97
|
-
|
98
|
-
|
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.
|
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::
|
133
|
-
grpc_core::channelz::ChannelzRegistry::
|
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
|
-
|
44
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
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
|
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
|
-
|
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<
|
87
|
+
InlinedVector<BaseNode*, 20> entities_;
|
115
88
|
};
|
116
89
|
|
117
90
|
} // namespace channelz
|