From dcad15d43ba301beb3d40ed312f03c64147de7b3 Mon Sep 17 00:00:00 2001 From: Vignesh Babu Date: Thu, 1 Dec 2022 02:32:57 +0530 Subject: [PATCH] Update xds client interface to take an externally supplied event engine (#31773) * Update xds client interface to take an externally supplied ev ent engine * update per review comments * fix sanity --- src/core/ext/xds/xds_client.cc | 11 ++++++----- src/core/ext/xds/xds_client.h | 8 +++++--- src/core/ext/xds/xds_client_grpc.cc | 2 ++ test/core/xds/xds_client_fuzzer.cc | 6 ++++-- test/core/xds/xds_client_test.cc | 2 ++ test/core/xds/xds_cluster_resource_type_test.cc | 3 ++- test/core/xds/xds_common_types_test.cc | 3 ++- test/core/xds/xds_endpoint_resource_type_test.cc | 3 ++- test/core/xds/xds_listener_resource_type_test.cc | 3 ++- test/core/xds/xds_route_config_resource_type_test.cc | 3 ++- 10 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/core/ext/xds/xds_client.cc b/src/core/ext/xds/xds_client.cc index 59eb879bcc4..1407d87a60f 100644 --- a/src/core/ext/xds/xds_client.cc +++ b/src/core/ext/xds/xds_client.cc @@ -39,7 +39,6 @@ #include "src/core/ext/xds/xds_bootstrap.h" #include "src/core/ext/xds/xds_client_stats.h" #include "src/core/lib/backoff/backoff.h" -#include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -1460,9 +1459,11 @@ bool XdsClient::ChannelState::LrsCallState::IsCurrentCallOnChannel() const { // XdsClient // -XdsClient::XdsClient(std::unique_ptr bootstrap, - OrphanablePtr transport_factory, - Duration resource_request_timeout) +XdsClient::XdsClient( + std::unique_ptr bootstrap, + OrphanablePtr transport_factory, + std::shared_ptr engine, + Duration resource_request_timeout) : DualRefCounted( GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_refcount_trace) ? "XdsClient" : nullptr), @@ -1471,7 +1472,7 @@ XdsClient::XdsClient(std::unique_ptr bootstrap, request_timeout_(resource_request_timeout), xds_federation_enabled_(XdsFederationEnabled()), api_(this, &grpc_xds_client_trace, bootstrap_->node(), &symtab_), - engine_(grpc_event_engine::experimental::GetDefaultEventEngine()) { + engine_(std::move(engine)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) { gpr_log(GPR_INFO, "[xds_client %p] creating xds client", this); } diff --git a/src/core/ext/xds/xds_client.h b/src/core/ext/xds/xds_client.h index d66bb9e97eb..aeafefb04b3 100644 --- a/src/core/ext/xds/xds_client.h +++ b/src/core/ext/xds/xds_client.h @@ -71,9 +71,11 @@ class XdsClient : public DualRefCounted { ABSL_EXCLUSIVE_LOCKS_REQUIRED(&work_serializer_) = 0; }; - XdsClient(std::unique_ptr bootstrap, - OrphanablePtr transport_factory, - Duration resource_request_timeout = Duration::Seconds(15)); + XdsClient( + std::unique_ptr bootstrap, + OrphanablePtr transport_factory, + std::shared_ptr engine, + Duration resource_request_timeout = Duration::Seconds(15)); ~XdsClient() override; const XdsBootstrap& bootstrap() const { diff --git a/src/core/ext/xds/xds_client_grpc.cc b/src/core/ext/xds/xds_client_grpc.cc index 20273bfc847..bfd7bec7569 100644 --- a/src/core/ext/xds/xds_client_grpc.cc +++ b/src/core/ext/xds/xds_client_grpc.cc @@ -41,6 +41,7 @@ #include "src/core/ext/xds/xds_transport_grpc.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" +#include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/orphanable.h" @@ -155,6 +156,7 @@ GrpcXdsClient::GrpcXdsClient(std::unique_ptr bootstrap, const ChannelArgs& args) : XdsClient( std::move(bootstrap), MakeOrphanable(args), + grpc_event_engine::experimental::GetDefaultEventEngine(), std::max(Duration::Zero(), args.GetDurationFromIntMillis( GRPC_ARG_XDS_RESOURCE_DOES_NOT_EXIST_TIMEOUT_MS) diff --git a/test/core/xds/xds_client_fuzzer.cc b/test/core/xds/xds_client_fuzzer.cc index 839880b88dd..dd41d220e80 100644 --- a/test/core/xds/xds_client_fuzzer.cc +++ b/test/core/xds/xds_client_fuzzer.cc @@ -22,6 +22,7 @@ #include "src/core/ext/xds/xds_endpoint.h" #include "src/core/ext/xds/xds_listener.h" #include "src/core/ext/xds/xds_route_config.h" +#include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/libfuzzer/libfuzzer_macro.h" #include "test/core/xds/xds_client_fuzzer.pb.h" @@ -42,8 +43,9 @@ class Fuzzer { auto transport_factory = MakeOrphanable(); transport_factory->SetAutoCompleteMessagesFromClient(false); transport_factory_ = transport_factory.get(); - xds_client_ = MakeRefCounted(std::move(*bootstrap), - std::move(transport_factory)); + xds_client_ = MakeRefCounted( + std::move(*bootstrap), std::move(transport_factory), + grpc_event_engine::experimental::GetDefaultEventEngine()); } void Act(const xds_client_fuzzer::Action& action) { diff --git a/test/core/xds/xds_client_test.cc b/test/core/xds/xds_client_test.cc index 5f99e51ed55..83c5387b57e 100644 --- a/test/core/xds/xds_client_test.cc +++ b/test/core/xds/xds_client_test.cc @@ -45,6 +45,7 @@ #include "src/core/ext/xds/xds_bootstrap.h" #include "src/core/ext/xds/xds_resource_type_impl.h" +#include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/env.h" #include "src/core/lib/gprpp/sync.h" @@ -568,6 +569,7 @@ class XdsClientTest : public ::testing::Test { transport_factory_ = transport_factory->Ref(); xds_client_ = MakeRefCounted( bootstrap_builder.Build(), std::move(transport_factory), + grpc_event_engine::experimental::GetDefaultEventEngine(), resource_request_timeout * grpc_test_slowdown_factor()); } diff --git a/test/core/xds/xds_cluster_resource_type_test.cc b/test/core/xds/xds_cluster_resource_type_test.cc index 764bc9e7791..ac8fba5c0e6 100644 --- a/test/core/xds/xds_cluster_resource_type_test.cc +++ b/test/core/xds/xds_cluster_resource_type_test.cc @@ -110,7 +110,8 @@ class XdsClusterTest : public ::testing::Test { GPR_ASSERT(false); } return MakeRefCounted(std::move(*bootstrap), - /*transport_factory=*/nullptr); + /*transport_factory=*/nullptr, + /*event_engine=*/nullptr); } RefCountedPtr xds_client_; diff --git a/test/core/xds/xds_common_types_test.cc b/test/core/xds/xds_common_types_test.cc index c706fcf1337..badcf594ce6 100644 --- a/test/core/xds/xds_common_types_test.cc +++ b/test/core/xds/xds_common_types_test.cc @@ -102,7 +102,8 @@ class XdsCommonTypesTest : public ::testing::Test { GPR_ASSERT(false); } return MakeRefCounted(std::move(*bootstrap), - /*transport_factory=*/nullptr); + /*transport_factory=*/nullptr, + /*event_engine=*/nullptr); } RefCountedPtr xds_client_; diff --git a/test/core/xds/xds_endpoint_resource_type_test.cc b/test/core/xds/xds_endpoint_resource_type_test.cc index c956db775c1..c1dea5a7bce 100644 --- a/test/core/xds/xds_endpoint_resource_type_test.cc +++ b/test/core/xds/xds_endpoint_resource_type_test.cc @@ -88,7 +88,8 @@ class XdsEndpointTest : public ::testing::Test { GPR_ASSERT(false); } return MakeRefCounted(std::move(*bootstrap), - /*transport_factory=*/nullptr); + /*transport_factory=*/nullptr, + /*event_engine=*/nullptr); } RefCountedPtr xds_client_; diff --git a/test/core/xds/xds_listener_resource_type_test.cc b/test/core/xds/xds_listener_resource_type_test.cc index 85f18644d35..bc1567ac4b7 100644 --- a/test/core/xds/xds_listener_resource_type_test.cc +++ b/test/core/xds/xds_listener_resource_type_test.cc @@ -115,7 +115,8 @@ class XdsListenerTest : public ::testing::Test { GPR_ASSERT(false); } return MakeRefCounted(std::move(*bootstrap), - /*transport_factory=*/nullptr); + /*transport_factory=*/nullptr, + /*event_engine=*/nullptr); } RefCountedPtr xds_client_; diff --git a/test/core/xds/xds_route_config_resource_type_test.cc b/test/core/xds/xds_route_config_resource_type_test.cc index 45e30373d2c..27400f554d8 100644 --- a/test/core/xds/xds_route_config_resource_type_test.cc +++ b/test/core/xds/xds_route_config_resource_type_test.cc @@ -103,7 +103,8 @@ class XdsRouteConfigTest : public ::testing::Test { GPR_ASSERT(false); } return MakeRefCounted(std::move(*bootstrap), - /*transport_factory=*/nullptr); + /*transport_factory=*/nullptr, + /*event_engine=*/nullptr); } RefCountedPtr xds_client_;