Skip to content

Commit

Permalink
Merge pull request #1171 from nats-io/add_node_id_in_serverz
Browse files Browse the repository at this point in the history
[FIXED] Added missing cluster node ID in serverz endpoint
  • Loading branch information
kozlovic committed Mar 5, 2021
2 parents 88d1466 + 4a4ad7f commit 45e1925
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/monitor.go
Expand Up @@ -49,6 +49,7 @@ type Serverz struct {
GoVersion string `json:"go"`
State string `json:"state"`
Role string `json:"role,omitempty"`
NodeID string `json:"node_id,omitempty"`
Now time.Time `json:"now"`
Start time.Time `json:"start_time"`
Uptime string `json:"uptime"`
Expand Down Expand Up @@ -198,10 +199,12 @@ func (s *StanServer) handleServerz(w http.ResponseWriter, r *http.Request) {
return
}
var role string
var nodeID string
s.mu.RLock()
state := s.state
if s.raft != nil {
role = s.raft.State().String()
nodeID = s.info.NodeID
}
s.mu.RUnlock()

Expand Down Expand Up @@ -231,6 +234,7 @@ func (s *StanServer) handleServerz(w http.ResponseWriter, r *http.Request) {
GoVersion: runtime.Version(),
State: state.String(),
Role: role,
NodeID: nodeID,
Now: now,
Start: s.startTime,
Uptime: myUptime(now.Sub(s.startTime)),
Expand Down
13 changes: 12 additions & 1 deletion server/monitor_test.go
Expand Up @@ -1250,7 +1250,7 @@ func TestMonitorClusterRole(t *testing.T) {
s2 := runServerWithOpts(t, s2sOpts, test.n2Opts)
defer s2.Shutdown()

getLeader(t, 10*time.Second, s1, s2)
l := getLeader(t, 10*time.Second, s1, s2)

resp, body := getBody(t, ServerPath, expectedJSON)
resp.Body.Close()
Expand All @@ -1261,6 +1261,17 @@ func TestMonitorClusterRole(t *testing.T) {
if sz.Role != test.expectedRole {
t.Fatalf("Expected role to be %v, got %v", test.expectedRole, sz.Role)
}
var nodeID string
if test.name == "leader" {
nodeID = l.info.NodeID
} else if l == s1 {
nodeID = s2.info.NodeID
} else {
nodeID = s1.info.NodeID
}
if sz.NodeID != nodeID {
t.Fatalf("Expected nodeID to be %q, got %q", nodeID, sz.NodeID)
}
})
}
}
Expand Down
5 changes: 5 additions & 0 deletions server/server_redelivery_test.go
Expand Up @@ -17,6 +17,7 @@ import (
"encoding/json"
"fmt"
"net"
"runtime"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -114,6 +115,10 @@ func TestMultipleRedeliveries(t *testing.T) {
ackWait := int64(15 * time.Millisecond)
lowBound := int64(float64(ackWait) * 0.5)
highBound := int64(float64(ackWait) * 1.7)
// On Windows (especially Travis), be more generous
if runtime.GOOS == "windows" {
highBound = int64(35 * time.Millisecond)
}
errCh := make(chan error)
cb := func(m *stan.Msg) {
now := time.Now().UnixNano()
Expand Down

0 comments on commit 45e1925

Please sign in to comment.