reviewable/pr15343/r7
Noah Eisen 7 years ago
parent d23739eda3
commit ea424b88fa
  1. 1
      src/core/lib/channel/channel_trace.h
  2. 21
      src/core/lib/channel/channelz.cc
  3. 2
      src/core/lib/channel/channelz.h
  4. 4
      src/core/lib/surface/call.cc
  5. 8
      test/core/channel/channelz_test.cc
  6. 6
      test/core/end2end/tests/simple_request.cc

@ -27,7 +27,6 @@
#include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/error.h"
#include "src/core/lib/json/json.h" #include "src/core/lib/json/json.h"
namespace grpc_core { namespace grpc_core {
namespace channelz { namespace channelz {

@ -90,9 +90,12 @@ grpc_json* add_num_str(grpc_json* parent, grpc_json* it, const char* name,
} // namespace } // namespace
Channel::Channel(grpc_channel* channel, size_t channel_tracer_max_nodes) Channel::Channel(grpc_channel* channel, size_t channel_tracer_max_nodes)
: channel_(channel), target_(UniquePtr<char>(grpc_channel_get_target(channel_))), channel_uuid_(ChannelzRegistry::Register(this)) { : channel_(channel),
target_(UniquePtr<char>(grpc_channel_get_target(channel_))),
channel_uuid_(ChannelzRegistry::Register(this)) {
trace_.Init(channel_tracer_max_nodes); trace_.Init(channel_tracer_max_nodes);
gpr_atm_no_barrier_store(&last_call_started_millis_, (gpr_atm)ExecCtx::Get()->Now()); gpr_atm_no_barrier_store(&last_call_started_millis_,
(gpr_atm)ExecCtx::Get()->Now());
} }
Channel::~Channel() { Channel::~Channel() {
@ -102,7 +105,8 @@ Channel::~Channel() {
void Channel::RecordCallStarted() { void Channel::RecordCallStarted() {
gpr_atm_no_barrier_fetch_add(&calls_started_, (gpr_atm)1); gpr_atm_no_barrier_fetch_add(&calls_started_, (gpr_atm)1);
gpr_atm_no_barrier_store(&last_call_started_millis_, (gpr_atm)ExecCtx::Get()->Now()); gpr_atm_no_barrier_store(&last_call_started_millis_,
(gpr_atm)ExecCtx::Get()->Now());
} }
grpc_connectivity_state Channel::GetConnectivityState() { grpc_connectivity_state Channel::GetConnectivityState() {
@ -142,8 +146,8 @@ char* Channel::RenderJSON() {
GRPC_JSON_STRING, false); GRPC_JSON_STRING, false);
// reset the parent to be the data object. // reset the parent to be the data object.
json = data; json = data;
json_iterator = grpc_json_create_child(json_iterator, json, "target", target_.get(), json_iterator = grpc_json_create_child(
GRPC_JSON_STRING, false); json_iterator, json, "target", target_.get(), GRPC_JSON_STRING, false);
// fill in the channel trace if applicable // fill in the channel trace if applicable
grpc_json* trace = trace_->RenderJSON(); grpc_json* trace = trace_->RenderJSON();
if (trace != nullptr) { if (trace != nullptr) {
@ -166,9 +170,10 @@ char* Channel::RenderJSON() {
calls_succeeded_ ? calls_succeeded_ : -1); calls_succeeded_ ? calls_succeeded_ : -1);
json_iterator = add_num_str(json, json_iterator, "callsFailed", json_iterator = add_num_str(json, json_iterator, "callsFailed",
calls_failed_ ? calls_failed_ : -1); calls_failed_ ? calls_failed_ : -1);
gpr_timespec ts = grpc_millis_to_timespec(last_call_started_millis_, GPR_CLOCK_REALTIME); gpr_timespec ts =
json_iterator = grpc_json_create_child( grpc_millis_to_timespec(last_call_started_millis_, GPR_CLOCK_REALTIME);
json_iterator, json, "lastCallStartedTimestamp", json_iterator =
grpc_json_create_child(json_iterator, json, "lastCallStartedTimestamp",
fmt_time(ts), GRPC_JSON_STRING, true); fmt_time(ts), GRPC_JSON_STRING, true);
// render and return the over json object // render and return the over json object
char* json_str = grpc_json_dump_to_string(top_level_json, 0); char* json_str = grpc_json_dump_to_string(top_level_json, 0);

@ -35,7 +35,7 @@ namespace grpc_core {
namespace channelz { namespace channelz {
namespace testing { namespace testing {
class ChannelPeer; class ChannelPeer;
} }
class Channel : public RefCounted<Channel> { class Channel : public RefCounted<Channel> {

@ -1262,7 +1262,8 @@ static void post_batch_completion(batch_control* bctl) {
} }
if (call->channel != nullptr) { if (call->channel != nullptr) {
grpc_core::channelz::Channel* channelz_channel = grpc_channel_get_channelz_channel_node(call->channel); grpc_core::channelz::Channel* channelz_channel =
grpc_channel_get_channelz_channel_node(call->channel);
if (*call->final_op.client.status != GRPC_STATUS_OK) { if (*call->final_op.client.status != GRPC_STATUS_OK) {
channelz_channel->RecordCallFailed(); channelz_channel->RecordCallFailed();
} else { } else {
@ -1270,7 +1271,6 @@ static void post_batch_completion(batch_control* bctl) {
} }
} }
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
error = GRPC_ERROR_NONE; error = GRPC_ERROR_NONE;
} }

@ -46,8 +46,12 @@ namespace testing {
// testing peer to access channel internals // testing peer to access channel internals
class ChannelPeer { class ChannelPeer {
public: public:
ChannelPeer (Channel* channel) : channel_(channel) {} ChannelPeer(Channel* channel) : channel_(channel) {}
grpc_millis last_call_started_millis() { return (grpc_millis)gpr_atm_no_barrier_load(&channel_->last_call_started_millis_); } grpc_millis last_call_started_millis() {
return (grpc_millis)gpr_atm_no_barrier_load(
&channel_->last_call_started_millis_);
}
private: private:
Channel* channel_; Channel* channel_;
}; };

@ -258,7 +258,8 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
// The following is a quick sanity check on channelz functionality. It // The following is a quick sanity check on channelz functionality. It
// ensures that core properly tracked the one call that occurred in this // ensures that core properly tracked the one call that occurred in this
// simple end2end test. // simple end2end test.
grpc_core::channelz::Channel* channelz_channel = grpc_channel_get_channelz_channel_node(f.client); grpc_core::channelz::Channel* channelz_channel =
grpc_channel_get_channelz_channel_node(f.client);
char* json = channelz_channel->RenderJSON(); char* json = channelz_channel->RenderJSON();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"1\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"1\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"1\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"1\""));
@ -280,7 +281,8 @@ static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
// The following is a quick sanity check on channelz functionality. It // The following is a quick sanity check on channelz functionality. It
// ensures that core properly tracked the ten calls that occurred. // ensures that core properly tracked the ten calls that occurred.
grpc_core::channelz::Channel* channelz_channel = grpc_channel_get_channelz_channel_node(f.client); grpc_core::channelz::Channel* channelz_channel =
grpc_channel_get_channelz_channel_node(f.client);
char* json = channelz_channel->RenderJSON(); char* json = channelz_channel->RenderJSON();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"10\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"10\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"10\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"10\""));

Loading…
Cancel
Save