Ensure subchannel channelz only created if enabled

reviewable/pr15980/r2
ncteisen 7 years ago
parent 9ff83ea77a
commit 1e6c0b46bc
  1. 16
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  2. 21
      src/core/ext/filters/client_channel/subchannel.cc
  3. 7
      src/core/ext/filters/client_channel/subchannel.h
  4. 8
      src/core/lib/channel/channelz.cc
  5. 18
      src/core/lib/channel/channelz.h

@ -328,8 +328,12 @@ void PickFirst::UpdateChildRefsLocked() {
if (subchannel_list_ != nullptr) {
for (size_t i = 0; i < subchannel_list_->num_subchannels(); ++i) {
if (subchannel_list_->subchannel(i)->subchannel() != nullptr) {
cs.push_back(grpc_subchannel_get_uuid(
subchannel_list_->subchannel(i)->subchannel()));
grpc_core::channelz::SubchannelNode* subchannel_node =
grpc_subchannel_get_channelz_node(
subchannel_list_->subchannel(i)->subchannel());
if (subchannel_node != nullptr) {
cs.push_back(subchannel_node->subchannel_uuid());
}
}
}
}
@ -338,8 +342,12 @@ void PickFirst::UpdateChildRefsLocked() {
++i) {
if (latest_pending_subchannel_list_->subchannel(i)->subchannel() !=
nullptr) {
cs.push_back(grpc_subchannel_get_uuid(
latest_pending_subchannel_list_->subchannel(i)->subchannel()));
grpc_core::channelz::SubchannelNode* subchannel_node =
grpc_subchannel_get_channelz_node(
latest_pending_subchannel_list_->subchannel(i)->subchannel());
if (subchannel_node != nullptr) {
cs.push_back(subchannel_node->subchannel_uuid());
}
}
}
}

@ -135,10 +135,8 @@ struct grpc_subchannel {
/** our alarm */
grpc_timer alarm;
/* the global uuid for this subchannel */
// TODO(ncteisen): move this into SubchannelNode while implementing
// GetSubchannel.
intptr_t subchannel_uuid;
grpc_core::RefCountedPtr<grpc_core::channelz::SubchannelNode>
channelz_subchannel;
};
struct grpc_subchannel_call {
@ -379,14 +377,21 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
c->backoff.Init(backoff_options);
gpr_mu_init(&c->mu);
// This is just a placeholder for now
c->subchannel_uuid = 42;
// This is just a placeholder channelz class for for now.
const grpc_arg* arg =
grpc_channel_args_find(c->args, GRPC_ARG_ENABLE_CHANNELZ);
bool channelz_enabled = grpc_channel_arg_get_bool(arg, false);
if (channelz_enabled) {
c->channelz_subchannel =
grpc_core::MakeRefCounted<grpc_core::channelz::SubchannelNode>();
}
return grpc_subchannel_index_register(key, c);
}
intptr_t grpc_subchannel_get_uuid(grpc_subchannel* s) {
return s->subchannel_uuid;
grpc_core::channelz::SubchannelNode* grpc_subchannel_get_channelz_node(
grpc_subchannel* s) {
return s->channelz_subchannel.get();
}
static void continue_connect_locked(grpc_subchannel* c) {

@ -71,6 +71,10 @@ typedef struct grpc_subchannel_key grpc_subchannel_key;
namespace grpc_core {
namespace channelz {
class SubchannelNode;
}
class ConnectedSubchannel : public RefCountedWithTracing<ConnectedSubchannel> {
public:
struct CallArgs {
@ -115,7 +119,8 @@ grpc_subchannel_call* grpc_subchannel_call_ref(
void grpc_subchannel_call_unref(
grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
intptr_t grpc_subchannel_get_uuid(grpc_subchannel* subchannel);
grpc_core::channelz::SubchannelNode* grpc_subchannel_get_channelz_node(
grpc_subchannel* subchannel);
/** Returns a pointer to the parent data associated with \a subchannel_call.
The data will be of the size specified in \a parent_data_size

@ -131,5 +131,13 @@ RefCountedPtr<ChannelNode> ChannelNode::MakeChannelNode(
channel, channel_tracer_max_nodes);
}
SubchannelNode::SubchannelNode() : subchannel_uuid_(-1) {
subchannel_uuid_ = ChannelzRegistry::Register(this);
}
SubchannelNode::~SubchannelNode() {
ChannelzRegistry::Unregister(subchannel_uuid_);
}
} // namespace channelz
} // namespace grpc_core

@ -95,6 +95,24 @@ class ChannelNode : public RefCounted<ChannelNode> {
ManualConstructor<ChannelTrace> trace_;
};
// Placeholds channelz class for subchannels. All this can do now is track its
// uuid (this information is needed by the parent channelz class). In the next
// PR I will build this out to support the GetSubchannel channelz request.
class SubchannelNode : public RefCounted<SubchannelNode> {
public:
SubchannelNode();
virtual ~SubchannelNode();
intptr_t subchannel_uuid() { return subchannel_uuid_; }
protected:
GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
private:
intptr_t subchannel_uuid_;
};
// Creation functions
typedef RefCountedPtr<ChannelNode> (*ChannelNodeCreationFunc)(grpc_channel*,

Loading…
Cancel
Save