Add C++ support for GetServers

pull/16360/head
ncteisen 6 years ago
parent 47edf79e3a
commit 70ef911343
  1. 16
      src/cpp/server/channelz/channelz_service.cc
  2. 4
      src/cpp/server/channelz/channelz_service.h
  3. 41
      test/cpp/end2end/channelz_service_test.cc

@ -44,6 +44,22 @@ Status ChannelzService::GetTopChannels(
return Status::OK;
}
Status ChannelzService::GetServers(
ServerContext* unused, const channelz::v1::GetServersRequest* request,
channelz::v1::GetServersResponse* response) {
char* json_str = grpc_channelz_get_servers(request->start_server_id());
if (json_str == nullptr) {
return Status(INTERNAL, "grpc_channelz_get_servers 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) {

@ -32,6 +32,10 @@ class ChannelzService final : public channelz::v1::Channelz::Service {
Status GetTopChannels(
ServerContext* unused, const channelz::v1::GetTopChannelsRequest* request,
channelz::v1::GetTopChannelsResponse* response) override;
// implementation of GetServers rpc
Status GetServers(ServerContext* unused,
const channelz::v1::GetServersRequest* request,
channelz::v1::GetServersResponse* 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::GetServersRequest;
using grpc::channelz::v1::GetServersResponse;
using grpc::channelz::v1::GetSubchannelRequest;
using grpc::channelz::v1::GetSubchannelResponse;
using grpc::channelz::v1::GetTopChannelsRequest;
@ -415,6 +417,45 @@ TEST_F(ChannelzServerTest, ManySubchannels) {
}
}
TEST_F(ChannelzServerTest, BasicServerTest) {
ResetStubs();
ConfigureProxy(1);
GetServersRequest request;
GetServersResponse response;
request.set_start_server_id(0);
ClientContext context;
Status s = channelz_stub_->GetServers(&context, request, &response);
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message();
EXPECT_EQ(response.server_size(), 1);
}
TEST_F(ChannelzServerTest, ServerCallTest) {
ResetStubs();
ConfigureProxy(1);
const int kNumSuccess = 10;
const int kNumFailed = 11;
for (int i = 0; i < kNumSuccess; ++i) {
SendSuccessfulEcho(0);
}
for (int i = 0; i < kNumFailed; ++i) {
SendFailedEcho(0);
}
GetServersRequest request;
GetServersResponse response;
request.set_start_server_id(0);
ClientContext context;
Status s = channelz_stub_->GetServers(&context, request, &response);
EXPECT_TRUE(s.ok()) << "s.error_message() = " << s.error_message();
EXPECT_EQ(response.server_size(), 1);
EXPECT_EQ(response.server(0).data().calls_succeeded(), kNumSuccess);
EXPECT_EQ(response.server(0).data().calls_failed(), kNumFailed);
// This is success+failure+1 because the call that retrieved this information
// will be counted as started. It will not track success/failure until after
// it has returned, so that is not included in the response.
EXPECT_EQ(response.server(0).data().calls_started(),
kNumSuccess + kNumFailed + 1);
}
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save