1# Copyright 2018 The gRPC Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Channelz debug service implementation in gRPC Python.""" 15 16import sys 17import grpc 18 19import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc 20from grpc_channelz.v1._servicer import ChannelzServicer 21 22_add_channelz_servicer_doc = """Add Channelz servicer to a server. 23 24Channelz servicer is in charge of 25pulling information from C-Core for entire process. It will allow the 26server to response to Channelz queries. 27 28The Channelz statistic is enabled by default inside C-Core. Whether the 29statistic is enabled or not is isolated from adding Channelz servicer. 30That means you can query Channelz info with a Channelz-disabled channel, 31and you can add Channelz servicer to a Channelz-disabled server. 32 33The Channelz statistic can be enabled or disabled by channel option 34'grpc.enable_channelz'. Set to 1 to enable, set to 0 to disable. 35 36This is an EXPERIMENTAL API. 37 38Args: 39 server: A gRPC server to which Channelz service will be added. 40""" 41 42if sys.version_info[0] >= 3 and sys.version_info[1] >= 6: 43 from grpc_channelz.v1 import _async as aio 44 45 def add_channelz_servicer(server): 46 47 if isinstance(server, grpc.experimental.aio.Server): 48 _channelz_pb2_grpc.add_ChannelzServicer_to_server( 49 aio.ChannelzServicer(), server) 50 else: 51 _channelz_pb2_grpc.add_ChannelzServicer_to_server( 52 ChannelzServicer(), server) 53 54 add_channelz_servicer.__doc__ = _add_channelz_servicer_doc 55 56 __all__ = [ 57 "aio", 58 "add_channelz_servicer", 59 "ChannelzServicer", 60 ] 61 62else: 63 64 def add_channelz_servicer(server): 65 _channelz_pb2_grpc.add_ChannelzServicer_to_server( 66 ChannelzServicer(), server) 67 68 add_channelz_servicer.__doc__ = _add_channelz_servicer_doc 69 70 __all__ = [ 71 "add_channelz_servicer", 72 "ChannelzServicer", 73 ] 74