1# Copyright 2021 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 16from envoy.service.status.v3 import csds_pb2 17from envoy.service.status.v3 import csds_pb2_grpc 18from google.protobuf import json_format 19from grpc._cython import cygrpc 20 21 22class ClientStatusDiscoveryServiceServicer( 23 csds_pb2_grpc.ClientStatusDiscoveryServiceServicer 24): 25 """CSDS Servicer works for both the sync API and asyncio API.""" 26 27 @staticmethod 28 def FetchClientStatus(request, unused_context): 29 return csds_pb2.ClientStatusResponse.FromString( 30 cygrpc.dump_xds_configs() 31 ) 32 33 @staticmethod 34 def StreamClientStatus(request_iterator, context): 35 for request in request_iterator: 36 yield ClientStatusDiscoveryServiceServicer.FetchClientStatus( 37 request, context 38 ) 39 40 41def add_csds_servicer(server): 42 """Register CSDS servicer to a server. 43 44 CSDS is part of xDS protocol used to expose in-effective traffic 45 configuration (or xDS resources). It focuses on simplify the debugging of 46 unexpected routing behaviors, which could be due to a misconfiguration, 47 unhealthy backends or issues in the control or data plane. 48 49 Args: 50 server: A gRPC server to which the CSDS service will be added. 51 """ 52 csds_pb2_grpc.add_ClientStatusDiscoveryServiceServicer_to_server( 53 ClientStatusDiscoveryServiceServicer(), server 54 ) 55 56 57__all__ = ["ClientStatusDiscoveryServiceServicer", "add_csds_servicer"] 58