diff options
author | ncteisen <ncteisen@gmail.com> | 2018-10-29 18:53:44 -0700 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2018-10-29 18:54:35 -0700 |
commit | ba6f81297ce112f429ec88e7c62274a88655234f (patch) | |
tree | 5e93051d0b97626e97b35fe59c9658e278e61648 /src/core | |
parent | d7f5055b8dc73b7c4d67f6b0bb1ed52277640478 (diff) |
Socket tracks remote address
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ext/transport/chttp2/transport/chttp2_transport.cc | 3 | ||||
-rw-r--r-- | src/core/lib/channel/channelz.cc | 31 | ||||
-rw-r--r-- | src/core/lib/channel/channelz.h | 5 |
3 files changed, 35 insertions, 4 deletions
diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 04874a9494..d7934ab7aa 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -396,7 +396,8 @@ static bool read_channel_args(grpc_chttp2_transport* t, } if (channelz_enabled) { t->channelz_socket = - grpc_core::MakeRefCounted<grpc_core::channelz::SocketNode>(); + grpc_core::MakeRefCounted<grpc_core::channelz::SocketNode>( + (t->peer_string)); } return enable_bdp; } diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index 032654b861..bf8acebcd7 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -30,6 +30,7 @@ #include "src/core/lib/channel/channelz_registry.h" #include "src/core/lib/channel/status_util.h" +#include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/memory.h" @@ -277,7 +278,20 @@ grpc_json* ServerNode::RenderJson() { return top_level_json; } -SocketNode::SocketNode() : BaseNode(EntityType::kSocket) {} +SocketNode::SocketNode(const char* remote_peer_string) + : BaseNode(EntityType::kSocket) { + const char* ipv6_prefix = "ipv6:"; + const int ipv6_prefix_len = 5; + char* host; + char* port; + int offset = (strncmp(remote_peer_string, ipv6_prefix, ipv6_prefix_len) == 0) + ? ipv6_prefix_len + : 0; + GPR_ASSERT(gpr_split_host_port(remote_peer_string + offset, &host, &port)); + remote_host_ = UniquePtr<char>(host); + remote_port_ = atoi(port); + gpr_free(port); +} void SocketNode::RecordStreamStartedFromLocal() { gpr_atm_no_barrier_fetch_add(&streams_started_, static_cast<gpr_atm>(1)); @@ -315,6 +329,21 @@ grpc_json* SocketNode::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, "remote", 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", + remote_port_); + json_iterator = + grpc_json_create_child(json_iterator, json, "ip_address", + remote_host_.get(), GRPC_JSON_STRING, false); // reset json iterators to top level object json = top_level_json; json_iterator = nullptr; diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h index 8e66623142..ba10b1a5bf 100644 --- a/src/core/lib/channel/channelz.h +++ b/src/core/lib/channel/channelz.h @@ -232,7 +232,7 @@ class ServerNode : public BaseNode { // Handles channelz bookkeeping for sockets class SocketNode : public BaseNode { public: - SocketNode(); + SocketNode(const char* remote_peer_string); ~SocketNode() override {} grpc_json* RenderJson() override; @@ -262,7 +262,8 @@ class SocketNode : public BaseNode { gpr_atm last_remote_stream_created_millis_ = 0; gpr_atm last_message_sent_millis_ = 0; gpr_atm last_message_received_millis_ = 0; - UniquePtr<char> peer_string_; + UniquePtr<char> remote_host_; + int remote_port_; }; // Handles channelz bookkeeping for listen sockets |