From 230035180fef721ae80ce7c35b574938040f4f80 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 29 Jun 2018 12:00:15 -0700 Subject: Change pattern to have subtype do json population --- .../filters/client_channel/client_channel_channelz.cc | 16 +++++++++++----- .../filters/client_channel/client_channel_channelz.h | 2 +- src/core/lib/channel/channelz.cc | 19 +++---------------- src/core/lib/channel/channelz.h | 10 ++++------ 4 files changed, 19 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.cc b/src/core/ext/filters/client_channel/client_channel_channelz.cc index df78dd5932..c9bdce1604 100644 --- a/src/core/ext/filters/client_channel/client_channel_channelz.cc +++ b/src/core/ext/filters/client_channel/client_channel_channelz.cc @@ -20,6 +20,7 @@ #include "src/core/ext/filters/client_channel/client_channel_channelz.h" #include "src/core/lib/gpr/useful.h" +#include "src/core/lib/transport/connectivity_state.h" namespace grpc_core { namespace channelz { @@ -36,13 +37,18 @@ static const grpc_arg_pointer_vtable client_channel_channelz_vtable = { client_channel_channelz_copy, client_channel_channelz_destroy, client_channel_channelz_cmp}; -bool ClientChannelNode::GetConnectivityState(grpc_connectivity_state* state) { - if (channel()) { - *state = grpc_channel_check_connectivity_state(channel(), false); +void ClientChannelNode::PopulateConnectivityState(grpc_json* json) { + grpc_connectivity_state state; + if (channel() != nullptr) { + state = grpc_channel_check_connectivity_state(channel(), false); } else { - *state = GRPC_CHANNEL_SHUTDOWN; + state = GRPC_CHANNEL_SHUTDOWN; } - return true; + json = grpc_json_create_child(nullptr, json, "state", nullptr, + GRPC_JSON_OBJECT, false); + grpc_json_create_child(nullptr, json, "state", + grpc_connectivity_state_name(state), GRPC_JSON_STRING, + false); } grpc_arg ClientChannelNode::CreateArg() { diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.h b/src/core/ext/filters/client_channel/client_channel_channelz.h index 7d05cda7da..d339b4e9f6 100644 --- a/src/core/ext/filters/client_channel/client_channel_channelz.h +++ b/src/core/ext/filters/client_channel/client_channel_channelz.h @@ -37,7 +37,7 @@ class ClientChannelNode : public ChannelNode { // Override this functionality since client_channels have a notion of // channel connectivity. - bool GetConnectivityState(grpc_connectivity_state* state) override; + void PopulateConnectivityState(grpc_json* json) override; // Helper to create a channel arg to ensure this type of ChannelNode is // created. diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index 62bc4d4330..0f13551c2a 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -36,7 +36,6 @@ #include "src/core/lib/iomgr/error.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/channel.h" -#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/error_utils.h" namespace grpc_core { @@ -109,9 +108,7 @@ void ChannelNode::RecordCallStarted() { (gpr_atm)ExecCtx::Get()->Now()); } -bool ChannelNode::GetConnectivityState(grpc_connectivity_state* state) { - return false; -} +void ChannelNode::PopulateConnectivityState(grpc_json* json) {} char* ChannelNode::RenderJSON() { // We need to track these three json objects to build our object @@ -132,18 +129,8 @@ char* ChannelNode::RenderJSON() { GRPC_JSON_OBJECT, false); json = data; json_iterator = nullptr; - // create and fill the connectivity state child. - grpc_connectivity_state connectivity_state; - if (GetConnectivityState(&connectivity_state)) { - json_iterator = grpc_json_create_child(json_iterator, json, "state", - nullptr, GRPC_JSON_OBJECT, false); - json = json_iterator; - grpc_json_create_child(nullptr, json, "state", - grpc_connectivity_state_name(connectivity_state), - GRPC_JSON_STRING, false); - // reset the parent to be the data object. - json = data; - } + + PopulateConnectivityState(json); json_iterator = grpc_json_create_child( json_iterator, json, "target", target_.get(), GRPC_JSON_STRING, false); // fill in the channel trace if applicable diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h index 5c91658dd1..fc972bf802 100644 --- a/src/core/lib/channel/channelz.h +++ b/src/core/lib/channel/channelz.h @@ -57,12 +57,10 @@ class ChannelNode : public RefCounted { char* RenderJSON(); - // helper for getting connectivity state. It is virtual because it allows - // the client_channel code to live in ext/ instead of lib/ - // - // returns true if the channel has a notion of a connectivity state. In that - // case it also sets state to the correct connectivity state. - virtual bool GetConnectivityState(grpc_connectivity_state* state); + // helper for getting and populating connectivity state. It is virtual + // because it allows the client_channel specific code to live in ext/ + // instead of lib/ + virtual void PopulateConnectivityState(grpc_json* json); ChannelTrace* trace() { return trace_.get(); } -- cgit v1.2.3