summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Fawley <dfawley@google.com>2024-05-03 10:50:09 -0700
committerGitHub <noreply@github.com>2024-05-03 10:50:09 -0700
commita87e923c4bc9b99d93c9936fa8096e736d5431e0 (patch)
treeed21db5b48cc9ee85ae2f3730e32cdc4f1e055c2
parent273fe145d03df516018cf4642e6987e027ffc0f5 (diff)
downloadgrpc-grpc-go-a87e923c4bc9b99d93c9936fa8096e736d5431e0.tar.gz
channelz: fix missing Target on SubChannel type (#7189)
-rw-r--r--clientconn.go4
-rw-r--r--test/channelz_test.go4
2 files changed, 8 insertions, 0 deletions
diff --git a/clientconn.go b/clientconn.go
index dfc3225f..2359f94b 100644
--- a/clientconn.go
+++ b/clientconn.go
@@ -842,6 +842,9 @@ func (cc *ClientConn) newAddrConnLocked(addrs []resolver.Address, opts balancer.
stateChan: make(chan struct{}),
}
ac.ctx, ac.cancel = context.WithCancel(cc.ctx)
+ // Start with our address set to the first address; this may be updated if
+ // we connect to different addresses.
+ ac.channelz.ChannelMetrics.Target.Store(&addrs[0].Addr)
channelz.AddTraceEvent(logger, ac.channelz, 0, &channelz.TraceEvent{
Desc: "Subchannel created",
@@ -1304,6 +1307,7 @@ func (ac *addrConn) resetTransport() {
func (ac *addrConn) tryAllAddrs(ctx context.Context, addrs []resolver.Address, connectDeadline time.Time) error {
var firstConnErr error
for _, addr := range addrs {
+ ac.channelz.ChannelMetrics.Target.Store(&addr.Addr)
if ctx.Err() != nil {
return errConnClosing
}
diff --git a/test/channelz_test.go b/test/channelz_test.go
index 44ad33de..7d8ea136 100644
--- a/test/channelz_test.go
+++ b/test/channelz_test.go
@@ -158,6 +158,10 @@ func (s) TestCZGetSubChannel(t *testing.T) {
if sc == nil {
return false, fmt.Errorf("subchannel with id %v is nil", scid)
}
+ target := sc.ChannelMetrics.Target.Load()
+ if target == nil || !strings.HasPrefix(*target, "localhost") {
+ t.Fatalf("subchannel target must never be set incorrectly; got: %v, want <HasPrefix('localhost')>", target)
+ }
state := sc.ChannelMetrics.State.Load()
if state == nil || *state != connectivity.Ready {
return false, fmt.Errorf("Got subchannel state=%v; want %q", state, connectivity.Ready)