MCPcopy
hub / github.com/grpc/grpc-go / channelToProto

Function channelToProto

channelz/internal/protoconv/channel.go:85–115  ·  view source on GitHub ↗
(cm *channelz.Channel)

Source from the content-addressed store, hash-verified

83}
84
85func channelToProto(cm *channelz.Channel) *channelzpb.Channel {
86 c := &channelzpb.Channel{}
87 c.Ref = &channelzpb.ChannelRef{ChannelId: cm.ID, Name: cm.RefName}
88
89 c.Data = &channelzpb.ChannelData{
90 State: connectivityStateToProto(cm.ChannelMetrics.State.Load()),
91 Target: strFromPointer(cm.ChannelMetrics.Target.Load()),
92 CallsStarted: cm.ChannelMetrics.CallsStarted.Load(),
93 CallsSucceeded: cm.ChannelMetrics.CallsSucceeded.Load(),
94 CallsFailed: cm.ChannelMetrics.CallsFailed.Load(),
95 }
96 if ts := timestamppb.New(time.Unix(0, cm.ChannelMetrics.LastCallStartedTimestamp.Load())); ts.IsValid() {
97 c.Data.LastCallStartedTimestamp = ts
98 }
99 ncs := cm.NestedChans()
100 nestedChans := make([]*channelzpb.ChannelRef, 0, len(ncs))
101 for id, ref := range ncs {
102 nestedChans = append(nestedChans, &channelzpb.ChannelRef{ChannelId: id, Name: ref})
103 }
104 c.ChannelRef = nestedChans
105
106 scs := cm.SubChans()
107 subChans := make([]*channelzpb.SubchannelRef, 0, len(scs))
108 for id, ref := range scs {
109 subChans = append(subChans, &channelzpb.SubchannelRef{SubchannelId: id, Name: ref})
110 }
111 c.SubchannelRef = subChans
112
113 c.Data.Trace = channelTraceToProto(cm.Trace())
114 return c
115}
116
117// GetTopChannels returns the protobuf representation of the channels starting
118// at startID (max of len), and returns end=true if no top channels exist with

Callers 2

GetTopChannelsFunction · 0.85
GetChannelFunction · 0.85

Calls 7

connectivityStateToProtoFunction · 0.85
channelTraceToProtoFunction · 0.85
NestedChansMethod · 0.80
SubChansMethod · 0.80
strFromPointerFunction · 0.70
LoadMethod · 0.45
TraceMethod · 0.45

Tested by

no test coverage detected