reviewer feedback

reviewable/pr16055/r9
ncteisen 6 years ago
parent d030114058
commit e888e93293
  1. 9
      src/core/ext/filters/client_channel/client_channel_channelz.h
  2. 4
      src/core/ext/filters/client_channel/subchannel.cc
  3. 16
      src/core/lib/channel/channelz.h
  4. 4
      src/core/lib/surface/channel.cc
  5. 38
      test/core/channel/channel_trace_test.cc

@ -77,7 +77,14 @@ class SubchannelNode : public BaseNode {
grpc_json* RenderJson() override; grpc_json* RenderJson() override;
// proxy methods to composed classes. // proxy methods to composed classes.
ChannelTrace* trace() { return trace_.get(); } 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, referenced_channel);
}
void RecordCallStarted() { call_counter_.RecordCallStarted(); } void RecordCallStarted() { call_counter_.RecordCallStarted(); }
void RecordCallFailed() { call_counter_.RecordCallFailed(); } void RecordCallFailed() { call_counter_.RecordCallFailed(); }
void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); } void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }

@ -183,7 +183,7 @@ static void connection_destroy(void* arg, grpc_error* error) {
static void subchannel_destroy(void* arg, grpc_error* error) { static void subchannel_destroy(void* arg, grpc_error* error) {
grpc_subchannel* c = static_cast<grpc_subchannel*>(arg); grpc_subchannel* c = static_cast<grpc_subchannel*>(arg);
if (c->channelz_subchannel != nullptr) { if (c->channelz_subchannel != nullptr) {
c->channelz_subchannel->trace()->AddTraceEvent( c->channelz_subchannel->AddTraceEvent(
grpc_core::channelz::ChannelTrace::Severity::Info, grpc_core::channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string("Subchannel destroyed")); grpc_slice_from_static_string("Subchannel destroyed"));
c->channelz_subchannel->MarkSubchannelDestroyed(); c->channelz_subchannel->MarkSubchannelDestroyed();
@ -397,7 +397,7 @@ grpc_subchannel* grpc_subchannel_create(grpc_connector* connector,
c->channelz_subchannel = c->channelz_subchannel =
grpc_core::MakeRefCounted<grpc_core::channelz::SubchannelNode>( grpc_core::MakeRefCounted<grpc_core::channelz::SubchannelNode>(
c, channel_tracer_max_nodes); c, channel_tracer_max_nodes);
c->channelz_subchannel->trace()->AddTraceEvent( c->channelz_subchannel->AddTraceEvent(
grpc_core::channelz::ChannelTrace::Severity::Info, grpc_core::channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string("Subchannel created")); grpc_slice_from_static_string("Subchannel created"));
} }

@ -44,7 +44,8 @@ namespace channelz {
namespace testing { namespace testing {
class CallCountingHelperPeer; class CallCountingHelperPeer;
} class ChannelNodePeer;
} // namespace testing
// base class for all channelz entities // base class for all channelz entities
class BaseNode : public RefCounted<BaseNode> { class BaseNode : public RefCounted<BaseNode> {
@ -131,7 +132,14 @@ class ChannelNode : public BaseNode {
bool ChannelIsDestroyed() { return channel_ == nullptr; } bool ChannelIsDestroyed() { return channel_ == nullptr; }
// proxy methods to composed classes. // proxy methods to composed classes.
ChannelTrace* trace() { return trace_.get(); } 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, referenced_channel);
}
void RecordCallStarted() { call_counter_.RecordCallStarted(); } void RecordCallStarted() { call_counter_.RecordCallStarted(); }
void RecordCallFailed() { call_counter_.RecordCallFailed(); } void RecordCallFailed() { call_counter_.RecordCallFailed(); }
void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); } void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
@ -141,8 +149,12 @@ class ChannelNode : public BaseNode {
char* target_view() { return target_.get(); } char* target_view() { return target_.get(); }
// provides access to call_counter_ for child. // provides access to call_counter_ for child.
CallCountingHelper* call_counter() { return &call_counter_; } CallCountingHelper* call_counter() { return &call_counter_; }
// provides access to channel trace for child.
ChannelTrace* trace() { return trace_.get(); }
private: private:
// to allow the channel trace test to access trace();
friend class testing::ChannelNodePeer;
grpc_channel* channel_ = nullptr; grpc_channel* channel_ = nullptr;
UniquePtr<char> target_; UniquePtr<char> target_;
CallCountingHelper call_counter_; CallCountingHelper call_counter_;

@ -170,7 +170,7 @@ grpc_channel* grpc_channel_create_with_builder(
bool is_top_level_channel = channel->is_client && !internal_channel; bool is_top_level_channel = channel->is_client && !internal_channel;
channel->channelz_channel = channel_node_create_func( channel->channelz_channel = channel_node_create_func(
channel, channel_tracer_max_nodes, is_top_level_channel); channel, channel_tracer_max_nodes, is_top_level_channel);
channel->channelz_channel->trace()->AddTraceEvent( channel->channelz_channel->AddTraceEvent(
grpc_core::channelz::ChannelTrace::Severity::Info, grpc_core::channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string("Channel created")); grpc_slice_from_static_string("Channel created"));
} }
@ -417,7 +417,7 @@ void grpc_channel_internal_unref(grpc_channel* c REF_ARG) {
static void destroy_channel(void* arg, grpc_error* error) { static void destroy_channel(void* arg, grpc_error* error) {
grpc_channel* channel = static_cast<grpc_channel*>(arg); grpc_channel* channel = static_cast<grpc_channel*>(arg);
if (channel->channelz_channel != nullptr) { if (channel->channelz_channel != nullptr) {
channel->channelz_channel->trace()->AddTraceEvent( channel->channelz_channel->AddTraceEvent(
grpc_core::channelz::ChannelTrace::Severity::Info, grpc_core::channelz::ChannelTrace::Severity::Info,
grpc_slice_from_static_string("Channel destroyed")); grpc_slice_from_static_string("Channel destroyed"));
channel->channelz_channel->MarkChannelDestroyed(); channel->channelz_channel->MarkChannelDestroyed();

@ -40,6 +40,17 @@
namespace grpc_core { namespace grpc_core {
namespace channelz { namespace channelz {
namespace testing { namespace testing {
// testing peer to access channel internals
class ChannelNodePeer {
public:
ChannelNodePeer(ChannelNode* node) : node_(node) {}
ChannelTrace* trace() { return node_->trace_.get(); }
private:
ChannelNode* node_;
};
namespace { namespace {
grpc_json* GetJsonChild(grpc_json* parent, const char* key) { grpc_json* GetJsonChild(grpc_json* parent, const char* key) {
@ -156,18 +167,19 @@ TEST_P(ChannelTracerTest, ComplexTest) {
ChannelFixture channel1(GetParam()); ChannelFixture channel1(GetParam());
RefCountedPtr<ChannelNode> sc1 = RefCountedPtr<ChannelNode> sc1 =
MakeRefCounted<ChannelNode>(channel1.channel(), GetParam(), true); MakeRefCounted<ChannelNode>(channel1.channel(), GetParam(), true);
ChannelNodePeer sc1_peer(sc1.get());
tracer.AddTraceEventWithReference( tracer.AddTraceEventWithReference(
ChannelTrace::Severity::Info, ChannelTrace::Severity::Info,
grpc_slice_from_static_string("subchannel one created"), sc1); grpc_slice_from_static_string("subchannel one created"), sc1);
ValidateChannelTrace(&tracer, 3, GetParam()); ValidateChannelTrace(&tracer, 3, GetParam());
AddSimpleTrace(sc1->trace()); AddSimpleTrace(sc1_peer.trace());
AddSimpleTrace(sc1->trace()); AddSimpleTrace(sc1_peer.trace());
AddSimpleTrace(sc1->trace()); AddSimpleTrace(sc1_peer.trace());
ValidateChannelTrace(sc1->trace(), 3, GetParam()); ValidateChannelTrace(sc1_peer.trace(), 3, GetParam());
AddSimpleTrace(sc1->trace()); AddSimpleTrace(sc1_peer.trace());
AddSimpleTrace(sc1->trace()); AddSimpleTrace(sc1_peer.trace());
AddSimpleTrace(sc1->trace()); AddSimpleTrace(sc1_peer.trace());
ValidateChannelTrace(sc1->trace(), 6, GetParam()); ValidateChannelTrace(sc1_peer.trace(), 6, GetParam());
AddSimpleTrace(&tracer); AddSimpleTrace(&tracer);
AddSimpleTrace(&tracer); AddSimpleTrace(&tracer);
ValidateChannelTrace(&tracer, 5, GetParam()); ValidateChannelTrace(&tracer, 5, GetParam());
@ -203,24 +215,26 @@ TEST_P(ChannelTracerTest, TestNesting) {
ChannelFixture channel1(GetParam()); ChannelFixture channel1(GetParam());
RefCountedPtr<ChannelNode> sc1 = RefCountedPtr<ChannelNode> sc1 =
MakeRefCounted<ChannelNode>(channel1.channel(), GetParam(), true); MakeRefCounted<ChannelNode>(channel1.channel(), GetParam(), true);
ChannelNodePeer sc1_peer(sc1.get());
tracer.AddTraceEventWithReference( tracer.AddTraceEventWithReference(
ChannelTrace::Severity::Info, ChannelTrace::Severity::Info,
grpc_slice_from_static_string("subchannel one created"), sc1); grpc_slice_from_static_string("subchannel one created"), sc1);
ValidateChannelTrace(&tracer, 3, GetParam()); ValidateChannelTrace(&tracer, 3, GetParam());
AddSimpleTrace(sc1->trace()); AddSimpleTrace(sc1_peer.trace());
ChannelFixture channel2(GetParam()); ChannelFixture channel2(GetParam());
RefCountedPtr<ChannelNode> conn1 = RefCountedPtr<ChannelNode> conn1 =
MakeRefCounted<ChannelNode>(channel2.channel(), GetParam(), true); MakeRefCounted<ChannelNode>(channel2.channel(), GetParam(), true);
ChannelNodePeer conn1_peer(conn1.get());
// nesting one level deeper. // nesting one level deeper.
sc1->trace()->AddTraceEventWithReference( sc1_peer.trace()->AddTraceEventWithReference(
ChannelTrace::Severity::Info, ChannelTrace::Severity::Info,
grpc_slice_from_static_string("connection one created"), conn1); grpc_slice_from_static_string("connection one created"), conn1);
ValidateChannelTrace(&tracer, 3, GetParam()); ValidateChannelTrace(&tracer, 3, GetParam());
AddSimpleTrace(conn1->trace()); AddSimpleTrace(conn1_peer.trace());
AddSimpleTrace(&tracer); AddSimpleTrace(&tracer);
AddSimpleTrace(&tracer); AddSimpleTrace(&tracer);
ValidateChannelTrace(&tracer, 5, GetParam()); ValidateChannelTrace(&tracer, 5, GetParam());
ValidateChannelTrace(conn1->trace(), 1, GetParam()); ValidateChannelTrace(conn1_peer.trace(), 1, GetParam());
ChannelFixture channel3(GetParam()); ChannelFixture channel3(GetParam());
RefCountedPtr<ChannelNode> sc2 = RefCountedPtr<ChannelNode> sc2 =
MakeRefCounted<ChannelNode>(channel3.channel(), GetParam(), true); MakeRefCounted<ChannelNode>(channel3.channel(), GetParam(), true);

Loading…
Cancel
Save