Merge pull request #22540 from apolcyn/per_target_service_configs

Add a flag used to allow qps_json_driver and qps_worker channels to use the "grpclb" LB policy
pull/22375/head
apolcyn 5 years ago committed by GitHub
commit 610533d47c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      test/cpp/qps/driver.cc
  2. 30
      test/cpp/util/create_test_channel.cc

@ -313,11 +313,10 @@ std::unique_ptr<ScenarioResult> RunScenario(
gpr_log(GPR_INFO, "Starting server on %s (worker #%" PRIuPTR ")",
workers[i].c_str(), i);
if (!run_inproc) {
servers[i].stub = WorkerService::NewStub(grpc::CreateChannel(
workers[i], GetCredentialsProvider()->GetChannelCredentials(
GetCredType(workers[i], per_worker_credential_types,
credential_type),
&channel_args)));
servers[i].stub = WorkerService::NewStub(grpc::CreateTestChannel(
workers[i],
GetCredType(workers[i], per_worker_credential_types, credential_type),
nullptr /* call creds */, {} /* interceptor creators */));
} else {
servers[i].stub = WorkerService::NewStub(
local_workers[i]->InProcessChannel(channel_args));
@ -373,11 +372,10 @@ std::unique_ptr<ScenarioResult> RunScenario(
gpr_log(GPR_INFO, "Starting client on %s (worker #%" PRIuPTR ")",
worker.c_str(), i + num_servers);
if (!run_inproc) {
clients[i].stub = WorkerService::NewStub(grpc::CreateChannel(
clients[i].stub = WorkerService::NewStub(grpc::CreateTestChannel(
worker,
GetCredentialsProvider()->GetChannelCredentials(
GetCredType(worker, per_worker_credential_types, credential_type),
&channel_args)));
GetCredType(worker, per_worker_credential_types, credential_type),
nullptr /* call creds */, {} /* interceptor creators */));
} else {
clients[i].stub = WorkerService::NewStub(
local_workers[i + num_servers]->InProcessChannel(channel_args));
@ -588,13 +586,11 @@ bool RunQuit(
return false;
}
ChannelArguments channel_args;
for (size_t i = 0; i < workers.size(); i++) {
auto stub = WorkerService::NewStub(grpc::CreateChannel(
workers[i], GetCredentialsProvider()->GetChannelCredentials(
GetCredType(workers[i], per_worker_credential_types,
credential_type),
&channel_args)));
auto stub = WorkerService::NewStub(grpc::CreateTestChannel(
workers[i],
GetCredType(workers[i], per_worker_credential_types, credential_type),
nullptr /* call creds */, {} /* interceptor creators */));
Void dummy;
grpc::ClientContext ctx;
ctx.set_wait_for_ready(true);

@ -18,12 +18,21 @@
#include "test/cpp/util/create_test_channel.h"
#include <gflags/gflags.h>
#include <grpc/support/log.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/security/credentials.h>
#include "test/cpp/util/test_credentials_provider.h"
DEFINE_string(
grpc_test_use_grpclb_with_child_policy, "",
"If non-empty, set a static service config on channels created by "
"grpc::CreateTestChannel, that configures the grpclb LB policy "
"with a child policy being the value of this flag (e.g. round_robin "
"or pick_first).");
namespace grpc {
namespace {
@ -49,6 +58,16 @@ void AddProdSslType() {
new SslCredentialProvider));
}
void MaybeSetCustomChannelArgs(grpc::ChannelArguments* args) {
if (FLAGS_grpc_test_use_grpclb_with_child_policy.size() > 0) {
args->SetString("grpc.service_config",
"{\"loadBalancingConfig\":[{\"grpclb\":{\"childPolicy\":[{"
"\"" +
FLAGS_grpc_test_use_grpclb_with_child_policy +
"\":{}}]}}]}");
}
}
} // namespace
// When cred_type is 'ssl', if server is empty, override_hostname is used to
@ -111,6 +130,7 @@ std::shared_ptr<Channel> CreateTestChannel(
const grpc::string& server, const grpc::string& credential_type,
const std::shared_ptr<CallCredentials>& creds) {
ChannelArguments channel_args;
MaybeSetCustomChannelArgs(&channel_args);
std::shared_ptr<ChannelCredentials> channel_creds =
testing::GetCredentialsProvider()->GetChannelCredentials(credential_type,
&channel_args);
@ -129,14 +149,15 @@ std::shared_ptr<Channel> CreateTestChannel(
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) {
ChannelArguments channel_args(args);
MaybeSetCustomChannelArgs(&channel_args);
std::shared_ptr<ChannelCredentials> channel_creds;
if (cred_type.empty()) {
if (interceptor_creators.empty()) {
return ::grpc::CreateCustomChannel(server, InsecureChannelCredentials(),
args);
channel_args);
} else {
return experimental::CreateCustomChannelWithInterceptors(
server, InsecureChannelCredentials(), args,
server, InsecureChannelCredentials(), channel_args,
std::move(interceptor_creators));
}
} else if (cred_type == testing::kTlsCredentialsType) { // cred_type == "ssl"
@ -173,10 +194,10 @@ std::shared_ptr<Channel> CreateTestChannel(
GPR_ASSERT(channel_creds != nullptr);
if (interceptor_creators.empty()) {
return ::grpc::CreateCustomChannel(server, channel_creds, args);
return ::grpc::CreateCustomChannel(server, channel_creds, channel_args);
} else {
return experimental::CreateCustomChannelWithInterceptors(
server, channel_creds, args, std::move(interceptor_creators));
server, channel_creds, channel_args, std::move(interceptor_creators));
}
}
}
@ -217,6 +238,7 @@ std::shared_ptr<Channel> CreateTestChannel(
std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
interceptor_creators) {
ChannelArguments channel_args;
MaybeSetCustomChannelArgs(&channel_args);
std::shared_ptr<ChannelCredentials> channel_creds =
testing::GetCredentialsProvider()->GetChannelCredentials(credential_type,
&channel_args);

Loading…
Cancel
Save