Merge pull request #17045 from ncteisen/channelz-listen-sockets

Listen Sockets Track their Port
pull/17054/head
Noah Eisen 6 years ago committed by GitHub
commit d7f5055b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/core/ext/transport/chttp2/server/chttp2_server.cc
  2. 18
      src/core/lib/channel/channelz.cc
  3. 7
      src/core/lib/channel/channelz.h

@ -37,6 +37,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/channel/handshaker_registry.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/resource_quota.h"
@ -366,8 +367,14 @@ grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr,
arg = grpc_channel_args_find(args, GRPC_ARG_ENABLE_CHANNELZ);
if (grpc_channel_arg_get_bool(arg, false)) {
char* host;
char* port;
gpr_split_host_port(addr, &host, &port);
// allocated host's ownership is passed to ListenSocketNode.
state->channelz_listen_socket =
grpc_core::MakeRefCounted<grpc_core::channelz::ListenSocketNode>();
grpc_core::MakeRefCounted<grpc_core::channelz::ListenSocketNode>(
grpc_core::UniquePtr<char>(host), *port_num);
gpr_free(port);
socket_uuid = state->channelz_listen_socket->uuid();
}

@ -374,7 +374,8 @@ grpc_json* SocketNode::RenderJson() {
return top_level_json;
}
ListenSocketNode::ListenSocketNode() : BaseNode(EntityType::kSocket) {}
ListenSocketNode::ListenSocketNode(UniquePtr<char> host, int port)
: BaseNode(EntityType::kSocket), host_(std::move(host)), port_(port) {}
grpc_json* ListenSocketNode::RenderJson() {
// We need to track these three json objects to build our object
@ -388,6 +389,21 @@ grpc_json* ListenSocketNode::RenderJson() {
json_iterator = nullptr;
json_iterator = grpc_json_add_number_string_child(json, json_iterator,
"socketId", uuid());
json = top_level_json;
json_iterator = nullptr;
json_iterator = grpc_json_create_child(json_iterator, json, "local", nullptr,
GRPC_JSON_OBJECT, false);
json = json_iterator;
json_iterator = nullptr;
json_iterator = grpc_json_create_child(json_iterator, json, "tcpip_address",
nullptr, GRPC_JSON_OBJECT, false);
json = json_iterator;
json_iterator = nullptr;
json_iterator =
grpc_json_add_number_string_child(json, json_iterator, "port", port_);
json_iterator = grpc_json_create_child(json_iterator, json, "ip_address",
host_.get(), GRPC_JSON_STRING, false);
return top_level_json;
}

@ -268,10 +268,15 @@ class SocketNode : public BaseNode {
// Handles channelz bookkeeping for listen sockets
class ListenSocketNode : public BaseNode {
public:
ListenSocketNode();
// ListenSocketNode takes ownership of host.
ListenSocketNode(UniquePtr<char> host, int port);
~ListenSocketNode() override {}
grpc_json* RenderJson() override;
private:
UniquePtr<char> host_;
int port_;
};
// Creation functions

Loading…
Cancel
Save