From d7266f48f4344c43d5bbd3e0921aa4962d558638 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 28 Sep 2022 16:09:13 -0700 Subject: [PATCH] GcpObservability: Disable observability traces for CloudOps endpoints (#31094) * GcpObservability: Disable observability traces for CloudOps endpoints * Fix deps and IWYU --- bazel/grpc_deps.bzl | 10 ++++++++++ src/cpp/ext/gcp/BUILD | 3 +++ src/cpp/ext/gcp/observability.cc | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 2c4dfcf8d62..a64fbab7fd2 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -190,6 +190,16 @@ def grpc_deps(): actual = "@com_github_libuv_libuv//:libuv_test", ) + native.bind( + name = "googleapis_trace_grpc_service", + actual = "@com_google_googleapis//google/devtools/cloudtrace/v2:cloudtrace_cc_grpc", + ) + + native.bind( + name = "googleapis_monitoring_grpc_service", + actual = "@com_google_googleapis//google/monitoring/v3:monitoring_cc_grpc", + ) + if "boringssl" not in native.existing_rules(): http_archive( name = "boringssl", diff --git a/src/cpp/ext/gcp/BUILD b/src/cpp/ext/gcp/BUILD index d05a9a32574..22b81e4bec4 100644 --- a/src/cpp/ext/gcp/BUILD +++ b/src/cpp/ext/gcp/BUILD @@ -41,6 +41,8 @@ grpc_cc_library( "absl/status", "absl/status:statusor", "absl/types:optional", + "googleapis_trace_grpc_service", + "googleapis_monitoring_grpc_service", "opencensus-stats", "opencensus-trace", "opencensus-trace-stackdriver_exporter", @@ -54,6 +56,7 @@ grpc_cc_library( "//:gpr", "//:grpc++_public_hdrs", "//:grpc_opencensus_plugin", + "//:grpc_public_hdrs", ], ) diff --git a/src/cpp/ext/gcp/observability.cc b/src/cpp/ext/gcp/observability.cc index c71a5d9570c..df3d8858e90 100644 --- a/src/cpp/ext/gcp/observability.cc +++ b/src/cpp/ext/gcp/observability.cc @@ -20,11 +20,14 @@ #include +#include #include #include #include "absl/status/statusor.h" #include "absl/types/optional.h" +#include "google/devtools/cloudtrace/v2/tracing.grpc.pb.h" +#include "google/monitoring/v3/metric_service.grpc.pb.h" #include "opencensus/exporters/stats/stackdriver/stackdriver_exporter.h" #include "opencensus/exporters/trace/stackdriver/stackdriver_exporter.h" #include "opencensus/stats/stats.h" @@ -32,9 +35,12 @@ #include "opencensus/trace/trace_config.h" #include +#include +#include #include #include "src/cpp/ext/filters/census/grpc_plugin.h" +#include "src/cpp/ext/filters/census/open_census_call_tracer.h" #include "src/cpp/ext/gcp/observability_config.h" namespace grpc { @@ -49,6 +55,9 @@ constexpr uint32_t kMaxAnnotations = 128; constexpr uint32_t kMaxMessageEvents = 128; constexpr uint32_t kMaxLinks = 128; +constexpr char kGoogleStackdriverTraceAddress[] = "cloudtrace.googleapis.com"; +constexpr char kGoogleStackdriverStatsAddress[] = "monitoring.googleapis.com"; + void RegisterOpenCensusViewsForGcpObservability() { // Register client default views for GCP observability ClientStartedRpcsCumulative().RegisterForExport(); @@ -67,6 +76,8 @@ absl::Status GcpObservabilityInit() { } grpc::RegisterOpenCensusPlugin(); RegisterOpenCensusViewsForGcpObservability(); + ChannelArguments args; + args.SetInt(GRPC_ARG_ENABLE_OBSERVABILITY, 0); if (config->cloud_trace.has_value()) { opencensus::trace::TraceConfig::SetCurrentTraceParams( {kMaxAttributes, kMaxAnnotations, kMaxMessageEvents, kMaxLinks, @@ -74,12 +85,19 @@ absl::Status GcpObservabilityInit() { config->cloud_trace->sampling_rate)}); opencensus::exporters::trace::StackdriverOptions trace_opts; trace_opts.project_id = config->project_id; + trace_opts.trace_service_stub = + ::google::devtools::cloudtrace::v2::TraceService::NewStub( + CreateCustomChannel(kGoogleStackdriverTraceAddress, + GoogleDefaultCredentials(), args)); opencensus::exporters::trace::StackdriverExporter::Register( std::move(trace_opts)); } if (config->cloud_monitoring.has_value()) { opencensus::exporters::stats::StackdriverOptions stats_opts; stats_opts.project_id = config->project_id; + stats_opts.metric_service_stub = + google::monitoring::v3::MetricService::NewStub(CreateCustomChannel( + kGoogleStackdriverStatsAddress, GoogleDefaultCredentials(), args)); opencensus::exporters::stats::StackdriverExporter::Register( std::move(stats_opts)); }