xDS server serving status: Use a struct to allow more fields to be added in the future (#27242)

pull/27296/head
Yash Tibrewal 3 years ago committed by GitHub
parent b51355c691
commit f26c107651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      include/grpc/grpc.h
  2. 13
      include/grpcpp/xds_server_builder.h
  3. 8
      src/core/ext/xds/xds_server_config_fetcher.cc
  4. 5
      test/cpp/end2end/xds_end2end_test.cc

@ -410,12 +410,18 @@ GRPCAPI void grpc_server_register_completion_queue(grpc_server* server,
grpc_completion_queue* cq,
void* reserved);
// More members might be added in later, so users should take care to memset
// this to 0 before using it.
typedef struct {
grpc_status_code code;
const char* error_message;
} grpc_serving_status_update;
// There might be more methods added later, so users should take care to memset
// this to 0 before using it.
typedef struct {
void (*on_serving_status_update)(void* user_data, const char* uri,
grpc_status_code code,
const char* error_message);
grpc_serving_status_update update);
void* user_data;
} grpc_server_xds_status_notifier;

@ -28,6 +28,10 @@ namespace experimental {
class XdsServerServingStatusNotifierInterface {
public:
struct ServingStatusUpdate {
::grpc::Status status;
};
virtual ~XdsServerServingStatusNotifierInterface() = default;
// \a uri contains the listening target associated with the notification. Note
@ -37,7 +41,8 @@ class XdsServerServingStatusNotifierInterface {
// The API does not provide any guarantees around duplicate updates.
// Status::OK signifies that the server is serving, while a non-OK status
// signifies that the server is not serving.
virtual void OnServingStatusUpdate(std::string uri, grpc::Status status) = 0;
virtual void OnServingStatusUpdate(std::string uri,
ServingStatusUpdate update) = 0;
};
class XdsServerBuilder : public ::grpc::ServerBuilder {
@ -62,13 +67,13 @@ class XdsServerBuilder : public ::grpc::ServerBuilder {
}
static void OnServingStatusUpdate(void* user_data, const char* uri,
grpc_status_code code,
const char* error_message) {
grpc_serving_status_update update) {
if (user_data == nullptr) return;
XdsServerServingStatusNotifierInterface* notifier =
static_cast<XdsServerServingStatusNotifierInterface*>(user_data);
notifier->OnServingStatusUpdate(
uri, grpc::Status(static_cast<StatusCode>(code), error_message));
uri, {grpc::Status(static_cast<StatusCode>(update.code),
update.error_message)});
}
XdsServerServingStatusNotifierInterface* notifier_ = nullptr;

@ -428,7 +428,7 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher {
if (serving_status_notifier_.on_serving_status_update != nullptr) {
serving_status_notifier_.on_serving_status_update(
serving_status_notifier_.user_data, listening_address_.c_str(),
GRPC_STATUS_OK, "");
{GRPC_STATUS_OK, ""});
} else {
gpr_log(GPR_INFO,
"xDS Listener resource obtained; will start serving on %s",
@ -459,7 +459,7 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher {
if (serving_status_notifier_.on_serving_status_update != nullptr) {
serving_status_notifier_.on_serving_status_update(
serving_status_notifier_.user_data, listening_address_.c_str(),
GRPC_STATUS_UNAVAILABLE, grpc_error_std_string(error).c_str());
{GRPC_STATUS_UNAVAILABLE, grpc_error_std_string(error).c_str()});
} else {
gpr_log(
GPR_ERROR,
@ -486,8 +486,8 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher {
if (serving_status_notifier_.on_serving_status_update != nullptr) {
serving_status_notifier_.on_serving_status_update(
serving_status_notifier_.user_data, listening_address_.c_str(),
static_cast<grpc_status_code>(status.raw_code()),
std::string(status.message()).c_str());
{static_cast<grpc_status_code>(status.raw_code()),
std::string(status.message()).c_str()});
}
}

@ -2491,9 +2491,10 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {
class XdsServingStatusNotifier
: public grpc::experimental::XdsServerServingStatusNotifierInterface {
public:
void OnServingStatusUpdate(std::string uri, grpc::Status status) override {
void OnServingStatusUpdate(std::string uri,
ServingStatusUpdate update) override {
grpc_core::MutexLock lock(&mu_);
status_map[uri] = status;
status_map[uri] = update.status;
cond_.Signal();
}

Loading…
Cancel
Save