diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 2f507f51ae2..f4408e111f5 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -414,7 +414,7 @@ GRPCAPI void grpc_server_register_completion_queue(grpc_server* server, // 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_change)(void* user_data, const char* uri, + void (*on_serving_status_update)(void* user_data, const char* uri, grpc_status_code code, const char* error_message); void* user_data; diff --git a/include/grpcpp/xds_server_builder.h b/include/grpcpp/xds_server_builder.h index 0661c3061c6..076c377f781 100644 --- a/include/grpcpp/xds_server_builder.h +++ b/include/grpcpp/xds_server_builder.h @@ -32,9 +32,12 @@ class XdsServerServingStatusNotifierInterface { // \a uri contains the listening target associated with the notification. Note // that a single target provided to XdsServerBuilder can get resolved to - // multiple listening addresses. Status::OK signifies that the server is - // serving, while a non-OK status signifies that the server is not serving. - virtual void OnServingStatusChange(std::string uri, grpc::Status status) = 0; + // multiple listening addresses. + // The callback is invoked each time there is an update to the serving status. + // 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; }; class XdsServerBuilder : public ::grpc::ServerBuilder { @@ -53,18 +56,18 @@ class XdsServerBuilder : public ::grpc::ServerBuilder { ChannelArguments args = ServerBuilder::BuildChannelArgs(); grpc_channel_args c_channel_args = args.c_channel_args(); grpc_server_config_fetcher* fetcher = grpc_server_config_fetcher_xds_create( - {OnServingStatusChange, notifier_}, &c_channel_args); + {OnServingStatusUpdate, notifier_}, &c_channel_args); if (fetcher != nullptr) set_fetcher(fetcher); return args; } - static void OnServingStatusChange(void* user_data, const char* uri, + static void OnServingStatusUpdate(void* user_data, const char* uri, grpc_status_code code, const char* error_message) { if (user_data == nullptr) return; XdsServerServingStatusNotifierInterface* notifier = static_cast(user_data); - notifier->OnServingStatusChange( + notifier->OnServingStatusUpdate( uri, grpc::Status(static_cast(code), error_message)); } diff --git a/src/core/ext/xds/xds_server_config_fetcher.cc b/src/core/ext/xds/xds_server_config_fetcher.cc index f856704afbb..578daeaf95e 100644 --- a/src/core/ext/xds/xds_server_config_fetcher.cc +++ b/src/core/ext/xds/xds_server_config_fetcher.cc @@ -425,8 +425,8 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher { return; } if (filter_chain_match_manager_ == nullptr) { - if (serving_status_notifier_.on_serving_status_change != nullptr) { - serving_status_notifier_.on_serving_status_change( + 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, ""); } else { @@ -456,8 +456,8 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher { this, grpc_error_std_string(error).c_str(), listening_address_.c_str()); } else { - if (serving_status_notifier_.on_serving_status_change != nullptr) { - serving_status_notifier_.on_serving_status_change( + 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()); } else { @@ -483,8 +483,8 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher { server_config_watcher_->StopServing(); filter_chain_match_manager_.reset(); } - if (serving_status_notifier_.on_serving_status_change != nullptr) { - serving_status_notifier_.on_serving_status_change( + 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(status.raw_code()), std::string(status.message()).c_str()); diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index 381c0404536..48f3461dd19 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -405,7 +405,7 @@ cdef extern from "grpc/grpc.h": grpc_server* server, grpc_server_config_fetcher* config_fetcher) nogil ctypedef struct grpc_server_xds_status_notifier: - void (*on_serving_status_change)(void* user_data, const char* uri, + void (*on_serving_status_update)(void* user_data, const char* uri, grpc_status_code code, const char* error_message) void* user_data; diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi index 1b1cfce9448..d3caf3a5b84 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi @@ -26,7 +26,7 @@ cdef class Server: cdef _ChannelArgs channel_args = _ChannelArgs(arguments) self.c_server = grpc_server_create(channel_args.c_args(), NULL) cdef grpc_server_xds_status_notifier notifier - notifier.on_serving_status_change = NULL + notifier.on_serving_status_update = NULL notifier.user_data = NULL if xds: grpc_server_set_config_fetcher(self.c_server, diff --git a/test/cpp/end2end/xds_end2end_test.cc b/test/cpp/end2end/xds_end2end_test.cc index e35125380d5..2062c44e1b2 100644 --- a/test/cpp/end2end/xds_end2end_test.cc +++ b/test/cpp/end2end/xds_end2end_test.cc @@ -2264,7 +2264,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam { class XdsServingStatusNotifier : public grpc::experimental::XdsServerServingStatusNotifierInterface { public: - void OnServingStatusChange(std::string uri, grpc::Status status) override { + void OnServingStatusUpdate(std::string uri, grpc::Status status) override { grpc_core::MutexLock lock(&mu_); status_map[uri] = status; cond_.Signal();