Revert "Observability Logging: Interfaces and structure (#31651)" (#31669)

This reverts commit 2146107e25.
pull/31204/head^2
Craig Tiller 2 years ago committed by GitHub
parent 2146107e25
commit 3be177223e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      bazel/grpc_deps.bzl
  2. 1
      src/cpp/ext/filters/logging/BUILD
  3. 49
      src/cpp/ext/filters/logging/logging_sink.h
  4. 5
      src/cpp/ext/gcp/BUILD
  5. 61
      src/cpp/ext/gcp/observability_logging_sink.cc
  6. 18
      src/cpp/ext/gcp/observability_logging_sink.h
  7. 20
      test/cpp/ext/gcp/observability_logging_sink_test.cc

@ -200,11 +200,6 @@ def grpc_deps():
actual = "@com_google_googleapis//google/monitoring/v3:monitoring_cc_grpc",
)
native.bind(
name = "googleapis_logging_grpc_service",
actual = "@com_google_googleapis//google/logging/v2:logging_cc_grpc",
)
if "boringssl" not in native.existing_rules():
http_archive(
name = "boringssl",

@ -35,7 +35,6 @@ grpc_cc_library(
],
external_deps = [
"absl/strings",
"absl/time",
],
language = "c++",
visibility = [

@ -23,11 +23,7 @@
#include <stdint.h>
#include <map>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
namespace grpc {
namespace internal {
@ -56,54 +52,9 @@ class LoggingSink {
uint32_t max_message_bytes_;
};
struct Entry {
enum class EventType {
kUnkown = 0,
kClientHeader,
kServerHeader,
kClientMessage,
kServerMessage,
kClientHalfClose,
kServerTrailer,
kCancel
};
enum class Logger { kUnkown = 0, kClient, kServer };
struct Payload {
std::map<std::string, std::string> metadata;
absl::Duration duration;
uint32_t status_code;
std::string status_message;
std::string status_details;
uint32_t message_length;
std::string message;
};
struct Address {
enum class Type { kUnknown = 0, kIpv4, kIpv6, kUnix };
Type type;
std::string address;
uint32_t ip_port;
};
uint64_t call_id;
uint64_t sequence_id;
EventType type;
Logger logger;
Payload payload;
bool payload_truncated;
Address peer;
std::string authority;
std::string service_name;
std::string method_name;
};
virtual ~LoggingSink() = default;
virtual Config FindMatch(bool is_client, absl::string_view path) = 0;
virtual void LogEntry(Entry entry) = 0;
};
} // namespace internal

@ -101,8 +101,6 @@ grpc_cc_library(
],
external_deps = [
"absl/strings",
"absl/types:optional",
"googleapis_logging_grpc_service",
],
language = "c++",
tags = ["nofixdeps"],
@ -110,9 +108,6 @@ grpc_cc_library(
deps = [
":observability_config",
"//:gpr_platform",
"//:grpc++",
"//:grpc_opencensus_plugin",
"//src/core:env",
"//src/cpp/ext/filters/logging:logging_sink",
],
)

@ -23,49 +23,17 @@
#include <stddef.h>
#include <algorithm>
#include <utility>
#include "absl/types/optional.h"
#include "google/logging/v2/logging.grpc.pb.h"
#include <grpcpp/grpcpp.h>
#include "src/core/lib/gprpp/env.h"
#include "src/cpp/ext/filters/census/open_census_call_tracer.h"
namespace grpc {
namespace internal {
ObservabilityLoggingSink::ObservabilityLoggingSink(
GcpObservabilityConfig::CloudLogging logging_config, std::string project_id)
: project_id_(std::move(project_id)) {
GcpObservabilityConfig::CloudLogging logging_config) {
for (auto& client_rpc_event_config : logging_config.client_rpc_events) {
client_configs_.emplace_back(client_rpc_event_config);
client_configs.emplace_back(client_rpc_event_config);
}
for (auto& server_rpc_event_config : logging_config.server_rpc_events) {
server_configs_.emplace_back(server_rpc_event_config);
}
std::string endpoint;
absl::optional<std::string> endpoint_env =
grpc_core::GetEnv("GOOGLE_CLOUD_CPP_LOGGING_SERVICE_V2_ENDPOINT");
if (endpoint_env.has_value() && !endpoint_env->empty()) {
endpoint = std::move(*endpoint_env);
} else {
endpoint = "logging.googleapis.com";
}
ChannelArguments args;
// Disable observability for RPCs on this channel
args.SetInt(GRPC_ARG_ENABLE_OBSERVABILITY, 0);
// Set keepalive time to 24 hrs to effectively disable keepalive ping, but
// still enable KEEPALIVE_TIMEOUT to get the TCP_USER_TIMEOUT effect.
args.SetInt(GRPC_ARG_KEEPALIVE_TIME_MS, 24 * 60 * 60 * 1000 /* 24 hours */);
args.SetInt(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 20 * 1000 /* 20 seconds */);
stub_ = google::logging::v2::LoggingServiceV2::NewStub(
CreateCustomChannel(endpoint, GoogleDefaultCredentials(), args));
absl::optional<std::string> authority_env =
grpc_core::GetEnv("GOOGLE_CLOUD_CPP_LOGGING_SERVICE_V2_ENDPOINT");
if (authority_env.has_value() && !authority_env->empty()) {
authority_ = std::move(*endpoint_env);
server_configs.emplace_back(server_rpc_event_config);
}
}
@ -80,7 +48,7 @@ LoggingSink::Config ObservabilityLoggingSink::FindMatch(
path.substr(0, pos); // service name is before the '/'
absl::string_view method =
path.substr(pos + 1); // method name starts after the '/'
const auto& configs = is_client ? client_configs_ : server_configs_;
const auto& configs = is_client ? client_configs : server_configs;
for (const auto& config : configs) {
for (const auto& config_method : config.parsed_methods) {
if ((config_method.service == "*") ||
@ -98,27 +66,6 @@ LoggingSink::Config ObservabilityLoggingSink::FindMatch(
return LoggingSink::Config(0, 0);
}
void ObservabilityLoggingSink::LogEntry(Entry /* entry */) {
struct CallContext {
ClientContext context;
google::logging::v2::WriteLogEntriesRequest request;
google::logging::v2::WriteLogEntriesResponse response;
};
// TODO(yashykt): Implement batching so that we can batch a bunch of log
// entries into a single entry. Also, set a reasonable deadline on the
// context, and actually use the entry.
CallContext* call = new CallContext;
call->context.set_authority(authority_);
stub_->async()->WriteLogEntries(&(call->context), &(call->request),
&(call->response), [call](Status status) {
if (!status.ok()) {
// TODO(yashykt): Log the contents of the
// request on a failure.
}
delete call;
});
}
ObservabilityLoggingSink::Configuration::Configuration(
const GcpObservabilityConfig::CloudLogging::RpcEventConfiguration&
rpc_event_config)

@ -23,14 +23,10 @@
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "google/logging/v2/logging.grpc.pb.h"
#include <grpcpp/channel.h>
#include "src/cpp/ext/filters/logging/logging_sink.h"
#include "src/cpp/ext/gcp/observability_config.h"
@ -41,16 +37,14 @@ namespace internal {
// Interface for a logging sink that will be used by the logging filter.
class ObservabilityLoggingSink : public LoggingSink {
public:
ObservabilityLoggingSink(GcpObservabilityConfig::CloudLogging logging_config,
std::string project_id);
explicit ObservabilityLoggingSink(
GcpObservabilityConfig::CloudLogging logging_config);
~ObservabilityLoggingSink() override = default;
LoggingSink::Config FindMatch(bool is_client,
absl::string_view path) override;
void LogEntry(Entry entry) override;
private:
struct Configuration {
explicit Configuration(
@ -66,12 +60,8 @@ class ObservabilityLoggingSink : public LoggingSink {
uint32_t max_message_bytes = 0;
};
std::vector<Configuration> client_configs_;
std::vector<Configuration> server_configs_;
std::string project_id_;
std::shared_ptr<grpc::Channel> channel_;
std::unique_ptr<google::logging::v2::LoggingServiceV2::StubInterface> stub_;
std::string authority_;
std::vector<Configuration> client_configs;
std::vector<Configuration> server_configs;
};
} // namespace internal

@ -37,7 +37,7 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigEmpty) {
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "foo/bar"), LoggingSink::Config(0, 0));
// server test
@ -62,7 +62,7 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigClientWildCardEntries) {
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "foo/bar"), LoggingSink::Config(1024, 4096));
// server test
@ -87,7 +87,7 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigBadPath) {
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
EXPECT_EQ(sink.FindMatch(true, "foo"), LoggingSink::Config(0, 0));
}
@ -110,7 +110,7 @@ TEST(GcpObservabilityLoggingSinkTest,
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "service/bar"),
LoggingSink::Config(1024, 4096));
@ -139,7 +139,7 @@ TEST(GcpObservabilityLoggingSinkTest,
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "foo/bar"), LoggingSink::Config(1024, 4096));
EXPECT_EQ(sink.FindMatch(true, "foo/baz"), LoggingSink::Config(1024, 4096));
@ -171,7 +171,7 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigClientMultipleEventEntries) {
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "foo/bar"), LoggingSink::Config(1024, 4096));
EXPECT_EQ(sink.FindMatch(true, "foo/baz"), LoggingSink::Config(512, 2048));
@ -198,7 +198,7 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigServerWildCardEntries) {
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "foo/bar"), LoggingSink::Config(0, 0));
// server test
@ -224,7 +224,7 @@ TEST(GcpObservabilityLoggingSinkTest,
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "service/bar"), LoggingSink::Config(0, 0));
EXPECT_EQ(sink.FindMatch(true, "foo/bar"), LoggingSink::Config(0, 0));
@ -253,7 +253,7 @@ TEST(GcpObservabilityLoggingSinkTest,
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "foo/bar"), LoggingSink::Config(0, 0));
EXPECT_EQ(sink.FindMatch(true, "foo/baz"), LoggingSink::Config(0, 0));
@ -285,7 +285,7 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigServerMultipleEventEntries) {
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test");
ObservabilityLoggingSink sink(config.cloud_logging.value());
// client test
EXPECT_EQ(sink.FindMatch(true, "foo/bar"), LoggingSink::Config(0, 0));
EXPECT_EQ(sink.FindMatch(true, "foo/baz"), LoggingSink::Config(0, 0));

Loading…
Cancel
Save