Channelz get server sockets support

reviewable/pr16760/r1
ncteisen 6 years ago
parent fd2fe1d5c4
commit 3545d754d5
  1. 1
      grpc.def
  2. 4
      include/grpc/grpc.h
  3. 35
      src/core/lib/channel/channelz.cc
  4. 10
      src/core/lib/channel/channelz.h
  5. 12
      src/core/lib/channel/channelz_registry.cc
  6. 10
      src/core/lib/surface/server.cc
  7. 3
      src/core/lib/surface/server.h
  8. 2
      src/ruby/ext/grpc/rb_grpc_imports.generated.c
  9. 3
      src/ruby/ext/grpc/rb_grpc_imports.generated.h
  10. 1
      test/core/surface/public_headers_must_be_c89.c

@ -75,6 +75,7 @@ EXPORTS
grpc_resource_quota_arg_vtable
grpc_channelz_get_top_channels
grpc_channelz_get_servers
grpc_channelz_get_server_sockets
grpc_channelz_get_channel
grpc_channelz_get_subchannel
grpc_channelz_get_socket

@ -503,6 +503,10 @@ GRPCAPI char* grpc_channelz_get_top_channels(intptr_t start_channel_id);
/* Gets all servers that exist in the process. */
GRPCAPI char* grpc_channelz_get_servers(intptr_t start_server_id);
/* Gets all server sockets that exist in the server. */
GRPCAPI char* grpc_channelz_get_server_sockets(intptr_t server_id,
intptr_t start_socket_id);
/* Returns a single Channel, or else a NOT_FOUND code. The returned string
is allocated and must be freed by the application. */
GRPCAPI char* grpc_channelz_get_channel(intptr_t channel_id);

@ -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);

