Merge pull request #16761 from ncteisen/channelz-cpp

Channelz++ Part 5: GetServerSockets Support
pull/16753/head
Noah Eisen 6 years ago committed by GitHub
commit 520a4a297d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/cpp/server/channelz/channelz_service.cc
  2. 5
      src/cpp/server/channelz/channelz_service.h
  3. 26
      test/cpp/end2end/channelz_service_test.cc

@ -60,6 +60,23 @@ Status ChannelzService::GetServers(
return Status::OK;
}
Status ChannelzService::GetServerSockets(
ServerContext* unused, const channelz::v1::GetServerSocketsRequest* request,
channelz::v1::GetServerSocketsResponse* response) {
char* json_str = grpc_channelz_get_server_sockets(request->server_id(),
request->start_socket_id());
if (json_str == nullptr) {
return Status(INTERNAL, "grpc_channelz_get_server_sockets returned null");
}
google::protobuf::util::Status s =
google::protobuf::util::JsonStringToMessage(json_str, response);
gpr_free(json_str);
if (s != google::protobuf::util::Status::OK) {
return Status(INTERNAL, s.ToString());
}
return Status::OK;
}
Status ChannelzService::GetChannel(
ServerContext* unused, const channelz::v1::GetChannelRequest* request,
channelz::v1::GetChannelResponse* response) {

@ -36,6 +36,11 @@ class ChannelzService final : public channelz::v1::Channelz::Service {
Status GetServers(ServerContext* unused,
const channelz::v1::GetServersRequest* request,
channelz::v1::GetServersResponse* response) override;
// implementation of GetServerSockets rpc
Status GetServerSockets(
ServerContext* unused,
const channelz::v1::GetServerSocketsRequest* request,
channelz::v1::GetServerSocketsResponse* response) override;
// implementation of GetChannel rpc
Status GetChannel(ServerContext* unused,
const channelz::v1::GetChannelRequest* request,

@ -41,6 +41,8 @@
using grpc::channelz::v1::GetChannelRequest;
using grpc::channelz::v1::GetChannelResponse;
using grpc::channelz::v1::GetServerSocketsRequest;
using grpc::channelz::v1::GetServerSocketsResponse;
using grpc::channelz::v1::GetServersRequest;
using grpc::channelz::v1::GetServersResponse;
using grpc::channelz::v1::GetSocketRequest;
@ -600,6 +602,30 @@ TEST_F(ChannelzServerTest, StreamingRPC) {
kNumMessages);
}
TEST_F(ChannelzServerTest, GetServerSocketsTest) {
ResetStubs();
ConfigureProxy(1);
GetServersRequest get_server_request;
GetServersResponse get_server_response;
get_server_request.set_start_server_id(0);
ClientContext get_server_context;
Status s = channelz_stub_->GetServers(&get_server_context, get_server_request,
&get_server_response);
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message();
EXPECT_EQ(get_server_response.server_size(), 1);
GetServerSocketsRequest get_server_sockets_request;
GetServerSocketsResponse get_server_sockets_response;
get_server_sockets_request.set_server_id(
get_server_response.server(0).ref().server_id());
get_server_sockets_request.set_start_socket_id(0);
ClientContext get_server_sockets_context;
s = channelz_stub_->GetServerSockets(&get_server_sockets_context,
get_server_sockets_request,
&get_server_sockets_response);
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message();
EXPECT_EQ(get_server_sockets_response.socket_ref_size(), 1);
}
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save