mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 11:48:43 -07:00
Merge pull request #1166 from nats-io/add_servername_to_routestat
[ADDED] Server name in the RouteStat for statsz
This commit is contained in:
@@ -165,6 +165,7 @@ type ServerStats struct {
|
||||
// RouteStat holds route statistics.
|
||||
type RouteStat struct {
|
||||
ID uint64 `json:"rid"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Sent DataStats `json:"sent"`
|
||||
Received DataStats `json:"received"`
|
||||
Pending int `json:"pending"`
|
||||
@@ -413,6 +414,9 @@ func routeStat(r *client) *RouteStat {
|
||||
},
|
||||
Pending: int(r.out.pb),
|
||||
}
|
||||
if r.route != nil {
|
||||
rs.Name = r.route.remoteName
|
||||
}
|
||||
r.mu.Unlock()
|
||||
return rs
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ func runTrustedCluster(t *testing.T) (*Server, *Options, *Server, *Options, nkey
|
||||
optsA.TrustedKeys = []string{pub}
|
||||
optsA.AccountResolver = mr
|
||||
optsA.SystemAccount = apub
|
||||
optsA.ServerName = "A"
|
||||
// Add in dummy gateway
|
||||
optsA.Gateway.Name = "TEST CLUSTER 22"
|
||||
optsA.Gateway.Host = "127.0.0.1"
|
||||
@@ -108,6 +109,7 @@ func runTrustedCluster(t *testing.T) (*Server, *Options, *Server, *Options, nkey
|
||||
sa := RunServer(optsA)
|
||||
|
||||
optsB := nextServerOpts(optsA)
|
||||
optsB.ServerName = "B"
|
||||
optsB.Routes = RoutesFromStr(fmt.Sprintf("nats://%s:%d", optsA.Cluster.Host, optsA.Cluster.Port))
|
||||
sb := RunServer(optsB)
|
||||
|
||||
@@ -1322,6 +1324,27 @@ func TestServerEventsStatsZ(t *testing.T) {
|
||||
if lr := len(m3.Stats.Routes); lr != 1 {
|
||||
t.Fatalf("Expected a route, but got %d", lr)
|
||||
}
|
||||
if sr := m3.Stats.Routes[0]; sr.Name != "B" {
|
||||
t.Fatalf("Expected server A's route to B to have Name set to %q, got %q", "B", sr.Name)
|
||||
}
|
||||
|
||||
// Now query B and check that route's name is "A"
|
||||
subj = fmt.Sprintf(serverStatsReqSubj, sb.ID())
|
||||
ncs.SubscribeSync(subj)
|
||||
msg, err = ncs.Request(subj, nil, time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("Error trying to request statsz: %v", err)
|
||||
}
|
||||
m = ServerStatsMsg{}
|
||||
if err := json.Unmarshal(msg.Data, &m); err != nil {
|
||||
t.Fatalf("Error unmarshalling the statz json: %v", err)
|
||||
}
|
||||
if lr := len(m.Stats.Routes); lr != 1 {
|
||||
t.Fatalf("Expected a route, but got %d", lr)
|
||||
}
|
||||
if sr := m.Stats.Routes[0]; sr.Name != "A" {
|
||||
t.Fatalf("Expected server B's route to A to have Name set to %q, got %q", "A", sr.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerEventsPingStatsZ(t *testing.T) {
|
||||
|
||||
@@ -65,6 +65,7 @@ func setRouteProtoForTest(wantedProto int) int {
|
||||
|
||||
type route struct {
|
||||
remoteID string
|
||||
remoteName string
|
||||
didSolicit bool
|
||||
retry bool
|
||||
routeType RouteType
|
||||
@@ -413,6 +414,7 @@ func (c *client) processRouteInfo(info *Info) {
|
||||
c.route.authRequired = info.AuthRequired
|
||||
c.route.tlsRequired = info.TLSRequired
|
||||
c.route.gatewayURL = info.GatewayURL
|
||||
c.route.remoteName = info.Name
|
||||
// When sent through route INFO, if the field is set, it should be of size 1.
|
||||
if len(info.LeafNodeURLs) == 1 {
|
||||
c.route.leafnodeURL = info.LeafNodeURLs[0]
|
||||
@@ -1482,6 +1484,7 @@ func (s *Server) routeAcceptLoop(ch chan struct{}) {
|
||||
tlsReq := opts.Cluster.TLSConfig != nil
|
||||
info := Info{
|
||||
ID: s.info.ID,
|
||||
Name: s.info.Name,
|
||||
Version: s.info.Version,
|
||||
GoVersion: runtime.Version(),
|
||||
AuthRequired: false,
|
||||
|
||||
Reference in New Issue
Block a user