@ -74,6 +74,12 @@ class BaseNode : public RefCounted<BaseNode> {
// All children must implement this function.
virtual grpc_json* RenderJson() GRPC_ABSTRACT;
// Fat interface for functionality that will only ever be called on Servers.
// All other channelz entities will assert false.
virtual char* RenderServerSockets(intptr_t start_socket_id) {
GPR_ASSERT(false);
}
// Renders the json and returns allocated string that must be freed by the
// caller.
char* RenderJsonString();
@ -184,6 +190,10 @@ class ServerNode : public BaseNode {
grpc_json* RenderJson() override;
// Server overrides this functionality to populate the JSON with
// the sockets it owns.
char* RenderServerSockets(intptr_t start_socket_id) override;
// proxy methods to composed classes.
void AddTraceEvent(ChannelTrace::Severity severity, grpc_slice data) {
trace_.AddTraceEvent(severity, data);

@ -160,6 +160,18 @@ char* grpc_channelz_get_servers(intptr_t start_server_id) {
return grpc_core::channelz::ChannelzRegistry::GetServers(start_server_id);
}
char* grpc_channelz_get_server_sockets(intptr_t server_id,
intptr_t start_socket_id) {
grpc_core::channelz::BaseNode* server_node =
grpc_core::channelz::ChannelzRegistry::Get(server_id);
if (server_node == nullptr ||
server_node->type() !=
grpc_core::channelz::BaseNode::EntityType::kServer) {
return nullptr;
}
return server_node->RenderServerSockets(start_socket_id);
}
char* grpc_channelz_get_channel(intptr_t channel_id) {
grpc_core::channelz::BaseNode* channel_node =
grpc_core::channelz::ChannelzRegistry::Get(channel_id);

@ -1213,7 +1213,8 @@ void grpc_server_setup_transport(grpc_server* s, grpc_transport* transport,
}
void grpc_server_populate_listen_sockets(
grpc_server* s, grpc_core::ChildRefsList* listen_sockets) {
grpc_server* s, grpc_core::ChildRefsList* listen_sockets,
intptr_t start_idx) {
gpr_mu_lock(&s->mu_global);
channel_data* c = nullptr;
for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) {
@ -1221,8 +1222,11 @@ void grpc_server_populate_listen_sockets(
grpc_channel_element* connected_channel_elem =
grpc_channel_stack_last_element(
grpc_channel_get_channel_stack(c->channel));
listen_sockets->push_back(
grpc_connected_channel_get_socket_uuid(connected_channel_elem));
intptr_t socket_uuid =
grpc_connected_channel_get_socket_uuid(connected_channel_elem);
if (socket_uuid >= start_idx) {
listen_sockets->push_back(socket_uuid);
}
}
}
gpr_mu_unlock(&s->mu_global);

@ -48,7 +48,8 @@ void grpc_server_setup_transport(grpc_server* server, grpc_transport* transport,
const grpc_channel_args* args);
void grpc_server_populate_listen_sockets(
grpc_server* server, grpc_core::ChildRefsList* listen_sockets);
grpc_server* server, grpc_core::ChildRefsList* listen_sockets,
intptr_t start_idx);
grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
grpc_server* server);

@ -98,6 +98,7 @@ grpc_resource_quota_set_max_threads_type grpc_resource_quota_set_max_threads_imp
grpc_resource_quota_arg_vtable_type grpc_resource_quota_arg_vtable_import;
grpc_channelz_get_top_channels_type grpc_channelz_get_top_channels_import;
grpc_channelz_get_servers_type grpc_channelz_get_servers_import;
grpc_channelz_get_server_sockets_type grpc_channelz_get_server_sockets_import;
grpc_channelz_get_channel_type grpc_channelz_get_channel_import;
grpc_channelz_get_subchannel_type grpc_channelz_get_subchannel_import;
grpc_channelz_get_socket_type grpc_channelz_get_socket_import;
@ -355,6 +356,7 @@ void grpc_rb_load_imports(HMODULE library) {
grpc_resource_quota_arg_vtable_import = (grpc_resource_quota_arg_vtable_type) GetProcAddress(library, "grpc_resource_quota_arg_vtable");
grpc_channelz_get_top_channels_import = (grpc_channelz_get_top_channels_type) GetProcAddress(library, "grpc_channelz_get_top_channels");
grpc_channelz_get_servers_import = (grpc_channelz_get_servers_type) GetProcAddress(library, "grpc_channelz_get_servers");
grpc_channelz_get_server_sockets_import = (grpc_channelz_get_server_sockets_type) GetProcAddress(library, "grpc_channelz_get_server_sockets");
grpc_channelz_get_channel_import = (grpc_channelz_get_channel_type) GetProcAddress(library, "grpc_channelz_get_channel");
grpc_channelz_get_subchannel_import = (grpc_channelz_get_subchannel_type) GetProcAddress(library, "grpc_channelz_get_subchannel");
grpc_channelz_get_socket_import = (grpc_channelz_get_socket_type) GetProcAddress(library, "grpc_channelz_get_socket");

@ -269,6 +269,9 @@ extern grpc_channelz_get_top_channels_type grpc_channelz_get_top_channels_import
typedef char*(*grpc_channelz_get_servers_type)(intptr_t start_server_id);
extern grpc_channelz_get_servers_type grpc_channelz_get_servers_import;
#define grpc_channelz_get_servers grpc_channelz_get_servers_import
typedef char*(*grpc_channelz_get_server_sockets_type)(intptr_t server_id, intptr_t start_socket_id);
extern grpc_channelz_get_server_sockets_type grpc_channelz_get_server_sockets_import;
#define grpc_channelz_get_server_sockets grpc_channelz_get_server_sockets_import
typedef char*(*grpc_channelz_get_channel_type)(intptr_t channel_id);
extern grpc_channelz_get_channel_type grpc_channelz_get_channel_import;
#define grpc_channelz_get_channel grpc_channelz_get_channel_import

@ -137,6 +137,7 @@ int main(int argc, char **argv) {
printf("%lx", (unsigned long) grpc_resource_quota_arg_vtable);
printf("%lx", (unsigned long) grpc_channelz_get_top_channels);
printf("%lx", (unsigned long) grpc_channelz_get_servers);
printf("%lx", (unsigned long) grpc_channelz_get_server_sockets);
printf("%lx", (unsigned long) grpc_channelz_get_channel);
printf("%lx", (unsigned long) grpc_channelz_get_subchannel);
printf("%lx", (unsigned long) grpc_channelz_get_socket);

Loading…
Cancel
Save