Skip to content

Commit 0ca3d12

Browse files
authored
Support XDS protocols for client load balancing in order to request to Access Service (#21280)
1 parent 420a830 commit 0ca3d12

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

ydb/library/grpc/actor_client/grpc_service_client.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ class TGrpcServiceClient {
7676
using TResponseType = decltype(typename TCallType::TResponseEventType().Response);
7777
const auto& requestId = ev->Get()->RequestId;
7878
if (!Connection) {
79-
BLOG_GRPC_D(Prefix(requestId) << "Connect to "
80-
<< ((Config.EnableSsl || !Config.SslCredentials.pem_root_certs.empty()) ? "grpcs://" : "grpc://")
81-
<< Config.Locator);
79+
TString schema;
80+
if (!Config.UseXds) {
81+
schema = ((Config.EnableSsl || !Config.SslCredentials.pem_root_certs.empty()) ? "grpcs://" : "grpc://");
82+
}
83+
BLOG_GRPC_D(Prefix(requestId) << "Connect to " << schema << Config.Locator);
8284
Connection = Client.CreateGRpcServiceConnection<TGrpcService>(Config);
8385
}
8486

ydb/public/sdk/cpp/src/library/grpc/client/grpc_common.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ struct TGRpcClientConfig {
2222
ui32 MaxInFlight = 0;
2323
bool EnableSsl = false;
2424
grpc::SslCredentialsOptions SslCredentials;
25-
grpc_compression_algorithm CompressionAlgoritm = GRPC_COMPRESS_NONE;
25+
grpc_compression_algorithm CompressionAlgorithm = GRPC_COMPRESS_NONE;
2626
ui64 MemQuota = 0;
2727
std::unordered_map<std::string, std::string> StringChannelParams;
2828
std::unordered_map<std::string, int> IntChannelParams;
2929
std::string LoadBalancingPolicy = { };
3030
std::string SslTargetNameOverride = { };
31+
bool UseXds = false;
3132

3233
TGRpcClientConfig() = default;
3334
TGRpcClientConfig(const TGRpcClientConfig&) = default;
@@ -46,15 +47,16 @@ struct TGRpcClientConfig {
4647
, SslCredentials{.pem_root_certs = NYdb::TStringType{caCert},
4748
.pem_private_key = NYdb::TStringType{clientPrivateKey},
4849
.pem_cert_chain = NYdb::TStringType{clientCert}}
49-
, CompressionAlgoritm(compressionAlgorithm)
50+
, CompressionAlgorithm(compressionAlgorithm)
51+
, UseXds((Locator.starts_with("xds:///")))
5052
{}
5153
};
5254

5355
inline std::shared_ptr<grpc::ChannelInterface> CreateChannelInterface(const TGRpcClientConfig& config, grpc_socket_mutator* mutator = nullptr){
5456
grpc::ChannelArguments args;
5557
args.SetMaxReceiveMessageSize(config.MaxInboundMessageSize ? config.MaxInboundMessageSize : config.MaxMessageSize);
5658
args.SetMaxSendMessageSize(config.MaxOutboundMessageSize ? config.MaxOutboundMessageSize : config.MaxMessageSize);
57-
args.SetCompressionAlgorithm(config.CompressionAlgoritm);
59+
args.SetCompressionAlgorithm(config.CompressionAlgorithm);
5860

5961
for (const auto& kvp: config.StringChannelParams) {
6062
args.SetString(NYdb::TStringType{kvp.first}, NYdb::TStringType{kvp.second});
@@ -78,11 +80,16 @@ inline std::shared_ptr<grpc::ChannelInterface> CreateChannelInterface(const TGRp
7880
if (!config.SslTargetNameOverride.empty()) {
7981
args.SetSslTargetNameOverride(NYdb::TStringType{config.SslTargetNameOverride});
8082
}
83+
std::shared_ptr<grpc::ChannelCredentials> channelCredentials = nullptr;
8184
if (config.EnableSsl || !config.SslCredentials.pem_root_certs.empty()) {
82-
return grpc::CreateCustomChannel(grpc::string(config.Locator), grpc::SslCredentials(config.SslCredentials), args);
85+
channelCredentials = grpc::SslCredentials(config.SslCredentials);
8386
} else {
84-
return grpc::CreateCustomChannel(grpc::string(config.Locator), grpc::InsecureChannelCredentials(), args);
87+
channelCredentials = grpc::InsecureChannelCredentials();
8588
}
89+
if (config.UseXds) {
90+
channelCredentials = grpc::XdsCredentials(channelCredentials);
91+
}
92+
return grpc::CreateCustomChannel(grpc::string(config.Locator), channelCredentials, args);
8693
}
8794

8895
}

0 commit comments

Comments
 (0)