mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 11:24:44 -07:00
Adding logger for IPQueue
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
@@ -268,6 +268,16 @@ type Server struct {
|
||||
|
||||
// How often user logon fails due to the issuer account not being pinned.
|
||||
pinnedAccFail uint64
|
||||
|
||||
// This is a central logger for IPQueues when the number of pending
|
||||
// messages reaches a certain thresold (per queue)
|
||||
ipqLog *srvIPQueueLogger
|
||||
}
|
||||
|
||||
type srvIPQueueLogger struct {
|
||||
ch chan string
|
||||
done chan struct{}
|
||||
s *Server
|
||||
}
|
||||
|
||||
// For tracking JS nodes.
|
||||
@@ -1225,7 +1235,7 @@ func (s *Server) setSystemAccount(acc *Account) error {
|
||||
sid: 1,
|
||||
servers: make(map[string]*serverUpdate),
|
||||
replies: make(map[string]msgHandler),
|
||||
sendq: newIPQueue(), // of *pubMsg
|
||||
sendq: newIPQueue(ipQueue_Logger("System send", s.ipqLog)), // of *pubMsg
|
||||
resetCh: make(chan struct{}),
|
||||
sq: s.newSendQ(),
|
||||
statsz: eventsHBInterval,
|
||||
@@ -1595,6 +1605,8 @@ func (s *Server) Start() {
|
||||
s.grRunning = true
|
||||
s.grMu.Unlock()
|
||||
|
||||
s.startIPQLogger()
|
||||
|
||||
// Pprof http endpoint for the profiler.
|
||||
if opts.ProfPort != 0 {
|
||||
s.StartProfiler()
|
||||
@@ -1963,6 +1975,11 @@ func (s *Server) Shutdown() {
|
||||
doneExpected--
|
||||
}
|
||||
|
||||
// Stop the IPQueue logger (before the grWG.Wait() call)
|
||||
if s.ipqLog != nil {
|
||||
s.ipqLog.stop()
|
||||
}
|
||||
|
||||
// Wait for go routines to be done.
|
||||
s.grWG.Wait()
|
||||
|
||||
@@ -3601,3 +3618,35 @@ func (s *Server) updateRemoteSubscription(acc *Account, sub *subscription, delta
|
||||
|
||||
s.updateLeafNodes(acc, sub, delta)
|
||||
}
|
||||
|
||||
func (s *Server) startIPQLogger() {
|
||||
s.ipqLog = &srvIPQueueLogger{
|
||||
ch: make(chan string, 128),
|
||||
done: make(chan struct{}),
|
||||
s: s,
|
||||
}
|
||||
s.startGoRoutine(s.ipqLog.run)
|
||||
}
|
||||
|
||||
func (l *srvIPQueueLogger) stop() {
|
||||
close(l.done)
|
||||
}
|
||||
|
||||
func (l *srvIPQueueLogger) log(name string, pending int) {
|
||||
select {
|
||||
case l.ch <- fmt.Sprintf("%s queue pending size: %v", name, pending):
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (l *srvIPQueueLogger) run() {
|
||||
defer l.s.grWG.Done()
|
||||
for {
|
||||
select {
|
||||
case w := <-l.ch:
|
||||
l.s.Warnf("%s", w)
|
||||
case <-l.done:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user