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/json/json.h"
namespace grpc_core {
namespace channelz {

@ -90,9 +90,12 @@ grpc_json* add_num_str(grpc_json* parent, grpc_json* it, const char* name,
} // namespace
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);
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() {
@ -102,7 +105,8 @@ Channel::~Channel() {
void Channel::RecordCallStarted() {
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() {
@ -142,8 +146,8 @@ char* Channel::RenderJSON() {
GRPC_JSON_STRING, false);
// reset the parent to be the data object.
json = data;
json_iterator = grpc_json_create_child(json_iterator, json, "target", target_.get(),
GRPC_JSON_STRING, false);
json_iterator = grpc_json_create_child(
json_iterator, json, "target", target_.get(), GRPC_JSON_STRING, false);
// fill in the channel trace if applicable
grpc_json* trace = trace_->RenderJSON();
if (trace != nullptr) {
@ -166,9 +170,10 @@ char* Channel::RenderJSON() {
calls_succeeded_ ? calls_succeeded_ : -1);
json_iterator = add_num_str(json, json_iterator, "callsFailed",
calls_failed_ ? calls_failed_ : -1);
gpr_timespec ts = grpc_millis_to_timespec(last_call_started_millis_, GPR_CLOCK_REALTIME);
json_iterator = grpc_json_create_child(
json_iterator, json, "lastCallStartedTimestamp",
gpr_timespec ts =
grpc_millis_to_timespec(last_call_started_millis_, GPR_CLOCK_REALTIME);
json_iterator =
grpc_json_create_child(json_iterator, json, "lastCallStartedTimestamp",
fmt_time(ts), GRPC_JSON_STRING, true);
// render and return the over json object
char* json_str = grpc_json_dump_to_string(top_level_json, 0);

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

@ -1262,7 +1262,8 @@ static void post_batch_completion(batch_control* bctl) {
}
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) {
channelz_channel->RecordCallFailed();
} else {
@ -1270,7 +1271,6 @@ static void post_batch_completion(batch_control* bctl) {
}
}
GRPC_ERROR_UNREF(error);
error = GRPC_ERROR_NONE;
}

@ -46,8 +46,12 @@ namespace testing {
// testing peer to access channel internals
class ChannelPeer {
public:
ChannelPeer (Channel* channel) : channel_(channel) {}
grpc_millis last_call_started_millis() { return (grpc_millis)gpr_atm_no_barrier_load(&channel_->last_call_started_millis_); }
ChannelPeer(Channel* channel) : channel_(channel) {}
grpc_millis last_call_started_millis() {
return (grpc_millis)gpr_atm_no_barrier_load(
&channel_->last_call_started_millis_);
}
private:
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
// ensures that core properly tracked the one call that occurred in this
// 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();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"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
// 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();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"10\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"10\""));

Loading…
Cancel
Save