diff --git a/BUILD b/BUILD index 609fd9fee44..33d14f660d6 100644 --- a/BUILD +++ b/BUILD @@ -2200,14 +2200,12 @@ grpc_cc_library( "src/cpp/ext/filters/census/grpc_plugin.h", "src/cpp/ext/filters/census/measures.h", "src/cpp/ext/filters/census/open_census_call_tracer.h", - "src/cpp/ext/filters/census/promise_notification.h", "src/cpp/ext/filters/census/rpc_encoding.h", "src/cpp/ext/filters/census/server_filter.h", ], external_deps = [ "absl/base", "absl/base:core_headers", - "absl/functional:any_invocable", "absl/meta:type_traits", "absl/status", "absl/status:statusor", @@ -2231,7 +2229,6 @@ grpc_cc_library( "grpc++_base", "grpc_base", "grpc_public_hdrs", - "//src/core:activity", "//src/core:arena", "//src/core:arena_promise", "//src/core:cancel_callback", @@ -2239,13 +2236,11 @@ grpc_cc_library( "//src/core:channel_fwd", "//src/core:channel_stack_type", "//src/core:context", - "//src/core:default_event_engine", "//src/core:error", "//src/core:experiments", "//src/core:map", "//src/core:pipe", "//src/core:poll", - "//src/core:seq", "//src/core:slice", "//src/core:slice_buffer", "//src/core:slice_refcount", diff --git a/src/cpp/ext/filters/census/client_filter.cc b/src/cpp/ext/filters/census/client_filter.cc index eb6c9b92d17..2a53094a5b6 100644 --- a/src/cpp/ext/filters/census/client_filter.cc +++ b/src/cpp/ext/filters/census/client_filter.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -55,7 +54,6 @@ #include "src/core/lib/experiments/experiments.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/promise/context.h" -#include "src/core/lib/promise/seq.h" #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/slice/slice_buffer.h" @@ -65,7 +63,6 @@ #include "src/cpp/ext/filters/census/grpc_plugin.h" #include "src/cpp/ext/filters/census/measures.h" #include "src/cpp/ext/filters/census/open_census_call_tracer.h" -#include "src/cpp/ext/filters/census/promise_notification.h" namespace grpc { namespace internal { @@ -88,11 +85,6 @@ absl::StatusOr OpenCensusClientFilter::Create( const grpc_core::ChannelArgs& args, ChannelFilter::Args /*filter_args*/) { bool observability_enabled = args.GetInt(GRPC_ARG_ENABLE_OBSERVABILITY).value_or(true); - // Only run the Post-Init Registry if observability is enabled to avoid - // running into a cyclic loop for exporter channels. - if (observability_enabled) { - OpenCensusRegistry::Get().RunFunctionsPostInit(); - } return OpenCensusClientFilter(/*tracing_enabled=*/observability_enabled); } @@ -100,34 +92,19 @@ grpc_core::ArenaPromise OpenCensusClientFilter::MakeCallPromise( grpc_core::CallArgs call_args, grpc_core::NextPromiseFactory next_promise_factory) { - auto continue_making_call_promise = [this, - next_promise_factory = - std::move(next_promise_factory), - call_args = - std::move(call_args)]() mutable { - auto* path = call_args.client_initial_metadata->get_pointer( - grpc_core::HttpPathMetadata()); - auto* call_context = grpc_core::GetContext(); - auto* tracer = grpc_core::GetContext() - ->ManagedNew( - call_context, - path != nullptr ? path->Ref() : grpc_core::Slice(), - grpc_core::GetContext(), - OpenCensusTracingEnabled() && tracing_enabled_); - GPR_DEBUG_ASSERT(call_context[GRPC_CONTEXT_CALL_TRACER].value == nullptr); - call_context[GRPC_CONTEXT_CALL_TRACER].value = tracer; - call_context[GRPC_CONTEXT_CALL_TRACER].destroy = nullptr; - return next_promise_factory(std::move(call_args)); - }; - // If the OpenCensus plugin is not yet ready, then wait for it to be ready. - if (!grpc::internal::OpenCensusRegistry::Get().Ready()) { - auto notification = std::make_shared(); - grpc::internal::OpenCensusRegistry::Get().NotifyOnReady( - [notification]() { notification->Notify(); }); - return grpc_core::Seq([notification]() { return notification->Wait(); }, - std::move(continue_making_call_promise)); - } - return continue_making_call_promise(); + auto* path = call_args.client_initial_metadata->get_pointer( + grpc_core::HttpPathMetadata()); + auto* call_context = grpc_core::GetContext(); + auto* tracer = + grpc_core::GetContext() + ->ManagedNew( + call_context, path != nullptr ? path->Ref() : grpc_core::Slice(), + grpc_core::GetContext(), + OpenCensusTracingEnabled() && tracing_enabled_); + GPR_DEBUG_ASSERT(call_context[GRPC_CONTEXT_CALL_TRACER].value == nullptr); + call_context[GRPC_CONTEXT_CALL_TRACER].value = tracer; + call_context[GRPC_CONTEXT_CALL_TRACER].destroy = nullptr; + return next_promise_factory(std::move(call_args)); } // diff --git a/src/cpp/ext/filters/census/grpc_plugin.h b/src/cpp/ext/filters/census/grpc_plugin.h index 7cd93524994..9e2b837ddf8 100644 --- a/src/cpp/ext/filters/census/grpc_plugin.h +++ b/src/cpp/ext/filters/census/grpc_plugin.h @@ -22,25 +22,16 @@ #include #include -#include #include -#include #include #include #include -#include "absl/base/call_once.h" -#include "absl/base/thread_annotations.h" -#include "absl/functional/any_invocable.h" #include "opencensus/tags/tag_key.h" #include "opencensus/tags/tag_map.h" -#include #include -#include "src/core/lib/event_engine/default_event_engine.h" -#include "src/core/lib/gprpp/sync.h" - namespace grpc { // The following using declarations have been added to prevent breaking users @@ -160,22 +151,8 @@ class OpenCensusRegistry { static OpenCensusRegistry& Get(); - // Registers the functions to be run post-init. - void RegisterFunctions(std::function f) { - exporter_registry_.push_back(std::move(f)); - } - - void RegisterWaitOnReady() { wait_on_ready_ = true; } - - // Runs the registry post-init exactly once. Protected with an absl::CallOnce. - void RunFunctionsPostInit() { - absl::call_once(once_, &OpenCensusRegistry::RunFunctionsPostInitHelper, - this); - } - void RegisterConstantLabels( const std::map& labels) { - grpc_core::MutexLock lock(&mu_); constant_labels_.reserve(labels.size()); for (const auto& label : labels) { auto tag_key = opencensus::tags::TagKey::Register(label.first); @@ -184,89 +161,26 @@ class OpenCensusRegistry { } void RegisterConstantAttributes(std::vector attributes) { - grpc_core::MutexLock lock(&mu_); constant_attributes_ = std::move(attributes); } - void NotifyOnReady(absl::AnyInvocable callback) { - grpc_core::MutexLock lock(&mu_); - // Environment has already been detected - if (ready_) { - // Execute on the event engine to avoid deadlocks. - return event_engine()->Run(std::move(callback)); - } - callbacks_.push_back(std::move(callback)); - } - ::opencensus::tags::TagMap PopulateTagMapWithConstantLabels( const ::opencensus::tags::TagMap& tag_map); void PopulateCensusContextWithConstantAttributes( grpc::experimental::CensusContext* context); - void SetReady() { - std::vector> callbacks; - { - grpc_core::MutexLock lock(&mu_); - ready_ = true; - callbacks = std::move(callbacks_); - } - for (auto& callback : callbacks) { - callback(); - } - } - - bool Ready() { - if (!wait_on_ready_) { - return true; - } - grpc_core::MutexLock lock(&mu_); - return ready_; - } - - const std::vector