mirror of https://github.com/grpc/grpc-go.git
channelz: re-add target and state (#7042)
This commit is contained in:
parent
55cd7a68b3
commit
dadbbfa286
|
|
@ -529,6 +529,7 @@ func (csm *connectivityStateManager) updateState(state connectivity.State) {
|
|||
return
|
||||
}
|
||||
csm.state = state
|
||||
csm.channelz.ChannelMetrics.State.Store(&state)
|
||||
csm.pubSub.Publish(state)
|
||||
|
||||
channelz.Infof(logger, csm.channelz, "Channel Connectivity change to %v", state)
|
||||
|
|
|
|||
|
|
@ -108,13 +108,13 @@ func GetServer(id int64) *Server {
|
|||
}
|
||||
|
||||
// RegisterChannel registers the given channel c in the channelz database with
|
||||
// ref as its reference name, and adds it to the child list of its parent.
|
||||
// parent == nil means no parent.
|
||||
// target as its target and reference name, and adds it to the child list of its
|
||||
// parent. parent == nil means no parent.
|
||||
//
|
||||
// Returns a unique channelz identifier assigned to this channel.
|
||||
//
|
||||
// If channelz is not turned ON, the channelz database is not mutated.
|
||||
func RegisterChannel(parent *Channel, ref string) *Channel {
|
||||
func RegisterChannel(parent *Channel, target string) *Channel {
|
||||
id := IDGen.genID()
|
||||
|
||||
if !IsOn() {
|
||||
|
|
@ -125,12 +125,13 @@ func RegisterChannel(parent *Channel, ref string) *Channel {
|
|||
|
||||
cn := &Channel{
|
||||
ID: id,
|
||||
RefName: ref,
|
||||
RefName: target,
|
||||
nestedChans: make(map[int64]string),
|
||||
subChans: make(map[int64]string),
|
||||
Parent: parent,
|
||||
trace: &ChannelTrace{CreationTime: time.Now(), Events: make([]*traceEvent, 0, getMaxTraceEntry())},
|
||||
}
|
||||
cn.ChannelMetrics.Target.Store(&target)
|
||||
db.addChannel(id, cn, isTopChannel, cn.getParentID())
|
||||
return cn
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,37 @@ func (s) TestCZServerRegistrationAndDeletion(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s) TestCZGetChannel(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))
|
||||
}
|
||||
target := tcs[0].ChannelMetrics.Target.Load()
|
||||
wantTarget := "whatever:///" + te.srvAddr
|
||||
if target == nil || *target != wantTarget {
|
||||
return false, fmt.Errorf("Got channelz target=%v; want %q", target, wantTarget)
|
||||
}
|
||||
state := tcs[0].ChannelMetrics.State.Load()
|
||||
if state == nil || *state != connectivity.Ready {
|
||||
return false, fmt.Errorf("Got channelz 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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue