mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-16 19:14:41 -07:00
Replace reloaded varz field with config_load_time
This commit is contained in:
@@ -84,7 +84,7 @@ Hello World
|
||||
On Unix systems, the NATS server responds to the following signals:
|
||||
|
||||
| Signal | Result |
|
||||
| ------- | --------------------------------------|
|
||||
| ------- | ------------------------------------- |
|
||||
| SIGKILL | Kills the process immediately |
|
||||
| SIGINT | Stops the server gracefully |
|
||||
| SIGUSR1 | Reopens the log file for log rotation |
|
||||
|
||||
@@ -399,7 +399,7 @@ type Varz struct {
|
||||
SlowConsumers int64 `json:"slow_consumers"`
|
||||
Subscriptions uint32 `json:"subscriptions"`
|
||||
HTTPReqStats map[string]uint64 `json:"http_req_stats"`
|
||||
Reloaded uint64 `json:"reloaded"`
|
||||
ConfigLoadTime time.Time `json:"config_load_time"`
|
||||
}
|
||||
|
||||
func myUptime(d time.Duration) string {
|
||||
@@ -479,7 +479,7 @@ func (s *Server) HandleVarz(w http.ResponseWriter, r *http.Request) {
|
||||
v.OutBytes = atomic.LoadInt64(&s.outBytes)
|
||||
v.SlowConsumers = atomic.LoadInt64(&s.slowConsumers)
|
||||
v.Subscriptions = s.sl.Count()
|
||||
v.Reloaded = s.reloaded
|
||||
v.ConfigLoadTime = s.configTime
|
||||
s.httpReqStats[VarzPath]++
|
||||
// Need a copy here since s.httpReqStas can change while doing
|
||||
// the marshaling down below.
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FlagSnapshot captures the server options as specified by CLI flags at
|
||||
@@ -259,7 +260,7 @@ func (s *Server) Reload() error {
|
||||
err = s.reloadOptions(newOpts)
|
||||
if err == nil {
|
||||
s.mu.Lock()
|
||||
s.reloaded++
|
||||
s.configTime = time.Now()
|
||||
s.mu.Unlock()
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -19,14 +19,12 @@ import (
|
||||
// not start with a config file.
|
||||
func TestConfigReloadNoConfigFile(t *testing.T) {
|
||||
server := New(&Options{})
|
||||
if reloaded := server.NumReloads(); reloaded != 0 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 0\ngot: %d", reloaded)
|
||||
}
|
||||
loaded := server.ConfigTime()
|
||||
if server.Reload() == nil {
|
||||
t.Fatal("Expected Reload to return an error")
|
||||
}
|
||||
if reloaded := server.NumReloads(); reloaded != 0 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 0\ngot: %d", reloaded)
|
||||
if reloaded := server.ConfigTime(); reloaded != loaded {
|
||||
t.Fatalf("ConfigTime is incorrect.\nexpected: %s\ngot: %s", loaded, reloaded)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +34,7 @@ func TestConfigReloadUnsupported(t *testing.T) {
|
||||
server, opts, config := newServerWithSymlinkConfig(t, "tmp.conf", "./configs/reload/test.conf")
|
||||
defer os.Remove(config)
|
||||
|
||||
if reloaded := server.NumReloads(); reloaded != 0 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 0\ngot: %d", reloaded)
|
||||
}
|
||||
loaded := server.ConfigTime()
|
||||
|
||||
golden := &Options{
|
||||
ConfigFile: config,
|
||||
@@ -86,8 +82,8 @@ func TestConfigReloadUnsupported(t *testing.T) {
|
||||
golden, opts)
|
||||
}
|
||||
|
||||
if reloaded := server.NumReloads(); reloaded != 0 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 0\ngot: %d", reloaded)
|
||||
if reloaded := server.ConfigTime(); reloaded != loaded {
|
||||
t.Fatalf("ConfigTime is incorrect.\nexpected: %s\ngot: %s", loaded, reloaded)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,9 +92,7 @@ func TestConfigReloadInvalidConfig(t *testing.T) {
|
||||
server, opts, config := newServerWithSymlinkConfig(t, "tmp.conf", "./configs/reload/test.conf")
|
||||
defer os.Remove(config)
|
||||
|
||||
if reloaded := server.NumReloads(); reloaded != 0 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 0\ngot: %d", reloaded)
|
||||
}
|
||||
loaded := server.ConfigTime()
|
||||
|
||||
golden := &Options{
|
||||
ConfigFile: config,
|
||||
@@ -146,8 +140,8 @@ func TestConfigReloadInvalidConfig(t *testing.T) {
|
||||
golden, opts)
|
||||
}
|
||||
|
||||
if reloaded := server.NumReloads(); reloaded != 0 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 0\ngot: %d", reloaded)
|
||||
if reloaded := server.ConfigTime(); reloaded != loaded {
|
||||
t.Fatalf("ConfigTime is incorrect.\nexpected: %s\ngot: %s", loaded, reloaded)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,9 +150,7 @@ func TestConfigReload(t *testing.T) {
|
||||
server, opts, config := newServerWithSymlinkConfig(t, "tmp.conf", "./configs/reload/test.conf")
|
||||
defer os.Remove(config)
|
||||
|
||||
if reloaded := server.NumReloads(); reloaded != 0 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 0\ngot: %d", reloaded)
|
||||
}
|
||||
loaded := server.ConfigTime()
|
||||
|
||||
golden := &Options{
|
||||
ConfigFile: config,
|
||||
@@ -232,8 +224,8 @@ func TestConfigReload(t *testing.T) {
|
||||
t.Fatal("Expected NoAdvertise to be true")
|
||||
}
|
||||
|
||||
if reloaded := server.NumReloads(); reloaded != 1 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 1\ngot: %d", reloaded)
|
||||
if reloaded := server.ConfigTime(); !reloaded.After(loaded) {
|
||||
t.Fatalf("ConfigTime is incorrect.\nexpected greater than: %s\ngot: %s", loaded, reloaded)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ type Server struct {
|
||||
grRunning bool
|
||||
grWG sync.WaitGroup // to wait on various go routines
|
||||
cproto int64 // number of clients supporting async INFO
|
||||
reloaded uint64 // number of times server config has been reloaded
|
||||
configTime time.Time // last time config was loaded
|
||||
logging struct {
|
||||
sync.RWMutex
|
||||
logger Logger
|
||||
@@ -119,13 +119,15 @@ func New(opts *Options) *Server {
|
||||
clientConnectURLs: make(map[string]struct{}),
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
s := &Server{
|
||||
configFile: opts.ConfigFile,
|
||||
info: info,
|
||||
sl: NewSublist(),
|
||||
opts: opts,
|
||||
done: make(chan bool, 1),
|
||||
start: time.Now(),
|
||||
start: now,
|
||||
configTime: now,
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
@@ -919,12 +921,11 @@ func (s *Server) NumSubscriptions() uint32 {
|
||||
return subs
|
||||
}
|
||||
|
||||
// NumReloads returns the number of times the server config has been reloaded.
|
||||
func (s *Server) NumReloads() uint64 {
|
||||
// ConfigTime will report the last time the server configuration was loaded.
|
||||
func (s *Server) ConfigTime() time.Time {
|
||||
s.mu.Lock()
|
||||
reloaded := s.reloaded
|
||||
s.mu.Unlock()
|
||||
return reloaded
|
||||
defer s.mu.Unlock()
|
||||
return s.configTime
|
||||
}
|
||||
|
||||
// Addr will return the net.Addr object for the current listener.
|
||||
|
||||
@@ -70,17 +70,15 @@ func TestSignalToReloadConfig(t *testing.T) {
|
||||
s := RunServer(opts)
|
||||
defer s.Shutdown()
|
||||
|
||||
if reloaded := s.NumReloads(); reloaded != 0 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 0\ngot: %d", reloaded)
|
||||
}
|
||||
loaded := s.ConfigTime()
|
||||
|
||||
// This should cause config to be reloaded.
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGHUP)
|
||||
// Wait a bit for action to be performed
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
if reloaded := s.NumReloads(); reloaded != 1 {
|
||||
t.Fatalf("Reloaded is incorrect.\nexpected: 1\ngot: %d", reloaded)
|
||||
if reloaded := s.ConfigTime(); !reloaded.After(loaded) {
|
||||
t.Fatalf("ConfigTime is incorrect.\nexpected greater than: %s\ngot: %s", loaded, reloaded)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user