Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channelz: re-add state for subchannels #7046

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,12 +1204,14 @@ func (ac *addrConn) updateConnectivityState(s connectivity.State, lastErr error)
close(ac.stateChan)
ac.stateChan = make(chan struct{})
ac.state = s
ac.channelz.ChannelMetrics.State.Store(&s)
if lastErr == nil {
channelz.Infof(logger, ac.channelz, "Subchannel Connectivity change to %v", s)
} else {
channelz.Infof(logger, ac.channelz, "Subchannel Connectivity change to %v, last error: %s", s, lastErr)
}
ac.acbw.updateState(s, lastErr)

dfawley marked this conversation as resolved.
Show resolved Hide resolved
}

// adjustParams updates parameters used to create transports upon
Expand Down
37 changes: 37 additions & 0 deletions test/channelz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,43 @@ func (s) TestCZGetChannel(t *testing.T) {
}
}

func (s) TestCZGetSubChannel(t *testing.T) {
e := tcpClearRREnv
e.balancer = ""
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
r := manual.NewBuilderWithScheme("whatever")
addrs := []resolver.Address{{Addr: te.srvAddr}}
r.InitialState(resolver.State{Addresses: addrs})
te.resolverScheme = r.Scheme()
te.clientConn(grpc.WithResolvers(r))
defer te.tearDown()
if err := verifyResultWithDelay(func() (bool, error) {
tcs, _ := channelz.GetTopChannels(0, 0)
if len(tcs) != 1 {
return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
}
scs := tcs[0].SubChans()
if len(scs) != 1 {
return false, fmt.Errorf("there should be one subchannel, not %d", len(scs))
}
var scid int64
for scid = range scs {
}
sc := channelz.GetSubChannel(scid)
if sc == nil {
return false, fmt.Errorf("subchannel with id %v is nil", scid)
}
state := sc.ChannelMetrics.State.Load()
if state == nil || *state != connectivity.Ready {
return false, fmt.Errorf("Got subchannel state=%v; want %q", state, connectivity.Ready)
}
return true, nil
}); err != nil {
t.Fatal(err)
}
}

func (s) TestCZGetServer(t *testing.T) {
e := tcpClearRREnv
te := newTest(t, e)
Expand Down