|
|
|
@ -204,16 +204,27 @@ ServerNode::ServerNode(grpc_server* server, size_t channel_tracer_max_nodes) |
|
|
|
|
ServerNode::~ServerNode() {} |
|
|
|
|
|
|
|
|
|
char* ServerNode::RenderServerSockets(intptr_t start_socket_id) { |
|
|
|
|
const int kPaginationLimit = 100; |
|
|
|
|
grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT); |
|
|
|
|
grpc_json* json = top_level_json; |
|
|
|
|
grpc_json* json_iterator = nullptr; |
|
|
|
|
ChildSocketsList socket_refs; |
|
|
|
|
grpc_server_populate_server_sockets(server_, &socket_refs, start_socket_id); |
|
|
|
|
int sockets_added = 0; |
|
|
|
|
bool reached_pagination_limit = false; |
|
|
|
|
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) { |
|
|
|
|
// check if we are over pagination limit to determine if we need to set
|
|
|
|
|
// the "end" element. If we don't go through this block, we know that
|
|
|
|
|
// when the loop terminates, we have <= to kPaginationLimit.
|
|
|
|
|
if (sockets_added == kPaginationLimit) { |
|
|
|
|
reached_pagination_limit = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
sockets_added++; |
|
|
|
|
grpc_json* socket_ref_json = |
|
|
|
|
grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr, |
|
|
|
|
GRPC_JSON_OBJECT, false); |
|
|
|
@ -223,11 +234,10 @@ char* ServerNode::RenderServerSockets(intptr_t start_socket_id) { |
|
|
|
|
socket_refs[i]->remote(), GRPC_JSON_STRING, false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 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); |
|
|
|
|
if (!reached_pagination_limit) { |
|
|
|
|
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; |
|
|
|
|