aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-03-07 00:34:37 -0800
committerGravatar ncteisen <ncteisen@gmail.com>2018-03-07 00:34:37 -0800
commit09703ea30089464820dd56a07711f81a2d1e0f3c (patch)
tree9c0c473f4e23843ee9c2c9a6f7f21af4def449e1
parentbec1a61c26625364825dae396cc02a49926668c7 (diff)
Add severity
-rw-r--r--src/core/lib/channel/channel_trace.cc38
-rw-r--r--src/core/lib/channel/channel_trace.h22
-rw-r--r--src/core/lib/surface/channel.cc1
-rw-r--r--src/proto/grpc/channelz/channelz.proto2
-rw-r--r--test/core/channel/channel_trace_test.cc16
-rw-r--r--test/cpp/util/channel_trace_proto_helper.cc5
6 files changed, 58 insertions, 26 deletions
diff --git a/src/core/lib/channel/channel_trace.cc b/src/core/lib/channel/channel_trace.cc
index bbbf59cdf9..e0f495284f 100644
--- a/src/core/lib/channel/channel_trace.cc
+++ b/src/core/lib/channel/channel_trace.cc
@@ -41,17 +41,19 @@
namespace grpc_core {
ChannelTrace::TraceEvent::TraceEvent(
- grpc_slice data, RefCountedPtr<ChannelTrace> referenced_tracer,
- ReferencedType type)
- : data_(data),
+ Severity severity, grpc_slice data,
+ RefCountedPtr<ChannelTrace> referenced_tracer, ReferencedType type)
+ : severity_(severity),
+ data_(data),
timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(),
GPR_CLOCK_REALTIME)),
next_(nullptr),
referenced_tracer_(std::move(referenced_tracer)),
referenced_type_(type) {}
-ChannelTrace::TraceEvent::TraceEvent(grpc_slice data)
- : data_(data),
+ChannelTrace::TraceEvent::TraceEvent(Severity severity, grpc_slice data)
+ : severity_(severity),
+ data_(data),
timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(),
GPR_CLOCK_REALTIME)),
next_(nullptr) {}
@@ -107,25 +109,27 @@ void ChannelTrace::AddTraceEventHelper(TraceEvent* new_trace_event) {
}
}
-void ChannelTrace::AddTraceEventReferencingChannel(
- grpc_slice data, RefCountedPtr<ChannelTrace> referenced_tracer) {
+void ChannelTrace::AddTraceEvent(Severity severity, grpc_slice data) {
if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0
- // create and fill up the new event
- AddTraceEventHelper(
- New<TraceEvent>(data, std::move(referenced_tracer), Channel));
+ AddTraceEventHelper(New<TraceEvent>(severity, data));
}
-void ChannelTrace::AddTraceEventReferencingSubchannel(
- grpc_slice data, RefCountedPtr<ChannelTrace> referenced_tracer) {
+void ChannelTrace::AddTraceEventReferencingChannel(
+ Severity severity, grpc_slice data,
+ RefCountedPtr<ChannelTrace> referenced_tracer) {
if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0
// create and fill up the new event
AddTraceEventHelper(
- New<TraceEvent>(data, std::move(referenced_tracer), Subchannel));
+ New<TraceEvent>(severity, data, std::move(referenced_tracer), Channel));
}
-void ChannelTrace::AddTraceEvent(grpc_slice data) {
+void ChannelTrace::AddTraceEventReferencingSubchannel(
+ Severity severity, grpc_slice data,
+ RefCountedPtr<ChannelTrace> referenced_tracer) {
if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0
- AddTraceEventHelper(New<TraceEvent>(data));
+ // create and fill up the new event
+ AddTraceEventHelper(New<TraceEvent>(
+ severity, data, std::move(referenced_tracer), Subchannel));
}
namespace {
@@ -147,6 +151,10 @@ void ChannelTrace::TraceEvent::RenderTraceEvent(grpc_json* json) const {
json_iterator = grpc_json_create_child(json_iterator, json, "description",
grpc_slice_to_c_string(data_),
GRPC_JSON_STRING, true);
+ char* trace_level_str;
+ gpr_asprintf(&trace_level_str, "%d", static_cast<int32_t>(severity_));
+ json_iterator = grpc_json_create_child(
+ json_iterator, json, "severity", trace_level_str, GRPC_JSON_NUMBER, true);
json_iterator =
grpc_json_create_child(json_iterator, json, "timestamp",
fmt_time(timestamp_), GRPC_JSON_STRING, true);
diff --git a/src/core/lib/channel/channel_trace.h b/src/core/lib/channel/channel_trace.h
index 0c46ede600..7243096617 100644
--- a/src/core/lib/channel/channel_trace.h
+++ b/src/core/lib/channel/channel_trace.h
@@ -40,8 +40,15 @@ class ChannelTrace : public RefCounted<ChannelTrace> {
// returns the tracer's uuid
intptr_t GetUuid() const;
+ enum Severity {
+ Unset = 0, // never to be used
+ Info, // we start at 1 to avoid using proto default values
+ Warning,
+ Error
+ };
+
// Adds a new trace event to the tracing object
- void AddTraceEvent(grpc_slice data);
+ void AddTraceEvent(Severity severity, grpc_slice data);
// Adds a new trace event to the tracing object. This trace event refers to a
// an event on a child of the channel. For example, if this channel has
@@ -51,15 +58,18 @@ class ChannelTrace : public RefCounted<ChannelTrace> {
// TODO(ncteisen): Once channelz is implemented, the events should reference
// the overall channelz object, not just the ChannelTrace object.
void AddTraceEventReferencingChannel(
- grpc_slice data, RefCountedPtr<ChannelTrace> referenced_tracer);
+ Severity severity, grpc_slice data,
+ RefCountedPtr<ChannelTrace> referenced_tracer);
void AddTraceEventReferencingSubchannel(
- grpc_slice data, RefCountedPtr<ChannelTrace> referenced_tracer);
+ Severity severity, grpc_slice data,
+ RefCountedPtr<ChannelTrace> referenced_tracer);
// Returns the tracing data rendered as a grpc json string.
// The string is owned by the caller and must be freed.
char* RenderTrace() const;
private:
+ // Types of objects that can be references by trace events.
enum ReferencedType { Channel, Subchannel };
// Private class to encapsulate all the data and bookkeeping needed for a
// a trace event.
@@ -68,12 +78,13 @@ class ChannelTrace : public RefCounted<ChannelTrace> {
// Constructor for a TraceEvent that references a different channel.
// TODO(ncteisen): once channelz is implemented, this should reference the
// overall channelz object, not just the ChannelTrace object
- TraceEvent(grpc_slice data, RefCountedPtr<ChannelTrace> referenced_tracer,
+ TraceEvent(Severity severity, grpc_slice data,
+ RefCountedPtr<ChannelTrace> referenced_tracer,
ReferencedType type);
// Constructor for a TraceEvent that does not reverence a different
// channel.
- TraceEvent(grpc_slice data);
+ TraceEvent(Severity severity, grpc_slice data);
~TraceEvent();
@@ -86,6 +97,7 @@ class ChannelTrace : public RefCounted<ChannelTrace> {
void set_next(TraceEvent* next) { next_ = next; }
private:
+ Severity severity_;
grpc_slice data_;
gpr_timespec timestamp_;
TraceEvent* next_;
diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc
index 463e6121d0..cecc15b2df 100644
--- a/src/core/lib/surface/channel.cc
+++ b/src/core/lib/surface/channel.cc
@@ -184,6 +184,7 @@ grpc_channel* grpc_channel_create_with_builder(
channel->tracer = grpc_core::MakeRefCounted<grpc_core::ChannelTrace>(
channel_tracer_max_nodes);
channel->tracer->AddTraceEvent(
+ grpc_core::ChannelTrace::Severity::Info,
grpc_slice_from_static_string("Channel created"));
return channel;
}
diff --git a/src/proto/grpc/channelz/channelz.proto b/src/proto/grpc/channelz/channelz.proto
index 532ec7978f..851f301536 100644
--- a/src/proto/grpc/channelz/channelz.proto
+++ b/src/proto/grpc/channelz/channelz.proto
@@ -98,7 +98,7 @@ message ChannelTraceEvent {
// the severity of the trace event. Options are INFO, WARNING, and ERROR,
// which are represented by the values 1, 2, and 3, respectively. Any other
// value will be treated as ERROR.
- int32 trace_level = 2;
+ int32 severity = 2;
// When this event occurred.
google.protobuf.Timestamp timestamp = 3;
// ref of referenced channel or subchannel.
diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc
index 0c858005ca..471ebd6b58 100644
--- a/test/core/channel/channel_trace_test.cc
+++ b/test/core/channel/channel_trace_test.cc
@@ -73,7 +73,8 @@ void ValidateChannelTraceData(grpc_json* json,
}
void AddSimpleTrace(RefCountedPtr<ChannelTrace> tracer) {
- tracer->AddTraceEvent(grpc_slice_from_static_string("simple trace"));
+ tracer->AddTraceEvent(ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("simple trace"));
}
// checks for the existence of all the required members of the tracer.
@@ -113,8 +114,10 @@ TEST_P(ChannelTracerTest, BasicTest) {
AddSimpleTrace(tracer);
AddSimpleTrace(tracer);
ValidateTraceDataMatchedUuidLookup(tracer);
- tracer->AddTraceEvent(grpc_slice_from_static_string("trace three"));
- tracer->AddTraceEvent(grpc_slice_from_static_string("trace four"));
+ tracer->AddTraceEvent(ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("trace three"));
+ tracer->AddTraceEvent(ChannelTrace::Severity::Error,
+ grpc_slice_from_static_string("trace four error"));
ValidateChannelTrace(tracer, 4, GetParam());
AddSimpleTrace(tracer);
AddSimpleTrace(tracer);
@@ -138,6 +141,7 @@ TEST_P(ChannelTracerTest, ComplexTest) {
AddSimpleTrace(tracer);
RefCountedPtr<ChannelTrace> sc1 = MakeRefCounted<ChannelTrace>(GetParam());
tracer->AddTraceEventReferencingSubchannel(
+ ChannelTrace::Severity::Info,
grpc_slice_from_static_string("subchannel one created"), sc1);
ValidateChannelTrace(tracer, 3, GetParam());
AddSimpleTrace(sc1);
@@ -154,8 +158,10 @@ TEST_P(ChannelTracerTest, ComplexTest) {
ValidateTraceDataMatchedUuidLookup(tracer);
RefCountedPtr<ChannelTrace> sc2 = MakeRefCounted<ChannelTrace>(GetParam());
tracer->AddTraceEventReferencingChannel(
+ ChannelTrace::Severity::Info,
grpc_slice_from_static_string("LB channel two created"), sc2);
tracer->AddTraceEventReferencingSubchannel(
+ ChannelTrace::Severity::Warning,
grpc_slice_from_static_string("subchannel one inactive"), sc1);
ValidateChannelTrace(tracer, 7, GetParam());
AddSimpleTrace(tracer);
@@ -180,21 +186,25 @@ TEST_P(ChannelTracerTest, TestNesting) {
AddSimpleTrace(tracer);
RefCountedPtr<ChannelTrace> sc1 = MakeRefCounted<ChannelTrace>(GetParam());
tracer->AddTraceEventReferencingChannel(
+ ChannelTrace::Severity::Info,
grpc_slice_from_static_string("subchannel one created"), sc1);
AddSimpleTrace(sc1);
RefCountedPtr<ChannelTrace> conn1 = MakeRefCounted<ChannelTrace>(GetParam());
// nesting one level deeper.
sc1->AddTraceEventReferencingSubchannel(
+ ChannelTrace::Severity::Info,
grpc_slice_from_static_string("connection one created"), conn1);
AddSimpleTrace(conn1);
AddSimpleTrace(tracer);
AddSimpleTrace(tracer);
RefCountedPtr<ChannelTrace> sc2 = MakeRefCounted<ChannelTrace>(GetParam());
tracer->AddTraceEventReferencingSubchannel(
+ ChannelTrace::Severity::Info,
grpc_slice_from_static_string("subchannel two created"), sc2);
// this trace should not get added to the parents children since it is already
// present in the tracer.
tracer->AddTraceEventReferencingChannel(
+ ChannelTrace::Severity::Warning,
grpc_slice_from_static_string("subchannel one inactive"), sc1);
AddSimpleTrace(tracer);
tracer.reset(nullptr);
diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc
index be00dd1424..fbc9f1501c 100644
--- a/test/cpp/util/channel_trace_proto_helper.cc
+++ b/test/cpp/util/channel_trace_proto_helper.cc
@@ -22,6 +22,7 @@
#include <google/protobuf/util/json_util.h>
#include <grpc/grpc.h>
+#include <grpc/support/log.h>
#include <gtest/gtest.h>
#include "src/proto/grpc/channelz/channelz.pb.h"
@@ -32,14 +33,14 @@ namespace testing {
void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str) {
std::string tracer_json_str(tracer_json_c_str);
grpc::channelz::ChannelTrace channel_trace;
- google::protobuf::util::JsonParseOptions options;
+ google::protobuf::util::JsonParseOptions parse_options;
// If the following line is failing, then uncomment the last line of the
// comment, and uncomment the lines that print the two strings. You can
// then compare the output, and determine what fields are missing.
//
// options.ignore_unknown_fields = true;
ASSERT_EQ(google::protobuf::util::JsonStringToMessage(
- tracer_json_str, &channel_trace, options),
+ tracer_json_str, &channel_trace, parse_options),
google::protobuf::util::Status::OK);
std::string proto_json_str;
ASSERT_EQ(google::protobuf::util::MessageToJsonString(channel_trace,