Add channelz server support

reviewable/pr16346/r2
ncteisen 6 years ago
parent b8f030bc0b
commit 3aa987a29a
  1. 3
      include/grpc/grpc.h
  2. 41
      src/core/lib/channel/channelz.cc
  3. 28
      src/core/lib/channel/channelz.h
  4. 40
      src/core/lib/channel/channelz_registry.cc
  5. 7
      src/core/lib/channel/channelz_registry.h
  6. 54
      src/core/lib/surface/call.cc
  7. 1
      src/core/lib/surface/call.h
  8. 7
      src/core/lib/surface/channel.cc
  9. 24
      src/core/lib/surface/server.cc
  10. 4
      src/core/lib/surface/server.h
  11. 90
      test/core/channel/channelz_test.cc
  12. 67
      test/core/end2end/tests/channelz.cc
  13. 9
      test/cpp/util/channel_trace_proto_helper.cc
  14. 2
      test/cpp/util/channel_trace_proto_helper.h

@ -483,6 +483,9 @@ GRPCAPI const grpc_arg_pointer_vtable* grpc_resource_quota_arg_vtable(void);
The returned string is allocated and must be freed by the application. */
GRPCAPI char* grpc_channelz_get_top_channels(intptr_t start_channel_id);
/* Gets all servers that exist in the process. */
GRPCAPI char* grpc_channelz_get_servers(intptr_t start_channel_id);
/* Returns a single Channel, or else a NOT_FOUND code. The returned string
is allocated and must be freed by the application. */
GRPCAPI char* grpc_channelz_get_channel(intptr_t channel_id);

@ -48,6 +48,7 @@ BaseNode::~BaseNode() { ChannelzRegistry::Unregister(uuid_); }
char* BaseNode::RenderJsonString() {
grpc_json* json = RenderJson();
GPR_ASSERT(json != nullptr);
char* json_str = grpc_json_dump_to_string(json, 0);
grpc_json_destroy(json);
return json_str;
@ -146,5 +147,45 @@ RefCountedPtr<ChannelNode> ChannelNode::MakeChannelNode(
channel, channel_tracer_max_nodes, is_top_level_channel);
}
ServerNode::ServerNode(size_t channel_tracer_max_nodes)
: BaseNode(EntityType::kServer), trace_(channel_tracer_max_nodes) {}
ServerNode::~ServerNode() {}
grpc_json* ServerNode::RenderJson() {
// We need to track these three json objects to build our object
grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
grpc_json* json = top_level_json;
grpc_json* json_iterator = nullptr;
// create and fill the ref child
json_iterator = grpc_json_create_child(json_iterator, json, "ref", nullptr,
GRPC_JSON_OBJECT, false);
json = json_iterator;
json_iterator = nullptr;
json_iterator = grpc_json_add_number_string_child(json, json_iterator,
"serverId", uuid());
// reset json iterators to top level object
json = top_level_json;
json_iterator = nullptr;
// create and fill the data child.
grpc_json* data = grpc_json_create_child(json_iterator, json, "data", nullptr,
GRPC_JSON_OBJECT, false);
json = data;
json_iterator = nullptr;
// fill in the channel trace if applicable
grpc_json* trace_json = trace_.RenderJson();
if (trace_json != nullptr) {
trace_json->key = "trace"; // this object is named trace in channelz.proto
grpc_json_link_child(json, trace_json, nullptr);
}
// ask CallCountingHelper to populate trace and call count data.
call_counter_.PopulateCallCounts(json);
json = top_level_json;
// template method. Child classes may override this to add their specific
// functionality.
PopulateSockets(json);
return top_level_json;
}
} // namespace channelz
} // namespace grpc_core

