...
1
18
19
20 package service
21
22 import (
23 "context"
24
25 channelzgrpc "google.golang.org/grpc/channelz/grpc_channelz_v1"
26 channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
27
28 "google.golang.org/grpc"
29 "google.golang.org/grpc/channelz/internal/protoconv"
30 "google.golang.org/grpc/internal/channelz"
31 )
32
33 func init() {
34 channelz.TurnOn()
35 }
36
37
38
39
40
41
42 func RegisterChannelzServiceToServer(s grpc.ServiceRegistrar) {
43 channelzgrpc.RegisterChannelzServer(s, newCZServer())
44 }
45
46 func newCZServer() channelzgrpc.ChannelzServer {
47 return &serverImpl{}
48 }
49
50 type serverImpl struct {
51 channelzgrpc.UnimplementedChannelzServer
52 }
53
54 func (s *serverImpl) GetChannel(ctx context.Context, req *channelzpb.GetChannelRequest) (*channelzpb.GetChannelResponse, error) {
55 ch, err := protoconv.GetChannel(req.GetChannelId())
56 if err != nil {
57 return nil, err
58 }
59 return &channelzpb.GetChannelResponse{Channel: ch}, nil
60 }
61
62 func (s *serverImpl) GetTopChannels(ctx context.Context, req *channelzpb.GetTopChannelsRequest) (*channelzpb.GetTopChannelsResponse, error) {
63 resp := &channelzpb.GetTopChannelsResponse{}
64 resp.Channel, resp.End = protoconv.GetTopChannels(req.GetStartChannelId(), int(req.GetMaxResults()))
65 return resp, nil
66 }
67
68 func (s *serverImpl) GetServer(ctx context.Context, req *channelzpb.GetServerRequest) (*channelzpb.GetServerResponse, error) {
69 srv, err := protoconv.GetServer(req.GetServerId())
70 if err != nil {
71 return nil, err
72 }
73 return &channelzpb.GetServerResponse{Server: srv}, nil
74 }
75
76 func (s *serverImpl) GetServers(ctx context.Context, req *channelzpb.GetServersRequest) (*channelzpb.GetServersResponse, error) {
77 resp := &channelzpb.GetServersResponse{}
78 resp.Server, resp.End = protoconv.GetServers(req.GetStartServerId(), int(req.GetMaxResults()))
79 return resp, nil
80 }
81
82 func (s *serverImpl) GetSubchannel(ctx context.Context, req *channelzpb.GetSubchannelRequest) (*channelzpb.GetSubchannelResponse, error) {
83 subChan, err := protoconv.GetSubChannel(req.GetSubchannelId())
84 if err != nil {
85 return nil, err
86 }
87 return &channelzpb.GetSubchannelResponse{Subchannel: subChan}, nil
88 }
89
90 func (s *serverImpl) GetServerSockets(ctx context.Context, req *channelzpb.GetServerSocketsRequest) (*channelzpb.GetServerSocketsResponse, error) {
91 resp := &channelzpb.GetServerSocketsResponse{}
92 resp.SocketRef, resp.End = protoconv.GetServerSockets(req.GetServerId(), req.GetStartSocketId(), int(req.GetMaxResults()))
93 return resp, nil
94 }
95
96 func (s *serverImpl) GetSocket(ctx context.Context, req *channelzpb.GetSocketRequest) (*channelzpb.GetSocketResponse, error) {
97 socket, err := protoconv.GetSocket(req.GetSocketId())
98 if err != nil {
99 return nil, err
100 }
101 return &channelzpb.GetSocketResponse{Socket: socket}, nil
102 }
103
View as plain text