|
|
|
@ -17,6 +17,7 @@ |
|
|
|
|
#include "src/cpp/ext/gcp/observability_logging_sink.h" |
|
|
|
|
|
|
|
|
|
#include "gmock/gmock.h" |
|
|
|
|
#include "google/protobuf/text_format.h" |
|
|
|
|
#include "gtest/gtest.h" |
|
|
|
|
|
|
|
|
|
#include "test/core/util/test_config.h" |
|
|
|
@ -294,6 +295,754 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigServerMultipleEventEntries) { |
|
|
|
|
EXPECT_EQ(sink.FindMatch(false, "foo/baz"), LoggingSink::Config(512, 2048)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(EntryToJsonStructTest, ClientHeader) { |
|
|
|
|
LoggingSink::Entry entry; |
|
|
|
|
entry.call_id = 1234; |
|
|
|
|
entry.sequence_id = 1; |
|
|
|
|
entry.type = LoggingSink::Entry::EventType::kClientHeader; |
|
|
|
|
entry.payload.metadata["key"] = "value"; |
|
|
|
|
entry.payload.timeout = grpc_core::Duration::Seconds(100); |
|
|
|
|
entry.payload_truncated = true; |
|
|
|
|
entry.peer.type = LoggingSink::Entry::Address::Type::kIpv4; |
|
|
|
|
entry.peer.address = "127.0.0.1"; |
|
|
|
|
entry.peer.ip_port = 12345; |
|
|
|
|
entry.authority = "authority"; |
|
|
|
|
entry.service_name = "service_name"; |
|
|
|
|
entry.method_name = "method_name"; |
|
|
|
|
|
|
|
|
|
google::protobuf::Struct proto; |
|
|
|
|
EntryToJsonStructProto(std::move(entry), &proto); |
|
|
|
|
std::string output; |
|
|
|
|
::google::protobuf::TextFormat::PrintToString(proto, &output); |
|
|
|
|
const char* pb_str = |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"authority\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"authority\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"callId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"1234\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"logger\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"LOGGER_UNKNOWN\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"methodName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"method_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"payload\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"metadata\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"key\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"value\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"timeout\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"100.000000000s\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"payloadTruncated\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" bool_value: true\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"peer\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"address\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"127.0.0.1\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"ipPort\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 12345\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"TYPE_IPV4\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"sequenceId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 1\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"serviceName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"service_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"CLIENT_HEADER\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n"; |
|
|
|
|
EXPECT_EQ(output, pb_str); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(EntryToJsonStructTest, ServerHeader) { |
|
|
|
|
LoggingSink::Entry entry; |
|
|
|
|
entry.call_id = 1234; |
|
|
|
|
entry.sequence_id = 2; |
|
|
|
|
entry.type = LoggingSink::Entry::EventType::kServerHeader; |
|
|
|
|
entry.logger = LoggingSink::Entry::Logger::kServer; |
|
|
|
|
entry.payload.metadata["key"] = "value"; |
|
|
|
|
entry.peer.type = LoggingSink::Entry::Address::Type::kIpv4; |
|
|
|
|
entry.peer.address = "127.0.0.1"; |
|
|
|
|
entry.peer.ip_port = 1234; |
|
|
|
|
entry.authority = "authority"; |
|
|
|
|
entry.service_name = "service_name"; |
|
|
|
|
entry.method_name = "method_name"; |
|
|
|
|
|
|
|
|
|
google::protobuf::Struct proto; |
|
|
|
|
EntryToJsonStructProto(std::move(entry), &proto); |
|
|
|
|
std::string output; |
|
|
|
|
::google::protobuf::TextFormat::PrintToString(proto, &output); |
|
|
|
|
const char* pb_str = |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"authority\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"authority\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"callId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"1234\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"logger\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"SERVER\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"methodName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"method_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"payload\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"metadata\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"key\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"value\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"peer\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"address\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"127.0.0.1\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"ipPort\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 1234\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"TYPE_IPV4\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"sequenceId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 2\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"serviceName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"service_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"SERVER_HEADER\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n"; |
|
|
|
|
EXPECT_EQ(output, pb_str); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(EntryToJsonStructTest, ClientMessage) { |
|
|
|
|
LoggingSink::Entry entry; |
|
|
|
|
entry.call_id = 1234; |
|
|
|
|
entry.sequence_id = 3; |
|
|
|
|
entry.type = LoggingSink::Entry::EventType::kClientMessage; |
|
|
|
|
entry.logger = LoggingSink::Entry::Logger::kClient; |
|
|
|
|
entry.payload.message = "hello"; |
|
|
|
|
entry.payload.message_length = 5; |
|
|
|
|
entry.peer.type = LoggingSink::Entry::Address::Type::kIpv4; |
|
|
|
|
entry.peer.address = "127.0.0.1"; |
|
|
|
|
entry.peer.ip_port = 1234; |
|
|
|
|
entry.authority = "authority"; |
|
|
|
|
entry.service_name = "service_name"; |
|
|
|
|
entry.method_name = "method_name"; |
|
|
|
|
|
|
|
|
|
google::protobuf::Struct proto; |
|
|
|
|
EntryToJsonStructProto(std::move(entry), &proto); |
|
|
|
|
std::string output; |
|
|
|
|
::google::protobuf::TextFormat::PrintToString(proto, &output); |
|
|
|
|
const char* pb_str = |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"authority\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"authority\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"callId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"1234\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"logger\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"CLIENT\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"methodName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"method_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"payload\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"message\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"hello\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"messageLength\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 5\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"peer\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"address\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"127.0.0.1\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"ipPort\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 1234\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"TYPE_IPV4\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"sequenceId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 3\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"serviceName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"service_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"CLIENT_MESSAGE\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n"; |
|
|
|
|
EXPECT_EQ(output, pb_str); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(EntryToJsonStructTest, ServerMessage) { |
|
|
|
|
LoggingSink::Entry entry; |
|
|
|
|
entry.call_id = 1234; |
|
|
|
|
entry.sequence_id = 4; |
|
|
|
|
entry.type = LoggingSink::Entry::EventType::kServerMessage; |
|
|
|
|
entry.logger = LoggingSink::Entry::Logger::kServer; |
|
|
|
|
entry.payload.message = "world"; |
|
|
|
|
entry.payload.message_length = 5; |
|
|
|
|
entry.peer.type = LoggingSink::Entry::Address::Type::kIpv4; |
|
|
|
|
entry.peer.address = "127.0.0.1"; |
|
|
|
|
entry.peer.ip_port = 12345; |
|
|
|
|
entry.authority = "authority"; |
|
|
|
|
entry.service_name = "service_name"; |
|
|
|
|
entry.method_name = "method_name"; |
|
|
|
|
|
|
|
|
|
google::protobuf::Struct proto; |
|
|
|
|
EntryToJsonStructProto(std::move(entry), &proto); |
|
|
|
|
std::string output; |
|
|
|
|
::google::protobuf::TextFormat::PrintToString(proto, &output); |
|
|
|
|
const char* pb_str = |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"authority\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"authority\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"callId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"1234\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"logger\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"SERVER\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"methodName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"method_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"payload\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"message\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"world\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"messageLength\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 5\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"peer\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"address\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"127.0.0.1\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"ipPort\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 12345\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"TYPE_IPV4\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"sequenceId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 4\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"serviceName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"service_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"SERVER_MESSAGE\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n"; |
|
|
|
|
EXPECT_EQ(output, pb_str); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(EntryToJsonStructTest, ClientHalfClose) { |
|
|
|
|
LoggingSink::Entry entry; |
|
|
|
|
entry.call_id = 1234; |
|
|
|
|
entry.sequence_id = 5; |
|
|
|
|
entry.type = LoggingSink::Entry::EventType::kClientHalfClose; |
|
|
|
|
entry.logger = LoggingSink::Entry::Logger::kClient; |
|
|
|
|
entry.peer.type = LoggingSink::Entry::Address::Type::kIpv4; |
|
|
|
|
entry.peer.address = "127.0.0.1"; |
|
|
|
|
entry.peer.ip_port = 1234; |
|
|
|
|
entry.authority = "authority"; |
|
|
|
|
entry.service_name = "service_name"; |
|
|
|
|
entry.method_name = "method_name"; |
|
|
|
|
|
|
|
|
|
google::protobuf::Struct proto; |
|
|
|
|
EntryToJsonStructProto(std::move(entry), &proto); |
|
|
|
|
std::string output; |
|
|
|
|
::google::protobuf::TextFormat::PrintToString(proto, &output); |
|
|
|
|
const char* pb_str = |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"authority\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"authority\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"callId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"1234\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"logger\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"CLIENT\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"methodName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"method_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"payload\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"peer\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"address\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"127.0.0.1\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"ipPort\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 1234\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"TYPE_IPV4\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"sequenceId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 5\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"serviceName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"service_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"CLIENT_HALF_CLOSE\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n"; |
|
|
|
|
EXPECT_EQ(output, pb_str); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(EntryToJsonStructTest, ServerTrailer) { |
|
|
|
|
LoggingSink::Entry entry; |
|
|
|
|
entry.call_id = 1234; |
|
|
|
|
entry.sequence_id = 6; |
|
|
|
|
entry.type = LoggingSink::Entry::EventType::kServerTrailer; |
|
|
|
|
entry.logger = LoggingSink::Entry::Logger::kServer; |
|
|
|
|
entry.payload.metadata["key"] = "value"; |
|
|
|
|
entry.peer.type = LoggingSink::Entry::Address::Type::kIpv4; |
|
|
|
|
entry.peer.address = "127.0.0.1"; |
|
|
|
|
entry.peer.ip_port = 1234; |
|
|
|
|
entry.authority = "authority"; |
|
|
|
|
entry.service_name = "service_name"; |
|
|
|
|
entry.method_name = "method_name"; |
|
|
|
|
|
|
|
|
|
google::protobuf::Struct proto; |
|
|
|
|
EntryToJsonStructProto(std::move(entry), &proto); |
|
|
|
|
std::string output; |
|
|
|
|
::google::protobuf::TextFormat::PrintToString(proto, &output); |
|
|
|
|
const char* pb_str = |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"authority\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"authority\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"callId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"1234\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"logger\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"SERVER\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"methodName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"method_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"payload\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"metadata\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"key\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"value\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"peer\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"address\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"127.0.0.1\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"ipPort\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 1234\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"TYPE_IPV4\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"sequenceId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 6\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"serviceName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"service_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"SERVER_TRAILER\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n"; |
|
|
|
|
EXPECT_EQ(output, pb_str); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(EntryToJsonStructTest, Cancel) { |
|
|
|
|
LoggingSink::Entry entry; |
|
|
|
|
entry.call_id = 1234; |
|
|
|
|
entry.sequence_id = 7; |
|
|
|
|
entry.type = LoggingSink::Entry::EventType::kCancel; |
|
|
|
|
entry.logger = LoggingSink::Entry::Logger::kClient; |
|
|
|
|
entry.peer.type = LoggingSink::Entry::Address::Type::kIpv4; |
|
|
|
|
entry.peer.address = "127.0.0.1"; |
|
|
|
|
entry.peer.ip_port = 1234; |
|
|
|
|
entry.authority = "authority"; |
|
|
|
|
entry.service_name = "service_name"; |
|
|
|
|
entry.method_name = "method_name"; |
|
|
|
|
|
|
|
|
|
google::protobuf::Struct proto; |
|
|
|
|
EntryToJsonStructProto(std::move(entry), &proto); |
|
|
|
|
std::string output; |
|
|
|
|
::google::protobuf::TextFormat::PrintToString(proto, &output); |
|
|
|
|
const char* pb_str = |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"authority\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"authority\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"callId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"1234\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"logger\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"CLIENT\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"methodName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"method_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"payload\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"peer\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" struct_value {\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"address\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"127.0.0.1\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"ipPort\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 1234\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"TYPE_IPV4\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"sequenceId\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" number_value: 7\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"serviceName\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"service_name\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n" |
|
|
|
|
"fields {\n" |
|
|
|
|
" key: \"type\"\n" |
|
|
|
|
" value {\n" |
|
|
|
|
" string_value: \"CANCEL\"\n" |
|
|
|
|
" }\n" |
|
|
|
|
"}\n"; |
|
|
|
|
EXPECT_EQ(output, pb_str); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|