Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to enable tracing the system account. (default: false) #1295

Merged
merged 4 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ Logging Options:
-r, --remote_syslog <addr> Syslog server addr (udp://localhost:514)
-D, --debug Enable debugging output
-V, --trace Trace the raw protocol
-VV Verbose trace (traces system account as well)
-DV Debug and trace
-DVV Debug and verbose trace (traces system account as well)

Authorization Options:
--user <user> User required for connections
Expand Down
4 changes: 4 additions & 0 deletions server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ func (c *client) initClient() {
c.debug = (atomic.LoadInt32(&c.srv.logging.debug) != 0)
c.trace = (atomic.LoadInt32(&c.srv.logging.trace) != 0)

if c.kind == SYSTEM && !c.srv.logging.traceSysAcc {
c.trace = false
}

// This is a scratch buffer used for processMsg()
// The msg header starts with "RMSG ", which can be used
// for both local and routes.
Expand Down
5 changes: 5 additions & 0 deletions server/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ func (s *Server) internalSendLoop(wg *sync.WaitGroup) {
c.pa.reply = []byte(pm.rply)
c.mu.Unlock()

if c.trace {
matthiashanel marked this conversation as resolved.
Show resolved Hide resolved
c.traceInOp(fmt.Sprintf(
"PUB %s %s %d", c.pa.subject, c.pa.reply, c.pa.size), nil)
}

// Add in NL
b = append(b, _CRLF_...)
c.processInboundClientMsg(b)
Expand Down
2 changes: 2 additions & 0 deletions server/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func (s *Server) ConfigureLogger() {
}

s.SetLogger(log, opts.Debug, opts.Trace)

s.logging.traceSysAcc = opts.TraceVerbose
}

// SetLogger sets the logger of the server
Expand Down
35 changes: 28 additions & 7 deletions server/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type Options struct {
ClientAdvertise string `json:"-"`
Trace bool `json:"-"`
Debug bool `json:"-"`
TraceVerbose bool `json:"-"`
NoLog bool `json:"-"`
NoSigs bool `json:"-"`
NoSublistCache bool `json:"-"`
Expand Down Expand Up @@ -513,6 +514,11 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error
case "trace":
o.Trace = v.(bool)
trackExplicitVal(o, &o.inConfig, "Trace", o.Trace)
case "trace_verbose":
o.TraceVerbose = v.(bool)
o.Trace = v.(bool)
trackExplicitVal(o, &o.inConfig, "TraceVerbose", o.TraceVerbose)
trackExplicitVal(o, &o.inConfig, "Trace", o.Trace)
case "logtime":
o.Logtime = v.(bool)
trackExplicitVal(o, &o.inConfig, "Logtime", o.Logtime)
Expand Down Expand Up @@ -3020,13 +3026,15 @@ func setBaselineOptions(opts *Options) {
func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, printTLSHelp func()) (*Options, error) {
opts := &Options{}
var (
showVersion bool
showHelp bool
showTLSHelp bool
signal string
configFile string
dbgAndTrace bool
err error
showVersion bool
showHelp bool
showTLSHelp bool
signal string
configFile string
dbgAndTrace bool
trcAndVerboseTrc bool
dbgAndTrcAndVerboseTrc bool
err error
)

fs.BoolVar(&showHelp, "h", false, "Show this message.")
Expand All @@ -3040,8 +3048,10 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp,
fs.BoolVar(&opts.Debug, "D", false, "Enable Debug logging.")
fs.BoolVar(&opts.Debug, "debug", false, "Enable Debug logging.")
fs.BoolVar(&opts.Trace, "V", false, "Enable Trace logging.")
fs.BoolVar(&trcAndVerboseTrc, "VV", false, "Enable Verbose Trace logging. (Traces system account as well)")
fs.BoolVar(&opts.Trace, "trace", false, "Enable Trace logging.")
fs.BoolVar(&dbgAndTrace, "DV", false, "Enable Debug and Trace logging.")
fs.BoolVar(&dbgAndTrcAndVerboseTrc, "DVV", false, "Enable Debug and Verbose Trace logging. (Traces system account as well)")
fs.BoolVar(&opts.Logtime, "T", true, "Timestamp log entries.")
fs.BoolVar(&opts.Logtime, "logtime", true, "Timestamp log entries.")
fs.StringVar(&opts.Username, "user", "", "Username required for connection.")
Expand Down Expand Up @@ -3129,13 +3139,20 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp,
// Keep track of the boolean flags that were explicitly set with their value.
fs.Visit(func(f *flag.Flag) {
switch f.Name {
case "DVV":
trackExplicitVal(FlagSnapshot, &FlagSnapshot.inCmdLine, "Debug", dbgAndTrcAndVerboseTrc)
trackExplicitVal(FlagSnapshot, &FlagSnapshot.inCmdLine, "Trace", dbgAndTrcAndVerboseTrc)
trackExplicitVal(FlagSnapshot, &FlagSnapshot.inCmdLine, "TraceVerbose", dbgAndTrcAndVerboseTrc)
case "DV":
trackExplicitVal(FlagSnapshot, &FlagSnapshot.inCmdLine, "Debug", dbgAndTrace)
trackExplicitVal(FlagSnapshot, &FlagSnapshot.inCmdLine, "Trace", dbgAndTrace)
case "D":
fallthrough
case "debug":
trackExplicitVal(FlagSnapshot, &FlagSnapshot.inCmdLine, "Debug", FlagSnapshot.Debug)
case "VV":
trackExplicitVal(FlagSnapshot, &FlagSnapshot.inCmdLine, "Trace", trcAndVerboseTrc)
trackExplicitVal(FlagSnapshot, &FlagSnapshot.inCmdLine, "TraceVerbose", trcAndVerboseTrc)
case "V":
fallthrough
case "trace":
Expand Down Expand Up @@ -3216,6 +3233,10 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp,
}
} else {
switch f.Name {
case "VV":
opts.Trace, opts.TraceVerbose = trcAndVerboseTrc, trcAndVerboseTrc
case "DVV":
opts.Trace, opts.Debug, opts.TraceVerbose = dbgAndTrcAndVerboseTrc, dbgAndTrcAndVerboseTrc, dbgAndTrcAndVerboseTrc
case "DV":
// Check value to support -DV=false
opts.Trace, opts.Debug = dbgAndTrace, dbgAndTrace
Expand Down
7 changes: 4 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ type Server struct {

logging struct {
sync.RWMutex
logger Logger
trace int32
debug int32
logger Logger
trace int32
debug int32
traceSysAcc bool
}

clientConnectURLs []string
Expand Down