| 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 |
|
| 16 |
import sys |
| 17 |
|
| 18 |
import grpc |
| 19 |
from grpc_channelz.v1._servicer import ChannelzServicer |
| 20 |
import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc |
| 21 |
|
| 22 |
_add_channelz_servicer_doc = """Add Channelz servicer to a server. |
| 23 |
|
| 24 |
Channelz servicer is in charge of |
| 25 |
pulling information from C-Core for entire process. It will allow the |
| 26 |
server to response to Channelz queries. |
| 27 |
|
| 28 |
The Channelz statistic is enabled by default inside C-Core. Whether the |
| 29 |
statistic is enabled or not is isolated from adding Channelz servicer. |
| 30 |
That means you can query Channelz info with a Channelz-disabled channel, |
| 31 |
and you can add Channelz servicer to a Channelz-disabled server. |
| 32 |
|
| 33 |
The 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 |
|
| 36 |
This is an EXPERIMENTAL API. |
| 37 |
|
| 38 |
Args: |
| 39 |
server: A gRPC server to which Channelz service will be added. |
| 40 |
""" |
| 41 |
|
| 42 |
if 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 |
|
| 62 |
else: |
| 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 |
] |