@@ -43,13 +43,17 @@ type Channel struct {
4343 // Non-zero traceRefCount means the trace of this channel cannot be deleted.
4444 traceRefCount int32
4545
46+ // ChannelMetrics holds connectivity state, target and call metrics for the
47+ // channel within channelz.
4648 ChannelMetrics ChannelMetrics
4749}
4850
4951// Implemented to make Channel implement the Identifier interface used for
5052// nesting.
5153func (c * Channel ) channelzIdentifier () {}
5254
55+ // String returns a string representation of the Channel, including its parent
56+ // entity and ID.
5357func (c * Channel ) String () string {
5458 if c .Parent == nil {
5559 return fmt .Sprintf ("Channel #%d" , c .ID )
@@ -61,24 +65,31 @@ func (c *Channel) id() int64 {
6165 return c .ID
6266}
6367
68+ // SubChans returns a copy of the map of sub-channels associated with the
69+ // Channel.
6470func (c * Channel ) SubChans () map [int64 ]string {
6571 db .mu .RLock ()
6672 defer db .mu .RUnlock ()
6773 return copyMap (c .subChans )
6874}
6975
76+ // NestedChans returns a copy of the map of nested channels associated with the
77+ // Channel.
7078func (c * Channel ) NestedChans () map [int64 ]string {
7179 db .mu .RLock ()
7280 defer db .mu .RUnlock ()
7381 return copyMap (c .nestedChans )
7482}
7583
84+ // Trace returns a copy of the Channel's trace data.
7685func (c * Channel ) Trace () * ChannelTrace {
7786 db .mu .RLock ()
7887 defer db .mu .RUnlock ()
7988 return c .trace .copy ()
8089}
8190
91+ // ChannelMetrics holds connectivity state, target and call metrics for the
92+ // channel within channelz.
8293type ChannelMetrics struct {
8394 // The current connectivity state of the channel.
8495 State atomic.Pointer [connectivity.State ]
@@ -136,12 +147,16 @@ func strFromPointer(s *string) string {
136147 return * s
137148}
138149
150+ // String returns a string representation of the ChannelMetrics, including its
151+ // state, target, and call metrics.
139152func (c * ChannelMetrics ) String () string {
140153 return fmt .Sprintf ("State: %v, Target: %s, CallsStarted: %v, CallsSucceeded: %v, CallsFailed: %v, LastCallStartedTimestamp: %v" ,
141154 c .State .Load (), strFromPointer (c .Target .Load ()), c .CallsStarted .Load (), c .CallsSucceeded .Load (), c .CallsFailed .Load (), c .LastCallStartedTimestamp .Load (),
142155 )
143156}
144157
158+ // NewChannelMetricForTesting creates a new instance of ChannelMetrics with
159+ // specified initial values for testing purposes.
145160func NewChannelMetricForTesting (state connectivity.State , target string , started , succeeded , failed , timestamp int64 ) * ChannelMetrics {
146161 c := & ChannelMetrics {}
147162 c .State .Store (& state )
0 commit comments