Add GetServer to channelz cpp

pull/17020/head
ncteisen 6 years ago
parent 5cf95f0b52
commit bc44c5e353
  1. 17
      src/cpp/server/channelz/channelz_service.cc
  2. 4
      src/cpp/server/channelz/channelz_service.h
  3. 25
      test/cpp/end2end/channelz_service_test.cc

@ -59,6 +59,23 @@ Status ChannelzService::GetServers(
return Status::OK;
}
Status ChannelzService::GetServer(ServerContext* unused,
const channelz::v1::GetServerRequest* request,
channelz::v1::GetServerResponse* response) {
char* json_str = grpc_channelz_get_server(request->server_id());
if (json_str == nullptr) {
return Status(StatusCode::INTERNAL,
"grpc_channelz_get_server returned null");
}
grpc::protobuf::util::Status s =
grpc::protobuf::json::JsonStringToMessage(json_str, response);
gpr_free(json_str);
if (!s.ok()) {
return Status(StatusCode::INTERNAL, s.ToString());
}
return Status::OK;
}
Status ChannelzService::GetServerSockets(
ServerContext* unused, const channelz::v1::GetServerSocketsRequest* request,
channelz::v1::GetServerSocketsResponse* response) {

@ -36,6 +36,10 @@ class ChannelzService final : public channelz::v1::Channelz::Service {
Status GetServers(ServerContext* unused,
const channelz::v1::GetServersRequest* request,
channelz::v1::GetServersResponse* response) override;
// implementation of GetServer rpc
Status GetServer(ServerContext* unused,
const channelz::v1::GetServerRequest* request,
channelz::v1::GetServerResponse* response) override;
// implementation of GetServerSockets rpc
Status GetServerSockets(
ServerContext* unused,

@ -41,6 +41,8 @@
using grpc::channelz::v1::GetChannelRequest;
using grpc::channelz::v1::GetChannelResponse;
using grpc::channelz::v1::GetServerRequest;
using grpc::channelz::v1::GetServerResponse;
using grpc::channelz::v1::GetServerSocketsRequest;
using grpc::channelz::v1::GetServerSocketsResponse;
using grpc::channelz::v1::GetServersRequest;
@ -460,6 +462,29 @@ TEST_F(ChannelzServerTest, BasicServerTest) {
EXPECT_EQ(response.server_size(), 1);
}
TEST_F(ChannelzServerTest, BasicGetServerTest) {
ResetStubs();
ConfigureProxy(1);
GetServersRequest get_servers_request;
GetServersResponse get_servers_response;
get_servers_request.set_start_server_id(0);
ClientContext get_servers_context;
Status s = channelz_stub_->GetServers(
&get_servers_context, get_servers_request, &get_servers_response);
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message();
EXPECT_EQ(get_servers_response.server_size(), 1);
GetServerRequest get_server_request;
GetServerResponse get_server_response;
get_server_request.set_server_id(
get_servers_response.server(0).ref().server_id());
ClientContext get_server_context;
s = channelz_stub_->GetServer(&get_server_context, get_server_request,
&get_server_response);
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message();
EXPECT_EQ(get_servers_response.server(0).ref().server_id(),
get_server_response.server().ref().server_id());
}
TEST_F(ChannelzServerTest, ServerCallTest) {
ResetStubs();
ConfigureProxy(1);

Loading…
Cancel
Save