@ -167,12 +167,32 @@ class ChannelNode : public BaseNode {
};
// Handles channelz bookkeeping for servers
// TODO(ncteisen): implement in subsequent PR.
class ServerNode : public BaseNode {
public:
explicit ServerNode(size_t channel_tracer_max_nodes)
: BaseNode(EntityType::kServer) {}
~ServerNode() override {}
explicit ServerNode(size_t channel_tracer_max_nodes);
~ServerNode() override;
grpc_json* RenderJson() override;
void PopulateSockets(grpc_json* json) {}
// proxy methods to composed classes.
void AddTraceEvent(ChannelTrace::Severity severity, grpc_slice data) {
trace_.AddTraceEvent(severity, data);
}
void AddTraceEventWithReference(ChannelTrace::Severity severity,
grpc_slice data,
RefCountedPtr<BaseNode> referenced_channel) {
trace_.AddTraceEventWithReference(severity, data,
std::move(referenced_channel));
}
void RecordCallStarted() { call_counter_.RecordCallStarted(); }
void RecordCallFailed() { call_counter_.RecordCallFailed(); }
void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
private:
CallCountingHelper call_counter_;
ChannelTrace trace_;
};
// Handles channelz bookkeeping for sockets

@ -111,6 +111,42 @@ char* ChannelzRegistry::InternalGetTopChannels(intptr_t start_channel_id) {
return json_str;
}
char* ChannelzRegistry::InternalGetServers(intptr_t start_server_id) {
grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
grpc_json* json = top_level_json;
grpc_json* json_iterator = nullptr;
InlinedVector<BaseNode*, 10> servers;
// uuids index into entities one-off (idx 0 is really uuid 1, since 0 is
// reserved). However, we want to support requests coming in with
// start_server_id=0, which signifies "give me everything."
size_t start_idx = start_server_id == 0 ? 0 : start_server_id - 1;
for (size_t i = start_idx; i < entities_.size(); ++i) {
if (entities_[i] != nullptr &&
entities_[i]->type() ==
grpc_core::channelz::BaseNode::EntityType::kServer) {
servers.push_back(entities_[i]);
}
}
if (!servers.empty()) {
// create list of servers
grpc_json* array_parent = grpc_json_create_child(
nullptr, json, "server", nullptr, GRPC_JSON_ARRAY, false);
for (size_t i = 0; i < servers.size(); ++i) {
grpc_json* server_json = servers[i]->RenderJson();
json_iterator =
grpc_json_link_child(array_parent, server_json, json_iterator);
}
}
// For now we do not have any pagination rules. In the future we could
// pick a constant for max_channels_sent for a GetServers request.
// Tracking: https://github.com/grpc/grpc/issues/16019.
json_iterator = grpc_json_create_child(nullptr, json, "end", nullptr,
GRPC_JSON_TRUE, false);
char* json_str = grpc_json_dump_to_string(top_level_json, 0);
grpc_json_destroy(top_level_json);
return json_str;
}
} // namespace channelz
} // namespace grpc_core
@ -119,6 +155,10 @@ char* grpc_channelz_get_top_channels(intptr_t start_channel_id) {
start_channel_id);
}
char* grpc_channelz_get_servers(intptr_t start_server_id) {
return grpc_core::channelz::ChannelzRegistry::GetServers(start_server_id);
}
char* grpc_channelz_get_channel(intptr_t channel_id) {
grpc_core::channelz::BaseNode* channel_node =
grpc_core::channelz::ChannelzRegistry::Get(channel_id);

@ -52,6 +52,12 @@ class ChannelzRegistry {
return Default()->InternalGetTopChannels(start_channel_id);
}
// Returns the allocated JSON string that represents the proto
// GetServersResponse as per channelz.proto.
static char* GetServers(intptr_t start_server_id) {
return Default()->InternalGetServers(start_server_id);
}
private:
GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
@ -74,6 +80,7 @@ class ChannelzRegistry {
BaseNode* InternalGet(intptr_t uuid);
char* InternalGetTopChannels(intptr_t start_channel_id);
char* InternalGetServers(intptr_t start_server_id);
// protects entities_ and uuid_
gpr_mu mu_;

@ -48,6 +48,7 @@
#include "src/core/lib/surface/call_test_only.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/server.h"
#include "src/core/lib/surface/validate_metadata.h"
#include "src/core/lib/transport/error_utils.h"
#include "src/core/lib/transport/metadata.h"
@ -166,6 +167,8 @@ struct grpc_call {
grpc_completion_queue* cq;
grpc_polling_entity pollent;
grpc_channel* channel;
// backpointer to owning server if this is a server side call.
grpc_server* server;
gpr_timespec start_time;
/* parent_call* */ gpr_atm parent_call_atm;
child_call* child;
@ -362,14 +365,11 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
/* Always support no compression */
GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_MESSAGE_COMPRESS_NONE);
call->is_client = args->server_transport_data == nullptr;
if (call->is_client) {
GRPC_STATS_INC_CLIENT_CALLS_CREATED();
} else {
GRPC_STATS_INC_SERVER_CALLS_CREATED();
}
call->stream_op_payload.context = call->context;
grpc_slice path = grpc_empty_slice();
if (call->is_client) {
GRPC_STATS_INC_CLIENT_CALLS_CREATED();
call->server = nullptr;
GPR_ASSERT(args->add_initial_metadata_count <
MAX_SEND_EXTRA_METADATA_COUNT);
for (i = 0; i < args->add_initial_metadata_count; i++) {
@ -383,6 +383,8 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
call->send_extra_metadata_count =
static_cast<int>(args->add_initial_metadata_count);
} else {
GRPC_STATS_INC_SERVER_CALLS_CREATED();
call->server = args->server;
GPR_ASSERT(args->add_initial_metadata_count == 0);
call->send_extra_metadata_count = 0;
}
@ -486,10 +488,18 @@ grpc_error* grpc_call_create(const grpc_call_create_args* args,
&call->pollent);
}
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(call->channel);
if (channelz_channel != nullptr) {
channelz_channel->RecordCallStarted();
if (call->is_client) {
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(call->channel);
if (channelz_channel != nullptr) {
channelz_channel->RecordCallStarted();
}
} else {
grpc_core::channelz::ServerNode* channelz_server =
grpc_server_get_channelz_node(call->server);
if (channelz_server != nullptr) {
channelz_server->RecordCallStarted();
}
}
grpc_slice_unref_internal(path);
@ -1263,18 +1273,26 @@ static void post_batch_completion(batch_control* bctl) {
call->final_op.client.status,
call->final_op.client.status_details,
call->final_op.client.error_string);
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(call->channel);
if (channelz_channel != nullptr) {
if (*call->final_op.client.status != GRPC_STATUS_OK) {
channelz_channel->RecordCallFailed();
} else {
channelz_channel->RecordCallSucceeded();
}
}
} else {
get_final_status(call, set_cancelled_value,
call->final_op.server.cancelled, nullptr, nullptr);
}
// Record channelz data for the channel.
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(call->channel);
if (channelz_channel != nullptr) {
if (*call->final_op.client.status != GRPC_STATUS_OK) {
channelz_channel->RecordCallFailed();
} else {
channelz_channel->RecordCallSucceeded();
grpc_core::channelz::ServerNode* channelz_server =
grpc_server_get_channelz_node(call->server);
if (channelz_server != nullptr) {
if (*call->final_op.server.cancelled) {
channelz_server->RecordCallFailed();
} else {
channelz_server->RecordCallSucceeded();
}
}
}
GRPC_ERROR_UNREF(error);

@ -33,6 +33,7 @@ typedef void (*grpc_ioreq_completion_func)(grpc_call* call, int success,
typedef struct grpc_call_create_args {
grpc_channel* channel;
grpc_server* server;
grpc_call* parent;
uint32_t propagation_mask;

@ -166,10 +166,11 @@ grpc_channel* grpc_channel_create_with_builder(
}
grpc_channel_args_destroy(args);
if (channelz_enabled) {
bool is_top_level_channel = channel->is_client && !internal_channel;
// only track client channels since server channels are held in the
// grpc_server channel.
if (channelz_enabled && channel->is_client) {
channel->channelz_channel = channel_node_create_func(
channel, channel_tracer_max_nodes, is_top_level_channel);
channel, channel_tracer_max_nodes, !internal_channel);
channel->channelz_channel->AddTraceEvent(
grpc_core::channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string("Channel created"));

@ -219,6 +219,8 @@ struct grpc_server {
/** when did we print the last shutdown progress message */
gpr_timespec last_shutdown_message_time;
grpc_core::RefCountedPtr<grpc_core::channelz::ServerNode> channelz_server;
};
#define SERVER_FROM_CALL_ELEM(elem) \
@ -364,6 +366,7 @@ static void server_ref(grpc_server* server) {
static void server_delete(grpc_server* server) {
registered_method* rm;
size_t i;
server->channelz_server.reset();
grpc_channel_args_destroy(server->channel_args);
gpr_mu_destroy(&server->mu_global);
gpr_mu_destroy(&server->mu_call);
@ -779,6 +782,7 @@ static void accept_stream(void* cd, grpc_transport* transport,
args.channel = chand->channel;
args.server_transport_data = transport_server_data;
args.send_deadline = GRPC_MILLIS_INF_FUTURE;
args.server = chand->server;
grpc_call* call;
grpc_error* error = grpc_call_create(&args, &call);
grpc_call_element* elem =
@ -941,6 +945,7 @@ void grpc_server_register_completion_queue(grpc_server* server,
}
grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
grpc_core::ExecCtx exec_ctx;
GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
grpc_server* server =
@ -957,6 +962,20 @@ grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
server->channel_args = grpc_channel_args_copy(args);
const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_ENABLE_CHANNELZ);
if (grpc_channel_arg_get_bool(arg, false)) {
arg = grpc_channel_args_find(args,
GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE);
size_t trace_events_per_node =
grpc_channel_arg_get_integer(arg, {0, 0, INT_MAX});
server->channelz_server =
grpc_core::MakeRefCounted<grpc_core::channelz::ServerNode>(
trace_events_per_node);
server->channelz_server->AddTraceEvent(
grpc_core::channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string("Server created"));
}
return server;
}
@ -1459,3 +1478,8 @@ int grpc_server_has_open_connections(grpc_server* server) {
gpr_mu_unlock(&server->mu_global);
return r;
}
grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
grpc_server* server) {
return server->channelz_server.get();
}

@ -23,6 +23,7 @@
#include <grpc/grpc.h>
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/transport/transport.h"
@ -46,6 +47,9 @@ void grpc_server_setup_transport(grpc_server* server, grpc_transport* transport,
grpc_pollset* accepting_pollset,
const grpc_channel_args* args);
grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
grpc_server* server);
const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server);
int grpc_server_has_open_connections(grpc_server* server);

@ -31,6 +31,7 @@
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/json/json.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/test_config.h"
#include "test/cpp/util/channel_trace_proto_helper.h"
@ -102,6 +103,25 @@ void ValidateGetTopChannels(size_t expected_channels) {
gpr_free(core_api_json_str);
}
void ValidateGetServers(size_t expected_servers) {
char* json_str = ChannelzRegistry::GetServers(0);
grpc::testing::ValidateGetServersResponseProtoJsonTranslation(json_str);
grpc_json* parsed_json = grpc_json_parse_string(json_str);
// This check will naturally have to change when we support pagination.
// tracked: https://github.com/grpc/grpc/issues/16019.
ValidateJsonArraySize(parsed_json, "server", expected_servers);
grpc_json* end = GetJsonChild(parsed_json, "end");
ASSERT_NE(end, nullptr);
EXPECT_EQ(end->type, GRPC_JSON_TRUE);
grpc_json_destroy(parsed_json);
gpr_free(json_str);
// also check that the core API formats this correctly
char* core_api_json_str = grpc_channelz_get_servers(0);
grpc::testing::ValidateGetServersResponseProtoJsonTranslation(
core_api_json_str);
gpr_free(core_api_json_str);
}
class ChannelFixture {
public:
ChannelFixture(int max_trace_nodes = 0) {
@ -124,6 +144,27 @@ class ChannelFixture {
grpc_channel* channel_;
};
class ServerFixture {
public:
ServerFixture(int max_trace_nodes = 0) {
grpc_arg server_a[2];
server_a[0] = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE),
max_trace_nodes);
server_a[1] = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ), true);
grpc_channel_args server_args = {GPR_ARRAY_SIZE(server_a), server_a};
server_ = grpc_server_create(&server_args, nullptr);
}
~ServerFixture() { grpc_server_destroy(server_); }
grpc_server* server() { return server_; }
private:
grpc_server* server_;
};
struct validate_channel_data_args {
int64_t calls_started;
int64_t calls_failed;
@ -163,6 +204,13 @@ void ValidateChannel(ChannelNode* channel, validate_channel_data_args args) {
gpr_free(core_api_json_str);
}
void ValidateServer(ServerNode* server, validate_channel_data_args args) {
char* json_str = server->RenderJsonString();
grpc::testing::ValidateServerProtoJsonTranslation(json_str);
ValidateCounters(json_str, args);
gpr_free(json_str);
}
grpc_millis GetLastCallStartedMillis(CallCountingHelper* channel) {
CallCountingHelperPeer peer(channel);
return peer.last_call_started_millis();
@ -237,7 +285,7 @@ TEST_P(ChannelzChannelTest, LastCallStartedMillis) {
EXPECT_NE(millis1, millis4);
}
TEST(ChannelzGetTopChannelsTest, BasicTest) {
TEST(ChannelzGetTopChannelsTest, BasicGetTopChannelsTest) {
grpc_core::ExecCtx exec_ctx;
ChannelFixture channel;
ValidateGetTopChannels(1);
@ -273,9 +321,49 @@ TEST(ChannelzGetTopChannelsTest, InternalChannelTest) {
grpc_channel_destroy(internal_channel);
}
class ChannelzServerTest : public ::testing::TestWithParam<size_t> {};
TEST_P(ChannelzServerTest, BasicServerAPIFunctionality) {
grpc_core::ExecCtx exec_ctx;
ServerFixture server(10);
ServerNode* channelz_server = grpc_server_get_channelz_node(server.server());
channelz_server->RecordCallStarted();
channelz_server->RecordCallFailed();
channelz_server->RecordCallSucceeded();
ValidateServer(channelz_server, {1, 1, 1});
channelz_server->RecordCallStarted();
channelz_server->RecordCallFailed();
channelz_server->RecordCallSucceeded();
channelz_server->RecordCallStarted();
channelz_server->RecordCallFailed();
channelz_server->RecordCallSucceeded();
ValidateServer(channelz_server, {3, 3, 3});
}
TEST(ChannelzGetServersTest, BasicGetServersTest) {
grpc_core::ExecCtx exec_ctx;
ServerFixture server;
ValidateGetServers(1);
}
TEST(ChannelzGetServersTest, NoServersTest) {
grpc_core::ExecCtx exec_ctx;
ValidateGetServers(0);
}
TEST(ChannelzGetServersTest, ManyServersTest) {
grpc_core::ExecCtx exec_ctx;
ServerFixture servers[10];
(void)servers; // suppress unused variable error
ValidateGetServers(10);
}
INSTANTIATE_TEST_CASE_P(ChannelzChannelTestSweep, ChannelzChannelTest,
::testing::Values(0, 1, 2, 6, 10, 15));
INSTANTIATE_TEST_CASE_P(ChannelzServerTestSweep, ChannelzServerTest,
::testing::Values(0, 1, 2, 6, 10, 15));
} // namespace testing
} // namespace channelz
} // namespace grpc_core

@ -22,6 +22,7 @@
#include <string.h>
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
@ -198,17 +199,21 @@ static void run_one_request(grpc_end2end_test_config config,
static void test_channelz(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
grpc_arg client_a;
client_a.type = GRPC_ARG_INTEGER;
client_a.key = const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ);
client_a.value.integer = true;
grpc_channel_args client_args = {1, &client_a};
grpc_arg arg;
arg.type = GRPC_ARG_INTEGER;
arg.key = const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ);
arg.value.integer = true;
grpc_channel_args args = {1, &arg};
f = begin_test(config, "test_channelz", &client_args, nullptr);
f = begin_test(config, "test_channelz", &args, &args);
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(f.client);
GPR_ASSERT(channelz_channel != nullptr);
grpc_core::channelz::ServerNode* channelz_server =
grpc_server_get_channelz_node(f.server);
GPR_ASSERT(channelz_server != nullptr);
char* json = channelz_channel->RenderJsonString();
GPR_ASSERT(json != nullptr);
// nothing is present yet
@ -241,6 +246,18 @@ static void test_channelz(grpc_end2end_test_config config) {
GPR_ASSERT(nullptr == strstr(json, "\"severity\":\"CT_INFO\""));
gpr_free(json);
json = channelz_server->RenderJsonString();
GPR_ASSERT(json != nullptr);
gpr_log(GPR_INFO, "%s", json);
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"2\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"1\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"1\""));
// channel tracing is not enables, so these should not be preset.
GPR_ASSERT(nullptr == strstr(json, "\"trace\""));
GPR_ASSERT(nullptr == strstr(json, "\"description\":\"Channel created\""));
GPR_ASSERT(nullptr == strstr(json, "\"severity\":\"CT_INFO\""));
gpr_free(json);
end_test(&f);
config.tear_down_data(&f);
}
@ -248,22 +265,24 @@ static void test_channelz(grpc_end2end_test_config config) {
static void test_channelz_with_channel_trace(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
grpc_arg client_a[2];
client_a[0].type = GRPC_ARG_INTEGER;
client_a[0].key =
const_cast<char*>(GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE);
client_a[0].value.integer = 5;
client_a[1].type = GRPC_ARG_INTEGER;
client_a[1].key = const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ);
client_a[1].value.integer = true;
grpc_channel_args client_args = {GPR_ARRAY_SIZE(client_a), client_a};
f = begin_test(config, "test_channelz_with_channel_trace", &client_args,
nullptr);
grpc_arg arg[2];
arg[0].type = GRPC_ARG_INTEGER;
arg[0].key = const_cast<char*>(GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE);
arg[0].value.integer = 5;
arg[1].type = GRPC_ARG_INTEGER;
arg[1].key = const_cast<char*>(GRPC_ARG_ENABLE_CHANNELZ);
arg[1].value.integer = true;
grpc_channel_args args = {GPR_ARRAY_SIZE(arg), arg};
f = begin_test(config, "test_channelz_with_channel_trace", &args, &args);
grpc_core::channelz::ChannelNode* channelz_channel =
grpc_channel_get_channelz_node(f.client);
GPR_ASSERT(channelz_channel != nullptr);
grpc_core::channelz::ServerNode* channelz_server =
grpc_server_get_channelz_node(f.server);
GPR_ASSERT(channelz_server != nullptr);
char* json = channelz_channel->RenderJsonString();
GPR_ASSERT(json != nullptr);
gpr_log(GPR_INFO, "%s", json);
@ -272,6 +291,14 @@ static void test_channelz_with_channel_trace(grpc_end2end_test_config config) {
GPR_ASSERT(nullptr != strstr(json, "\"severity\":\"CT_INFO\""));
gpr_free(json);
json = channelz_server->RenderJsonString();
GPR_ASSERT(json != nullptr);
gpr_log(GPR_INFO, "%s", json);
GPR_ASSERT(nullptr != strstr(json, "\"trace\""));
GPR_ASSERT(nullptr != strstr(json, "\"description\":\"Server created\""));
GPR_ASSERT(nullptr != strstr(json, "\"severity\":\"CT_INFO\""));
gpr_free(json);
end_test(&f);
config.tear_down_data(&f);
}

@ -86,5 +86,14 @@ void ValidateSubchannelProtoJsonTranslation(char* json_c_str) {
VaidateProtoJsonTranslation<grpc::channelz::v1::Subchannel>(json_c_str);
}
void ValidateServerProtoJsonTranslation(char* json_c_str) {
VaidateProtoJsonTranslation<grpc::channelz::v1::Server>(json_c_str);
}
void ValidateGetServersResponseProtoJsonTranslation(char* json_c_str) {
VaidateProtoJsonTranslation<grpc::channelz::v1::GetServersResponse>(
json_c_str);
}
} // namespace testing
} // namespace grpc

@ -27,6 +27,8 @@ void ValidateChannelProtoJsonTranslation(char* json_c_str);
void ValidateGetTopChannelsResponseProtoJsonTranslation(char* json_c_str);
void ValidateGetChannelResponseProtoJsonTranslation(char* json_c_str);
void ValidateSubchannelProtoJsonTranslation(char* json_c_str);
void ValidateServerProtoJsonTranslation(char* json_c_str);
void ValidateGetServersResponseProtoJsonTranslation(char* json_c_str);
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save