From afb982981944a4c1a4febece03315aea95192e6a Mon Sep 17 00:00:00 2001 From: ncteisen Date: Thu, 28 Jun 2018 18:04:24 -0700 Subject: [PATCH] Fix the muddled linkeage of channelz --- BUILD | 2 + CMakeLists.txt | 6 ++ Makefile | 6 ++ build.yaml | 2 + config.m4 | 1 + config.w32 | 1 + gRPC-C++.podspec | 1 + gRPC-Core.podspec | 3 + grpc.gemspec | 2 + grpc.gyp | 4 ++ package.xml | 2 + .../client_channel/client_channel_channelz.cc | 62 +++++++++++++++++++ .../client_channel/client_channel_channelz.h | 55 ++++++++++++++++ .../chttp2/client/insecure/channel_create.cc | 10 +-- .../client/secure/secure_channel_create.cc | 4 +- src/core/lib/channel/channelz.cc | 37 +++++------ src/core/lib/channel/channelz.h | 27 ++++++-- src/core/lib/surface/channel.cc | 14 ++++- src/python/grpcio/grpc_core_dependencies.py | 1 + tools/doxygen/Doxyfile.core.internal | 2 + .../generated/sources_and_headers.json | 3 + 21 files changed, 216 insertions(+), 29 deletions(-) create mode 100644 src/core/ext/filters/client_channel/client_channel_channelz.cc create mode 100644 src/core/ext/filters/client_channel/client_channel_channelz.h diff --git a/BUILD b/BUILD index 6db179fd3f4..294ce46d413 100644 --- a/BUILD +++ b/BUILD @@ -1028,6 +1028,7 @@ grpc_cc_library( "src/core/ext/filters/client_channel/backup_poller.cc", "src/core/ext/filters/client_channel/channel_connectivity.cc", "src/core/ext/filters/client_channel/client_channel.cc", + "src/core/ext/filters/client_channel/client_channel_channelz.cc", "src/core/ext/filters/client_channel/client_channel_factory.cc", "src/core/ext/filters/client_channel/client_channel_plugin.cc", "src/core/ext/filters/client_channel/connector.cc", @@ -1050,6 +1051,7 @@ grpc_cc_library( hdrs = [ "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/client_channel.h", + "src/core/ext/filters/client_channel/client_channel_channelz.h", "src/core/ext/filters/client_channel/client_channel_factory.h", "src/core/ext/filters/client_channel/connector.h", "src/core/ext/filters/client_channel/http_connect_handshaker.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b8e4f919c9..7222894af62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1187,6 +1187,7 @@ add_library(grpc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc + src/core/ext/filters/client_channel/client_channel_channelz.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc src/core/ext/filters/client_channel/connector.cc @@ -1523,6 +1524,7 @@ add_library(grpc_cronet src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc + src/core/ext/filters/client_channel/client_channel_channelz.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc src/core/ext/filters/client_channel/connector.cc @@ -1881,6 +1883,7 @@ add_library(grpc_test_util src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc + src/core/ext/filters/client_channel/client_channel_channelz.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc src/core/ext/filters/client_channel/connector.cc @@ -2188,6 +2191,7 @@ add_library(grpc_test_util_unsecure src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc + src/core/ext/filters/client_channel/client_channel_channelz.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc src/core/ext/filters/client_channel/connector.cc @@ -2508,6 +2512,7 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc + src/core/ext/filters/client_channel/client_channel_channelz.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc src/core/ext/filters/client_channel/connector.cc @@ -3315,6 +3320,7 @@ add_library(grpc++_cronet src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc + src/core/ext/filters/client_channel/client_channel_channelz.cc src/core/ext/filters/client_channel/client_channel_factory.cc src/core/ext/filters/client_channel/client_channel_plugin.cc src/core/ext/filters/client_channel/connector.cc diff --git a/Makefile b/Makefile index c0c3d239ee5..47c9dc7ccdf 100644 --- a/Makefile +++ b/Makefile @@ -3633,6 +3633,7 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ + src/core/ext/filters/client_channel/client_channel_channelz.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ src/core/ext/filters/client_channel/connector.cc \ @@ -3968,6 +3969,7 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ + src/core/ext/filters/client_channel/client_channel_channelz.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ src/core/ext/filters/client_channel/connector.cc \ @@ -4324,6 +4326,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ + src/core/ext/filters/client_channel/client_channel_channelz.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ src/core/ext/filters/client_channel/connector.cc \ @@ -4622,6 +4625,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ + src/core/ext/filters/client_channel/client_channel_channelz.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ src/core/ext/filters/client_channel/connector.cc \ @@ -4920,6 +4924,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ + src/core/ext/filters/client_channel/client_channel_channelz.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ src/core/ext/filters/client_channel/connector.cc \ @@ -5715,6 +5720,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ + src/core/ext/filters/client_channel/client_channel_channelz.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ src/core/ext/filters/client_channel/connector.cc \ diff --git a/build.yaml b/build.yaml index c8d4e6109d2..3067ca9161d 100644 --- a/build.yaml +++ b/build.yaml @@ -564,6 +564,7 @@ filegroups: headers: - src/core/ext/filters/client_channel/backup_poller.h - src/core/ext/filters/client_channel/client_channel.h + - src/core/ext/filters/client_channel/client_channel_channelz.h - src/core/ext/filters/client_channel/client_channel_factory.h - src/core/ext/filters/client_channel/connector.h - src/core/ext/filters/client_channel/http_connect_handshaker.h @@ -586,6 +587,7 @@ filegroups: - src/core/ext/filters/client_channel/backup_poller.cc - src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/client_channel.cc + - src/core/ext/filters/client_channel/client_channel_channelz.cc - src/core/ext/filters/client_channel/client_channel_factory.cc - src/core/ext/filters/client_channel/client_channel_plugin.cc - src/core/ext/filters/client_channel/connector.cc diff --git a/config.m4 b/config.m4 index d4af0cfd91a..c277ccafc8c 100644 --- a/config.m4 +++ b/config.m4 @@ -332,6 +332,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ + src/core/ext/filters/client_channel/client_channel_channelz.cc \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ src/core/ext/filters/client_channel/connector.cc \ diff --git a/config.w32 b/config.w32 index 0f219d34964..2857781dd57 100644 --- a/config.w32 +++ b/config.w32 @@ -307,6 +307,7 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\backup_poller.cc " + "src\\core\\ext\\filters\\client_channel\\channel_connectivity.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel.cc " + + "src\\core\\ext\\filters\\client_channel\\client_channel_channelz.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel_factory.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel_plugin.cc " + "src\\core\\ext\\filters\\client_channel\\connector.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 4d574fd4d6a..57d58cc4400 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -317,6 +317,7 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', + 'src/core/ext/filters/client_channel/client_channel_channelz.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', 'src/core/ext/filters/client_channel/connector.h', 'src/core/ext/filters/client_channel/http_connect_handshaker.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 2789d15ec85..997617c5307 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -328,6 +328,7 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', + 'src/core/ext/filters/client_channel/client_channel_channelz.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', 'src/core/ext/filters/client_channel/connector.h', 'src/core/ext/filters/client_channel/http_connect_handshaker.h', @@ -753,6 +754,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', + 'src/core/ext/filters/client_channel/client_channel_channelz.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', 'src/core/ext/filters/client_channel/connector.cc', @@ -916,6 +918,7 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', + 'src/core/ext/filters/client_channel/client_channel_channelz.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', 'src/core/ext/filters/client_channel/connector.h', 'src/core/ext/filters/client_channel/http_connect_handshaker.h', diff --git a/grpc.gemspec b/grpc.gemspec index 6d0a9ced513..b69d5a7c6fc 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -265,6 +265,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel.h ) + s.files += %w( src/core/ext/filters/client_channel/client_channel_channelz.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.h ) s.files += %w( src/core/ext/filters/client_channel/connector.h ) s.files += %w( src/core/ext/filters/client_channel/http_connect_handshaker.h ) @@ -693,6 +694,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/backup_poller.cc ) s.files += %w( src/core/ext/filters/client_channel/channel_connectivity.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel.cc ) + s.files += %w( src/core/ext/filters/client_channel/client_channel_channelz.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel_plugin.cc ) s.files += %w( src/core/ext/filters/client_channel/connector.cc ) diff --git a/grpc.gyp b/grpc.gyp index 6b3efe5c12d..0db6afe4682 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -524,6 +524,7 @@ 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', + 'src/core/ext/filters/client_channel/client_channel_channelz.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', 'src/core/ext/filters/client_channel/connector.cc', @@ -783,6 +784,7 @@ 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', + 'src/core/ext/filters/client_channel/client_channel_channelz.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', 'src/core/ext/filters/client_channel/connector.cc', @@ -1015,6 +1017,7 @@ 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', + 'src/core/ext/filters/client_channel/client_channel_channelz.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', 'src/core/ext/filters/client_channel/connector.cc', @@ -1259,6 +1262,7 @@ 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', + 'src/core/ext/filters/client_channel/client_channel_channelz.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', 'src/core/ext/filters/client_channel/connector.cc', diff --git a/package.xml b/package.xml index 55891674744..a9dc2dc79ac 100644 --- a/package.xml +++ b/package.xml @@ -270,6 +270,7 @@ + @@ -698,6 +699,7 @@ + diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.cc b/src/core/ext/filters/client_channel/client_channel_channelz.cc new file mode 100644 index 00000000000..df78dd59323 --- /dev/null +++ b/src/core/ext/filters/client_channel/client_channel_channelz.cc @@ -0,0 +1,62 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/ext/filters/client_channel/client_channel_channelz.h" +#include "src/core/lib/gpr/useful.h" + +namespace grpc_core { +namespace channelz { + +static void* client_channel_channelz_copy(void* p) { return p; } + +static void client_channel_channelz_destroy(void* p) {} + +static int client_channel_channelz_cmp(void* a, void* b) { + return GPR_ICMP(a, b); +} + +static const grpc_arg_pointer_vtable client_channel_channelz_vtable = { + client_channel_channelz_copy, client_channel_channelz_destroy, + client_channel_channelz_cmp}; + +bool ClientChannelNode::GetConnectivityState(grpc_connectivity_state* state) { + if (channel()) { + *state = grpc_channel_check_connectivity_state(channel(), false); + } else { + *state = GRPC_CHANNEL_SHUTDOWN; + } + return true; +} + +grpc_arg ClientChannelNode::CreateArg() { + return grpc_channel_arg_pointer_create( + const_cast(GRPC_ARG_CHANNELZ_CHANNEL_NODE_CREATION_FUNC), + reinterpret_cast(MakeClientChannelNode), + &client_channel_channelz_vtable); +} + +RefCountedPtr MakeClientChannelNode( + grpc_channel* channel, size_t channel_tracer_max_nodes) { + return RefCountedPtr( + New(channel, channel_tracer_max_nodes)); +} + +} // namespace channelz +} // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.h b/src/core/ext/filters/client_channel/client_channel_channelz.h new file mode 100644 index 00000000000..7d05cda7da5 --- /dev/null +++ b/src/core/ext/filters/client_channel/client_channel_channelz.h @@ -0,0 +1,55 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_CHANNELZ_H +#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_CHANNELZ_H + +#include + +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/channel/channelz.h" + +namespace grpc_core { +namespace channelz { + +// Subtype of ChannelNode that overrides and provides client_channel specific +// functionality like querying for connectivity_state and subchannel data. +class ClientChannelNode : public ChannelNode { + public: + ClientChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes) + : ChannelNode(channel, channel_tracer_max_nodes) {} + virtual ~ClientChannelNode() {} + + // Override this functionality since client_channels have a notion of + // channel connectivity. + bool GetConnectivityState(grpc_connectivity_state* state) override; + + // Helper to create a channel arg to ensure this type of ChannelNode is + // created. + static grpc_arg CreateArg(); +}; + +RefCountedPtr MakeClientChannelNode( + grpc_channel* channel, size_t channel_tracer_max_nodes); + +grpc_arg BlahBlah(); + +} // namespace channelz +} // namespace grpc_core + +#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_CHANNELZ_H */ diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index e6c8c382607..420629f6b79 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -26,6 +26,7 @@ #include #include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/ext/filters/client_channel/client_channel_channelz.h" #include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/ext/transport/chttp2/client/authority.h" #include "src/core/ext/transport/chttp2/client/chttp2_connector.h" @@ -92,10 +93,11 @@ grpc_channel* grpc_insecure_channel_create(const char* target, "grpc_insecure_channel_create(target=%s, args=%p, reserved=%p)", 3, (target, args, reserved)); GPR_ASSERT(reserved == nullptr); - // Add channel arg containing the client channel factory. - grpc_arg arg = - grpc_client_channel_factory_create_channel_arg(&client_channel_factory); - grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1); + grpc_arg args_to_add[] = { + grpc_client_channel_factory_create_channel_arg(&client_channel_factory), + grpc_core::channelz::ClientChannelNode::CreateArg()}; + grpc_channel_args* new_args = grpc_channel_args_copy_and_add( + args, args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Create channel. grpc_channel* channel = client_channel_factory_create_channel( &client_channel_factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index 5ce73a95d76..82691d4e251 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -26,6 +26,7 @@ #include #include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/ext/filters/client_channel/client_channel_channelz.h" #include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/ext/filters/client_channel/uri_parser.h" #include "src/core/ext/transport/chttp2/client/chttp2_connector.h" @@ -213,7 +214,8 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, // credentials. grpc_arg args_to_add[] = { grpc_client_channel_factory_create_channel_arg(&client_channel_factory), - grpc_channel_credentials_to_arg(creds)}; + grpc_channel_credentials_to_arg(creds), + grpc_core::channelz::ClientChannelNode::CreateArg()}; grpc_channel_args* new_args = grpc_channel_args_copy_and_add( args, args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Create channel. diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index a49271c3a18..62bc4d43306 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -109,15 +109,8 @@ void ChannelNode::RecordCallStarted() { (gpr_atm)ExecCtx::Get()->Now()); } -grpc_connectivity_state ChannelNode::GetConnectivityState() { - if (channel_ == nullptr) { - return GRPC_CHANNEL_SHUTDOWN; - } else { - // TODO(ncteisen): re-enable this once we have cleaned up all of the - // internal dependency issues. - // return grpc_channel_check_connectivity_state(channel_, false); - return GRPC_CHANNEL_IDLE; - } +bool ChannelNode::GetConnectivityState(grpc_connectivity_state* state) { + return false; } char* ChannelNode::RenderJSON() { @@ -140,15 +133,17 @@ char* ChannelNode::RenderJSON() { json = data; json_iterator = nullptr; // create and fill the connectivity state child. - grpc_connectivity_state connectivity_state = GetConnectivityState(); - json_iterator = grpc_json_create_child(json_iterator, json, "state", nullptr, - GRPC_JSON_OBJECT, false); - json = json_iterator; - grpc_json_create_child(nullptr, json, "state", - grpc_connectivity_state_name(connectivity_state), - GRPC_JSON_STRING, false); - // reset the parent to be the data object. - json = data; + grpc_connectivity_state connectivity_state; + if (GetConnectivityState(&connectivity_state)) { + json_iterator = grpc_json_create_child(json_iterator, json, "state", + nullptr, GRPC_JSON_OBJECT, false); + json = json_iterator; + grpc_json_create_child(nullptr, json, "state", + grpc_connectivity_state_name(connectivity_state), + GRPC_JSON_STRING, false); + // reset the parent to be the data object. + json = data; + } json_iterator = grpc_json_create_child( json_iterator, json, "target", target_.get(), GRPC_JSON_STRING, false); // fill in the channel trace if applicable @@ -184,5 +179,11 @@ char* ChannelNode::RenderJSON() { return json_str; } +RefCountedPtr MakeChannelNode(grpc_channel* channel, + size_t channel_tracer_max_nodes) { + return MakeRefCounted( + channel, channel_tracer_max_nodes); +} + } // namespace channelz } // namespace grpc_core diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h index 2aad1e82f48..5c91658dd18 100644 --- a/src/core/lib/channel/channelz.h +++ b/src/core/lib/channel/channelz.h @@ -31,6 +31,10 @@ #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/json/json.h" +// Channel arg key for client channel factory. +#define GRPC_ARG_CHANNELZ_CHANNEL_NODE_CREATION_FUNC \ + "grpc.channelz_channel_node_creation_func" + namespace grpc_core { namespace channelz { @@ -41,7 +45,7 @@ class ChannelNodePeer; class ChannelNode : public RefCounted { public: ChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes); - ~ChannelNode(); + virtual ~ChannelNode(); void RecordCallStarted(); void RecordCallFailed() { @@ -53,6 +57,13 @@ class ChannelNode : public RefCounted { char* RenderJSON(); + // helper for getting connectivity state. It is virtual because it allows + // the client_channel code to live in ext/ instead of lib/ + // + // returns true if the channel has a notion of a connectivity state. In that + // case it also sets state to the correct connectivity state. + virtual bool GetConnectivityState(grpc_connectivity_state* state); + ChannelTrace* trace() { return trace_.get(); } void set_channel_destroyed() { @@ -62,13 +73,13 @@ class ChannelNode : public RefCounted { intptr_t channel_uuid() { return channel_uuid_; } + protected: + grpc_channel* channel() { return channel_; } + private: // testing peer friend. friend class testing::ChannelNodePeer; - // helper for getting connectivity state. - grpc_connectivity_state GetConnectivityState(); - grpc_channel* channel_ = nullptr; UniquePtr target_; gpr_atm calls_started_ = 0; @@ -79,6 +90,14 @@ class ChannelNode : public RefCounted { ManualConstructor trace_; }; +// Creation functions + +typedef RefCountedPtr (*ChannelNodeCreationFunc)(grpc_channel*, + size_t); + +RefCountedPtr MakeChannelNode(grpc_channel* channel, + size_t channel_tracer_max_nodes); + } // namespace channelz } // namespace grpc_core diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index d5d75fcb2aa..a17fde015f2 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -105,6 +105,10 @@ grpc_channel* grpc_channel_create_with_builder( channel->is_client = grpc_channel_stack_type_is_client(channel_stack_type); size_t channel_tracer_max_nodes = 0; // default to off bool channelz_enabled = false; + // this creates the default ChannelNode. Different types of channels may + // override this to ensure a correct ChannelNode is created. + grpc_core::channelz::ChannelNodeCreationFunc channel_node_create_func = + grpc_core::channelz::MakeChannelNode; gpr_mu_init(&channel->registered_call_mu); channel->registered_calls = nullptr; @@ -145,14 +149,20 @@ grpc_channel* grpc_channel_create_with_builder( (size_t)grpc_channel_arg_get_integer(&args->args[i], options); } else if (0 == strcmp(args->args[i].key, GRPC_ARG_ENABLE_CHANNELZ)) { channelz_enabled = grpc_channel_arg_get_bool(&args->args[i], false); + } else if (0 == strcmp(args->args[i].key, + GRPC_ARG_CHANNELZ_CHANNEL_NODE_CREATION_FUNC)) { + GPR_ASSERT(args->args[i].type == GRPC_ARG_POINTER); + GPR_ASSERT(args->args[i].value.pointer.p != nullptr); + channel_node_create_func = + reinterpret_cast( + args->args[i].value.pointer.p); } } grpc_channel_args_destroy(args); if (channelz_enabled) { channel->channelz_channel = - grpc_core::MakeRefCounted( - channel, channel_tracer_max_nodes); + channel_node_create_func(channel, channel_tracer_max_nodes); channel->channelz_channel->trace()->AddTraceEvent( grpc_core::channelz::ChannelTrace::Severity::Info, grpc_slice_from_static_string("Channel created")); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 1746020b724..49185cc6487 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -306,6 +306,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', + 'src/core/ext/filters/client_channel/client_channel_channelz.cc', 'src/core/ext/filters/client_channel/client_channel_factory.cc', 'src/core/ext/filters/client_channel/client_channel_plugin.cc', 'src/core/ext/filters/client_channel/connector.cc', diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 397b8e0c961..1a5dfb902b4 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -872,6 +872,8 @@ src/core/ext/filters/client_channel/backup_poller.h \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ src/core/ext/filters/client_channel/client_channel.h \ +src/core/ext/filters/client_channel/client_channel_channelz.cc \ +src/core/ext/filters/client_channel/client_channel_channelz.h \ src/core/ext/filters/client_channel/client_channel_factory.cc \ src/core/ext/filters/client_channel/client_channel_factory.h \ src/core/ext/filters/client_channel/client_channel_plugin.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 5610dfbf66e..7953fa37723 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9873,6 +9873,7 @@ "headers": [ "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/client_channel.h", + "src/core/ext/filters/client_channel/client_channel_channelz.h", "src/core/ext/filters/client_channel/client_channel_factory.h", "src/core/ext/filters/client_channel/connector.h", "src/core/ext/filters/client_channel/http_connect_handshaker.h", @@ -9901,6 +9902,8 @@ "src/core/ext/filters/client_channel/channel_connectivity.cc", "src/core/ext/filters/client_channel/client_channel.cc", "src/core/ext/filters/client_channel/client_channel.h", + "src/core/ext/filters/client_channel/client_channel_channelz.cc", + "src/core/ext/filters/client_channel/client_channel_channelz.h", "src/core/ext/filters/client_channel/client_channel_factory.cc", "src/core/ext/filters/client_channel/client_channel_factory.h", "src/core/ext/filters/client_channel/client_channel_plugin.cc",