Debian Codegraph @

src/python/grpcio_csds/grpc_csds/__init__.py

raw
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
16 from envoy.service.status.v3 import csds_pb2
17 from envoy.service.status.v3 import csds_pb2_grpc
18 from google.protobuf import json_format
19 from grpc._cython import cygrpc
20
21
22 class ClientStatusDiscoveryServiceServicer(
23 csds_pb2_grpc.ClientStatusDiscoveryServiceServicer):
24 """CSDS Servicer works for both the sync API and asyncio API."""
25
26 @staticmethod
27 def FetchClientStatus(request, unused_context):
28 client_config = csds_pb2.ClientConfig.FromString(
29 cygrpc.dump_xds_configs())
30 response = csds_pb2.ClientStatusResponse()
31 response.config.append(client_config)
32 return response
33
34 @staticmethod
35 def StreamClientStatus(request_iterator, context):
36 for request in request_iterator:
37 yield ClientStatusDiscoveryServiceServicer.FetchClientStatus(
38 request, context)
39
40
41 def 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 __all__ = ['ClientStatusDiscoveryServiceServicer', 'add_csds_servicer']