[xDS] make transport factory injectable in GrpcXdsClient (#33328)

pull/33338/head
Mark D. Roth 2 years ago committed by GitHub
parent b43a668def
commit 9fec475cc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/core/ext/xds/xds_client_grpc.cc
  2. 15
      src/core/ext/xds/xds_client_grpc.h

@ -145,8 +145,10 @@ absl::StatusOr<RefCountedPtr<GrpcXdsClient>> GrpcXdsClient::GetOrCreate(
if (!bootstrap.ok()) return bootstrap.status();
grpc_channel_args* xds_channel_args = args.GetPointer<grpc_channel_args>(
GRPC_ARG_TEST_ONLY_DO_NOT_USE_IN_PROD_XDS_CLIENT_CHANNEL_ARGS);
return MakeRefCounted<GrpcXdsClient>(std::move(*bootstrap),
ChannelArgs::FromC(xds_channel_args));
auto channel_args = ChannelArgs::FromC(xds_channel_args);
return MakeRefCounted<GrpcXdsClient>(
std::move(*bootstrap), channel_args,
MakeOrphanable<GrpcXdsTransportFactory>(channel_args));
}
// Otherwise, use the global instance.
MutexLock lock(g_mu);
@ -165,16 +167,19 @@ absl::StatusOr<RefCountedPtr<GrpcXdsClient>> GrpcXdsClient::GetOrCreate(
auto bootstrap = GrpcXdsBootstrap::Create(*bootstrap_contents);
if (!bootstrap.ok()) return bootstrap.status();
// Instantiate XdsClient.
auto channel_args = ChannelArgs::FromC(g_channel_args);
auto xds_client = MakeRefCounted<GrpcXdsClient>(
std::move(*bootstrap), ChannelArgs::FromC(g_channel_args));
std::move(*bootstrap), channel_args,
MakeOrphanable<GrpcXdsTransportFactory>(channel_args));
g_xds_client = xds_client.get();
return xds_client;
}
GrpcXdsClient::GrpcXdsClient(std::unique_ptr<GrpcXdsBootstrap> bootstrap,
const ChannelArgs& args)
GrpcXdsClient::GrpcXdsClient(
std::unique_ptr<GrpcXdsBootstrap> bootstrap, const ChannelArgs& args,
OrphanablePtr<XdsTransportFactory> transport_factory)
: XdsClient(
std::move(bootstrap), MakeOrphanable<GrpcXdsTransportFactory>(args),
std::move(bootstrap), std::move(transport_factory),
grpc_event_engine::experimental::GetDefaultEventEngine(),
absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING,
GRPC_XDS_USER_AGENT_NAME_SUFFIX_STRING),

@ -29,6 +29,7 @@
#include "src/core/ext/xds/certificate_provider_store.h"
#include "src/core/ext/xds/xds_bootstrap_grpc.h"
#include "src/core/ext/xds/xds_client.h"
#include "src/core/ext/xds/xds_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/orphanable.h"
@ -44,8 +45,20 @@ class GrpcXdsClient : public XdsClient {
const ChannelArgs& args, const char* reason);
// Do not instantiate directly -- use GetOrCreate() instead.
// TODO(roth): The transport factory is injectable here to support
// tests that want to use a fake transport factory with code that
// expects a GrpcXdsClient instead of an XdsClient, typically because
// it needs to call the interested_parties() method. Once we
// finish the EventEngine migration and remove the interested_parties()
// method, consider instead changing callers to an approach where the
// production code uses XdsClient instead of GrpcXdsClient, and then
// passing in a fake XdsClient impl in the tests. Note that this will
// work for callers that use interested_parties() but not for callers
// that also use certificate_provider_store(), but we should consider
// alternatives for that case as well.
GrpcXdsClient(std::unique_ptr<GrpcXdsBootstrap> bootstrap,
const ChannelArgs& args);
const ChannelArgs& args,
OrphanablePtr<XdsTransportFactory> transport_factory);
~GrpcXdsClient() override;
// Helpers for encoding the XdsClient object in channel args.

Loading…
Cancel
Save