aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/channel/channelz.cc
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-10-02 09:55:00 -0700
committerGravatar ncteisen <ncteisen@gmail.com>2018-10-02 09:55:00 -0700
commit3545d754d53448ce4ce17ac9605d4765094aa739 (patch)
tree1e55733262852b2683a91f8f7a471822ea796904 /src/core/lib/channel/channelz.cc
parentfd2fe1d5c42e95dc7c9a0dc59c6233d70ae85ff4 (diff)
Channelz get server sockets support
Diffstat (limited to 'src/core/lib/channel/channelz.cc')
-rw-r--r--src/core/lib/channel/channelz.cc35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc
index c1194ae872..47ba1492ea 100644
--- a/src/core/lib/channel/channelz.cc
+++ b/src/core/lib/channel/channelz.cc
@@ -157,6 +157,38 @@ ServerNode::ServerNode(grpc_server* server, size_t channel_tracer_max_nodes)
ServerNode::~ServerNode() {}
+char* ServerNode::RenderServerSockets(intptr_t start_socket_id) {
+ grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
+ grpc_json* json = top_level_json;
+ grpc_json* json_iterator = nullptr;
+ ChildRefsList socket_refs;
+ // uuids index into entities one-off (idx 0 is really uuid 1, since 0 is
+ // reserved). However, we want to support requests coming in with
+ // start_server_id=0, which signifies "give me everything."
+ size_t start_idx = start_socket_id == 0 ? 0 : start_socket_id - 1;
+ grpc_server_populate_listen_sockets(server_, &socket_refs, start_idx);
+ if (!socket_refs.empty()) {
+ // create list of socket refs
+ grpc_json* array_parent = grpc_json_create_child(
+ nullptr, json, "socketRef", nullptr, GRPC_JSON_ARRAY, false);
+ for (size_t i = 0; i < socket_refs.size(); ++i) {
+ json_iterator =
+ grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr,
+ GRPC_JSON_OBJECT, false);
+ grpc_json_add_number_string_child(json_iterator, nullptr, "socketId",
+ socket_refs[i]);
+ }
+ }
+ // For now we do not have any pagination rules. In the future we could
+ // pick a constant for max_channels_sent for a GetServers request.
+ // Tracking: https://github.com/grpc/grpc/issues/16019.
+ json_iterator = grpc_json_create_child(nullptr, json, "end", nullptr,
+ GRPC_JSON_TRUE, false);
+ char* json_str = grpc_json_dump_to_string(top_level_json, 0);
+ grpc_json_destroy(top_level_json);
+ return json_str;
+}
+
grpc_json* ServerNode::RenderJson() {
// We need to track these three json objects to build our object
grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
@@ -187,7 +219,8 @@ grpc_json* ServerNode::RenderJson() {
call_counter_.PopulateCallCounts(json);
json = top_level_json;
ChildRefsList listen_sockets;
- grpc_server_populate_listen_sockets(server_, &listen_sockets);
+ grpc_server_populate_listen_sockets(server_, &listen_sockets,
+ 0 /* start_idx*/);
if (!listen_sockets.empty()) {
grpc_json* array_parent = grpc_json_create_child(
nullptr, json, "listenSocket", nullptr, GRPC_JSON_ARRAY, false);