C++ xDS interop test server changes (#25633)
* C++ xDS interop test server changes
This commit is contained in:
parent
d4ef8084f4
commit
8eb2e13a6e
|
|
@ -16155,6 +16155,10 @@ endif()
|
||||||
if(gRPC_BUILD_TESTS)
|
if(gRPC_BUILD_TESTS)
|
||||||
|
|
||||||
add_executable(xds_interop_server
|
add_executable(xds_interop_server
|
||||||
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.pb.cc
|
||||||
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.grpc.pb.cc
|
||||||
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.pb.h
|
||||||
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.grpc.pb.h
|
||||||
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.cc
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.cc
|
||||||
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.cc
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.cc
|
||||||
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.h
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.h
|
||||||
|
|
@ -16167,6 +16171,7 @@ add_executable(xds_interop_server
|
||||||
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.cc
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.cc
|
||||||
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.pb.h
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.pb.h
|
||||||
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.h
|
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.h
|
||||||
|
test/cpp/end2end/test_health_check_service_impl.cc
|
||||||
test/cpp/interop/xds_interop_server.cc
|
test/cpp/interop/xds_interop_server.cc
|
||||||
third_party/googletest/googletest/src/gtest-all.cc
|
third_party/googletest/googletest/src/gtest-all.cc
|
||||||
third_party/googletest/googlemock/src/gmock-all.cc
|
third_party/googletest/googlemock/src/gmock-all.cc
|
||||||
|
|
|
||||||
|
|
@ -8374,11 +8374,14 @@ targets:
|
||||||
build: test
|
build: test
|
||||||
run: false
|
run: false
|
||||||
language: c++
|
language: c++
|
||||||
headers: []
|
headers:
|
||||||
|
- test/cpp/end2end/test_health_check_service_impl.h
|
||||||
src:
|
src:
|
||||||
|
- src/proto/grpc/health/v1/health.proto
|
||||||
- src/proto/grpc/testing/empty.proto
|
- src/proto/grpc/testing/empty.proto
|
||||||
- src/proto/grpc/testing/messages.proto
|
- src/proto/grpc/testing/messages.proto
|
||||||
- src/proto/grpc/testing/test.proto
|
- src/proto/grpc/testing/test.proto
|
||||||
|
- test/cpp/end2end/test_health_check_service_impl.cc
|
||||||
- test/cpp/interop/xds_interop_server.cc
|
- test/cpp/interop/xds_interop_server.cc
|
||||||
deps:
|
deps:
|
||||||
- grpc_test_util
|
- grpc_test_util
|
||||||
|
|
|
||||||
|
|
@ -239,6 +239,7 @@ grpc_cc_binary(
|
||||||
|
|
||||||
grpc_cc_binary(
|
grpc_cc_binary(
|
||||||
name = "xds_interop_server",
|
name = "xds_interop_server",
|
||||||
|
testonly = True,
|
||||||
srcs = [
|
srcs = [
|
||||||
"xds_interop_server.cc",
|
"xds_interop_server.cc",
|
||||||
],
|
],
|
||||||
|
|
@ -251,6 +252,7 @@ grpc_cc_binary(
|
||||||
"//src/proto/grpc/testing:messages_proto",
|
"//src/proto/grpc/testing:messages_proto",
|
||||||
"//src/proto/grpc/testing:test_proto",
|
"//src/proto/grpc/testing:test_proto",
|
||||||
"//test/core/util:grpc_test_util",
|
"//test/core/util:grpc_test_util",
|
||||||
|
"//test/cpp/end2end:test_health_check_service_impl",
|
||||||
"//test/cpp/util:test_config",
|
"//test/cpp/util:test_config",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,9 @@ ABSL_FLAG(std::string, rpc, "UnaryCall",
|
||||||
ABSL_FLAG(std::string, metadata, "", "metadata to send with the RPC.");
|
ABSL_FLAG(std::string, metadata, "", "metadata to send with the RPC.");
|
||||||
ABSL_FLAG(std::string, expect_status, "OK",
|
ABSL_FLAG(std::string, expect_status, "OK",
|
||||||
"RPC status for the test RPC to be considered successful");
|
"RPC status for the test RPC to be considered successful");
|
||||||
ABSL_FLAG(std::string, security, "none",
|
ABSL_FLAG(
|
||||||
"If set to \"secure\", XdsCredentials are used");
|
bool, secure_mode, false,
|
||||||
|
"If true, XdsCredentials are used, InsecureChannelCredentials otherwise");
|
||||||
|
|
||||||
using grpc::Channel;
|
using grpc::Channel;
|
||||||
using grpc::ClientAsyncResponseReader;
|
using grpc::ClientAsyncResponseReader;
|
||||||
|
|
@ -464,7 +465,7 @@ void RunTestLoop(std::chrono::duration<double> duration_per_query,
|
||||||
RpcConfigurationsQueue* rpc_configs_queue) {
|
RpcConfigurationsQueue* rpc_configs_queue) {
|
||||||
TestClient client(
|
TestClient client(
|
||||||
grpc::CreateChannel(absl::GetFlag(FLAGS_server),
|
grpc::CreateChannel(absl::GetFlag(FLAGS_server),
|
||||||
absl::GetFlag(FLAGS_security) == "secure"
|
absl::GetFlag(FLAGS_secure_mode)
|
||||||
? grpc::experimental::XdsCredentials(
|
? grpc::experimental::XdsCredentials(
|
||||||
grpc::InsecureChannelCredentials())
|
grpc::InsecureChannelCredentials())
|
||||||
: grpc::InsecureChannelCredentials()),
|
: grpc::InsecureChannelCredentials()),
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,17 @@
|
||||||
#include <grpc/grpc.h>
|
#include <grpc/grpc.h>
|
||||||
#include <grpc/support/log.h>
|
#include <grpc/support/log.h>
|
||||||
#include <grpc/support/time.h>
|
#include <grpc/support/time.h>
|
||||||
|
#include <grpcpp/health_check_service_interface.h>
|
||||||
#include <grpcpp/server.h>
|
#include <grpcpp/server.h>
|
||||||
#include <grpcpp/server_builder.h>
|
#include <grpcpp/server_builder.h>
|
||||||
#include <grpcpp/server_context.h>
|
#include <grpcpp/server_context.h>
|
||||||
|
#include <grpcpp/xds_server_builder.h>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "absl/flags/flag.h"
|
#include "absl/flags/flag.h"
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/synchronization/mutex.h"
|
||||||
#include "src/core/lib/gpr/string.h"
|
#include "src/core/lib/gpr/string.h"
|
||||||
#include "src/core/lib/iomgr/gethostname.h"
|
#include "src/core/lib/iomgr/gethostname.h"
|
||||||
#include "src/core/lib/transport/byte_stream.h"
|
#include "src/core/lib/transport/byte_stream.h"
|
||||||
|
|
@ -33,24 +37,33 @@
|
||||||
#include "src/proto/grpc/testing/messages.pb.h"
|
#include "src/proto/grpc/testing/messages.pb.h"
|
||||||
#include "src/proto/grpc/testing/test.grpc.pb.h"
|
#include "src/proto/grpc/testing/test.grpc.pb.h"
|
||||||
#include "test/core/util/test_config.h"
|
#include "test/core/util/test_config.h"
|
||||||
|
#include "test/cpp/end2end/test_health_check_service_impl.h"
|
||||||
#include "test/cpp/util/test_config.h"
|
#include "test/cpp/util/test_config.h"
|
||||||
|
|
||||||
ABSL_FLAG(int32_t, port, 50051, "Server port.");
|
ABSL_FLAG(int32_t, port, 8080, "Server port for service.");
|
||||||
|
ABSL_FLAG(int32_t, maintenance_port, 8081,
|
||||||
|
"Server port for maintenance if --security is \"secure\".");
|
||||||
ABSL_FLAG(std::string, server_id, "cpp_server",
|
ABSL_FLAG(std::string, server_id, "cpp_server",
|
||||||
"Server ID to include in responses.");
|
"Server ID to include in responses.");
|
||||||
|
ABSL_FLAG(bool, secure_mode, false,
|
||||||
|
"If true, XdsServerCredentials are used, InsecureServerCredentials "
|
||||||
|
"otherwise");
|
||||||
|
|
||||||
using grpc::Server;
|
using grpc::Server;
|
||||||
using grpc::ServerBuilder;
|
using grpc::ServerBuilder;
|
||||||
using grpc::ServerContext;
|
using grpc::ServerContext;
|
||||||
using grpc::Status;
|
using grpc::Status;
|
||||||
|
using grpc::experimental::XdsServerBuilder;
|
||||||
using grpc::testing::Empty;
|
using grpc::testing::Empty;
|
||||||
|
using grpc::testing::HealthCheckServiceImpl;
|
||||||
using grpc::testing::SimpleRequest;
|
using grpc::testing::SimpleRequest;
|
||||||
using grpc::testing::SimpleResponse;
|
using grpc::testing::SimpleResponse;
|
||||||
using grpc::testing::TestService;
|
using grpc::testing::TestService;
|
||||||
|
using grpc::testing::XdsUpdateHealthService;
|
||||||
|
|
||||||
class TestServiceImpl : public TestService::Service {
|
class TestServiceImpl : public TestService::Service {
|
||||||
public:
|
public:
|
||||||
explicit TestServiceImpl(const std::string& i) : hostname_(i) {}
|
explicit TestServiceImpl(const std::string& hostname) : hostname_(hostname) {}
|
||||||
|
|
||||||
Status UnaryCall(ServerContext* context, const SimpleRequest* /*request*/,
|
Status UnaryCall(ServerContext* context, const SimpleRequest* /*request*/,
|
||||||
SimpleResponse* response) override {
|
SimpleResponse* response) override {
|
||||||
|
|
@ -70,17 +83,71 @@ class TestServiceImpl : public TestService::Service {
|
||||||
std::string hostname_;
|
std::string hostname_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void RunServer(const int port, const std::string& hostname) {
|
class XdsUpdateHealthServiceImpl : public XdsUpdateHealthService::Service {
|
||||||
std::ostringstream server_address;
|
public:
|
||||||
server_address << "0.0.0.0:" << port;
|
explicit XdsUpdateHealthServiceImpl(
|
||||||
|
HealthCheckServiceImpl* health_check_service)
|
||||||
|
: health_check_service_(health_check_service) {}
|
||||||
|
|
||||||
|
Status SetServing(ServerContext* /* context */, const Empty* /* request */,
|
||||||
|
Empty* /* response */) override {
|
||||||
|
health_check_service_->SetAll(
|
||||||
|
grpc::health::v1::HealthCheckResponse::SERVING);
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status SetNotServing(ServerContext* /* context */, const Empty* /* request */,
|
||||||
|
Empty* /* response */) override {
|
||||||
|
health_check_service_->SetAll(
|
||||||
|
grpc::health::v1::HealthCheckResponse::NOT_SERVING);
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
HealthCheckServiceImpl* const health_check_service_;
|
||||||
|
};
|
||||||
|
|
||||||
|
void RunServer(bool secure_mode, const int port, const int maintenance_port,
|
||||||
|
const std::string& hostname) {
|
||||||
|
std::unique_ptr<Server> xds_enabled_server;
|
||||||
|
std::unique_ptr<Server> server;
|
||||||
TestServiceImpl service(hostname);
|
TestServiceImpl service(hostname);
|
||||||
|
HealthCheckServiceImpl health_check_service;
|
||||||
|
health_check_service.SetStatus(
|
||||||
|
"", grpc::health::v1::HealthCheckResponse::SERVING);
|
||||||
|
health_check_service.SetStatus(
|
||||||
|
"grpc.testing.TestService",
|
||||||
|
grpc::health::v1::HealthCheckResponse::SERVING);
|
||||||
|
health_check_service.SetStatus(
|
||||||
|
"grpc.testing.XdsUpdateHealthService",
|
||||||
|
grpc::health::v1::HealthCheckResponse::SERVING);
|
||||||
|
XdsUpdateHealthServiceImpl update_health_service(&health_check_service);
|
||||||
|
|
||||||
ServerBuilder builder;
|
ServerBuilder builder;
|
||||||
builder.RegisterService(&service);
|
if (secure_mode) {
|
||||||
builder.AddListeningPort(server_address.str(),
|
XdsServerBuilder xds_builder;
|
||||||
grpc::InsecureServerCredentials());
|
xds_builder.RegisterService(&service);
|
||||||
std::unique_ptr<Server> server(builder.BuildAndStart());
|
xds_builder.AddListeningPort(absl::StrCat("0.0.0.0:", port),
|
||||||
gpr_log(GPR_INFO, "Server listening on %s", server_address.str().c_str());
|
grpc::experimental::XdsServerCredentials(
|
||||||
|
grpc::InsecureServerCredentials()));
|
||||||
|
xds_enabled_server = xds_builder.BuildAndStart();
|
||||||
|
gpr_log(GPR_INFO, "Server starting on 0.0.0.0:%d", port);
|
||||||
|
builder.RegisterService(&health_check_service);
|
||||||
|
builder.RegisterService(&update_health_service);
|
||||||
|
builder.AddListeningPort(absl::StrCat("0.0.0.0:", maintenance_port),
|
||||||
|
grpc::InsecureServerCredentials());
|
||||||
|
server = builder.BuildAndStart();
|
||||||
|
gpr_log(GPR_INFO, "Maintenance server listening on 0.0.0.0:%d",
|
||||||
|
maintenance_port);
|
||||||
|
} else {
|
||||||
|
builder.RegisterService(&service);
|
||||||
|
builder.RegisterService(&health_check_service);
|
||||||
|
builder.RegisterService(&update_health_service);
|
||||||
|
builder.AddListeningPort(absl::StrCat("0.0.0.0:", port),
|
||||||
|
grpc::InsecureServerCredentials());
|
||||||
|
server = builder.BuildAndStart();
|
||||||
|
gpr_log(GPR_INFO, "Server listening on 0.0.0.0:%d", port);
|
||||||
|
}
|
||||||
|
|
||||||
server->Wait();
|
server->Wait();
|
||||||
}
|
}
|
||||||
|
|
@ -94,12 +161,18 @@ int main(int argc, char** argv) {
|
||||||
std::cout << "Failed to get hostname, terminating" << std::endl;
|
std::cout << "Failed to get hostname, terminating" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (absl::GetFlag(FLAGS_port) == 0) {
|
int port = absl::GetFlag(FLAGS_port);
|
||||||
|
if (port == 0) {
|
||||||
std::cout << "Invalid port, terminating" << std::endl;
|
std::cout << "Invalid port, terminating" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
int maintenance_port = absl::GetFlag(FLAGS_maintenance_port);
|
||||||
RunServer(absl::GetFlag(FLAGS_port), hostname);
|
if (maintenance_port == 0) {
|
||||||
|
std::cout << "Invalid maintenance port, terminating" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
grpc::EnableDefaultHealthCheckService(false);
|
||||||
|
RunServer(absl::GetFlag(FLAGS_secure_mode), port, maintenance_port, hostname);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue