Skip to content

Commit 55cd7a6

Browse files
authored
channelz: major cleanup / reorganization (#6969)
1 parent a1033b1 commit 55cd7a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2467
-2791
lines changed

balancer/balancer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ type BuildOptions struct {
232232
// implementations which do not communicate with a remote load balancer
233233
// server can ignore this field.
234234
Authority string
235-
// ChannelzParentID is the parent ClientConn's channelz ID.
236-
ChannelzParentID *channelz.Identifier
235+
// ChannelzParent is the parent ClientConn's channelz channel.
236+
ChannelzParent channelz.Identifier
237237
// CustomUserAgent is the custom user agent set on the parent ClientConn.
238238
// The balancer should set the same custom user agent if it creates a
239239
// ClientConn.

balancer/grpclb/grpclb_remote_balancer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (lb *lbBalancer) newRemoteBalancerCCWrapper() error {
246246
// Explicitly set pickfirst as the balancer.
247247
dopts = append(dopts, grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"pick_first"}`))
248248
dopts = append(dopts, grpc.WithResolvers(lb.manualResolver))
249-
dopts = append(dopts, grpc.WithChannelzParentID(lb.opt.ChannelzParentID))
249+
dopts = append(dopts, grpc.WithChannelzParentID(lb.opt.ChannelzParent))
250250

251251
// Enable Keepalive for grpclb client.
252252
dopts = append(dopts, grpc.WithKeepaliveParams(keepalive.ClientParameters{

balancer_wrapper.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ func newCCBalancerWrapper(cc *ClientConn) *ccBalancerWrapper {
7272
ccb := &ccBalancerWrapper{
7373
cc: cc,
7474
opts: balancer.BuildOptions{
75-
DialCreds: cc.dopts.copts.TransportCredentials,
76-
CredsBundle: cc.dopts.copts.CredsBundle,
77-
Dialer: cc.dopts.copts.Dialer,
78-
Authority: cc.authority,
79-
CustomUserAgent: cc.dopts.copts.UserAgent,
80-
ChannelzParentID: cc.channelzID,
81-
Target: cc.parsedTarget,
75+
DialCreds: cc.dopts.copts.TransportCredentials,
76+
CredsBundle: cc.dopts.copts.CredsBundle,
77+
Dialer: cc.dopts.copts.Dialer,
78+
Authority: cc.authority,
79+
CustomUserAgent: cc.dopts.copts.UserAgent,
80+
ChannelzParent: cc.channelz,
81+
Target: cc.parsedTarget,
8282
},
8383
serializer: grpcsync.NewCallbackSerializer(ctx),
8484
serializerCancel: cancel,
@@ -155,14 +155,14 @@ func (ccb *ccBalancerWrapper) switchTo(name string) {
155155
func (ccb *ccBalancerWrapper) buildLoadBalancingPolicy(name string) {
156156
builder := balancer.Get(name)
157157
if builder == nil {
158-
channelz.Warningf(logger, ccb.cc.channelzID, "Channel switches to new LB policy %q, since the specified LB policy %q was not registered", PickFirstBalancerName, name)
158+
channelz.Warningf(logger, ccb.cc.channelz, "Channel switches to new LB policy %q, since the specified LB policy %q was not registered", PickFirstBalancerName, name)
159159
builder = newPickfirstBuilder()
160160
} else {
161-
channelz.Infof(logger, ccb.cc.channelzID, "Channel switches to new LB policy %q", name)
161+
channelz.Infof(logger, ccb.cc.channelz, "Channel switches to new LB policy %q", name)
162162
}
163163

164164
if err := ccb.balancer.SwitchTo(builder); err != nil {
165-
channelz.Errorf(logger, ccb.cc.channelzID, "Channel failed to build new LB policy %q: %v", name, err)
165+
channelz.Errorf(logger, ccb.cc.channelz, "Channel failed to build new LB policy %q: %v", name, err)
166166
return
167167
}
168168
ccb.curBalancerName = builder.Name()
@@ -175,7 +175,7 @@ func (ccb *ccBalancerWrapper) close() {
175175
ccb.mu.Lock()
176176
ccb.closed = true
177177
ccb.mu.Unlock()
178-
channelz.Info(logger, ccb.cc.channelzID, "ccBalancerWrapper: closing")
178+
channelz.Info(logger, ccb.cc.channelz, "ccBalancerWrapper: closing")
179179
ccb.serializer.Schedule(func(context.Context) {
180180
if ccb.balancer == nil {
181181
return
@@ -212,7 +212,7 @@ func (ccb *ccBalancerWrapper) NewSubConn(addrs []resolver.Address, opts balancer
212212
}
213213
ac, err := ccb.cc.newAddrConnLocked(addrs, opts)
214214
if err != nil {
215-
channelz.Warningf(logger, ccb.cc.channelzID, "acBalancerWrapper: NewSubConn: failed to newAddrConn: %v", err)
215+
channelz.Warningf(logger, ccb.cc.channelz, "acBalancerWrapper: NewSubConn: failed to newAddrConn: %v", err)
216216
return nil, err
217217
}
218218
acbw := &acBalancerWrapper{
@@ -304,7 +304,7 @@ func (acbw *acBalancerWrapper) updateState(s connectivity.State, err error) {
304304
}
305305

306306
func (acbw *acBalancerWrapper) String() string {
307-
return fmt.Sprintf("SubConn(id:%d)", acbw.ac.channelzID.Int())
307+
return fmt.Sprintf("SubConn(id:%d)", acbw.ac.channelz.ID)
308308
}
309309

310310
func (acbw *acBalancerWrapper) UpdateAddresses(addrs []resolver.Address) {

channelz/service/func_linux.go

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ func convertToPtypesDuration(sec int64, usec int64) *durpb.Duration {
3333
}
3434

3535
func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOption {
36+
if skopts == nil {
37+
return nil
38+
}
3639
var opts []*channelzpb.SocketOption
3740
if skopts.Linger != nil {
3841
additional, err := anypb.New(&channelzpb.SocketOptionLinger{

0 commit comments

Comments
 (0)