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
allow limit to traced message #1057
allow limit to traced message #1057
Conversation
97c25cf
to
cdee4ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I like this idea. But need some changes.
server/client.go
Outdated
|
||
origLength := len(msg) - LEN_CR_LF | ||
validLength := origLength | ||
if origLength > MAX_TRACED_MESSAGE_PRINTABLE_LEN { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be configurable.
server/client.go
Outdated
if origLength > MAX_TRACED_MESSAGE_PRINTABLE_LEN { | ||
validLength = MAX_TRACED_MESSAGE_PRINTABLE_LEN | ||
if validLength >= 3 { | ||
msg[validLength-3] = '.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not write over msg, should just do a slice on original and then add '...'.
8050f92
to
10a4884
Compare
@derekcollison What about this? |
server/client.go
Outdated
|
||
origLength := len(msg) - LEN_CR_LF | ||
var msgToWrite []byte | ||
if origLength > c.srv.opts.MaxTracedMessagePrintableLen { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opts should be grabbed under a lock, but only if we know we are tracing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
server/client.go
Outdated
origLength := len(msg) - LEN_CR_LF | ||
var msgToWrite []byte | ||
if origLength > c.srv.opts.MaxTracedMessagePrintableLen { | ||
msgToWrite = make([]byte, c.srv.opts.MaxTracedMessagePrintableLen+len("...")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid allocation here IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, we need to trick the log formatter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sure its possible and prefer a solution that does not do additional allocs if possible.
server/opts.go
Outdated
@@ -190,6 +190,8 @@ type Options struct { | |||
WriteDeadline time.Duration `json:"-"` | |||
MaxClosedClients int `json:"-"` | |||
LameDuckDuration time.Duration `json:"-"` | |||
// MaxTracedMessagePrintableLen is the maximum printable length for traced messages. | |||
MaxTracedMessagePrintableLen int `json:"max_traced_message_printable_len"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer shorter names here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any special concerns? I think it is more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaxTracedMsgLen
server/opts.go
Outdated
@@ -2482,6 +2486,9 @@ func setBaselineOptions(opts *Options) { | |||
if opts.ReconnectErrorReports == 0 { | |||
opts.ReconnectErrorReports = DEFAULT_RECONNECT_ERROR_REPORTS | |||
} | |||
if opts.MaxTracedMessagePrintableLen == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have something to designate no limit? -1 maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Will change default value for MaxTracedMessagePrintableLen
to -1
to designate no limit.
10a4884
to
f700d21
Compare
@derekcollison Comments addressed. PTAL. |
1f2df4f
to
6ea0067
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting there. Need tests to show default value unlimited, so in code should check for > 0 too if we use -1.
server/client.go
Outdated
origLength := len(msg) - LEN_CR_LF | ||
validLength := origLength | ||
formatter := "<<- MSG_PAYLOAD: [%q]" | ||
if origLength > c.srv.getOpts().MaxTracedMsgLen { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only call getOpts once. opts := c.srv.getOpts()
server/client.go
Outdated
// FIXME(dlc), allow limits to printable payload. | ||
c.Tracef("<<- MSG_PAYLOAD: [%q]", msg[:len(msg)-LEN_CR_LF]) | ||
|
||
origLength := len(msg) - LEN_CR_LF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just do..
if len(msg) - LEN_CR_LF > opts.MaxTracedMsgLen {
c.Tracef("<<- MSG_PAYLOAD: [\"%s...\"]", msg[:opts.MaxTracedMsgLen])
} else {
c.Tracef("<<- MSG_PAYLOAD: [%q]", msg[:len(msg)-LEN_CR_LF])
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way you do not need constants for formatters.
server/opts.go
Outdated
@@ -190,6 +190,8 @@ type Options struct { | |||
WriteDeadline time.Duration `json:"-"` | |||
MaxClosedClients int `json:"-"` | |||
LameDuckDuration time.Duration `json:"-"` | |||
// MaxTracedMsgLen is the maximum printable length for traced messages. | |||
MaxTracedMsgLen int `json:"max_traced_msg_len"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have deprecated use of json
tags in Options because we used to use this directly in monitoring object but we no longer do.
As a side note, if this is something that we would want to see in /varz
then it would have to be added in monitor.go. This can be done as separate PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I have use json:"-"
for MaxTracedMsgLen
.
6ea0067
to
1f52ac4
Compare
@kozlovic @derekcollison Comments addressed. PTAL. |
1f52ac4
to
5b62b62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. A few more changes I think needed.
server/opts.go
Outdated
@@ -2482,6 +2486,9 @@ func setBaselineOptions(opts *Options) { | |||
if opts.ReconnectErrorReports == 0 { | |||
opts.ReconnectErrorReports = DEFAULT_RECONNECT_ERROR_REPORTS | |||
} | |||
if opts.MaxTracedMsgLen == -1 { | |||
opts.MaxTracedMsgLen = MAX_TRACED_MSG_LEN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels too low for the default. The behavior now is to print the whole msg which I think we need to preserve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I think we should not set baseline for MaxTracedMsgLen
.
I have update the help info for max_traced_msg_len
to add -1 for unlimited
for describing that -1
is the default value for max_traced_msg_len
and it defaults to unlimited. This should be ok for now.
server/opts.go
Outdated
@@ -2551,6 +2558,7 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, | |||
fs.StringVar(&opts.TLSCert, "tlscert", "", "Server certificate file.") | |||
fs.StringVar(&opts.TLSKey, "tlskey", "", "Private key for server certificate.") | |||
fs.StringVar(&opts.TLSCaCert, "tlscacert", "", "Client certificate CA for verification.") | |||
fs.IntVar(&opts.MaxTracedMsgLen, "max_traced_msg_len", -1, "Maximum printable length for traced messages") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only sets via server binary. We have many people that embed the server in other Go apps so we need the default in that mode as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the way for lib users to initialize an instance for options? i have no idea about where to start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have thought about this:
- Default value for
max_traces_msg_len
is 0. This should be also adapting to lib usage for unlimited message length - Print traced message with customized length only when
MaxTracedMsgLen
is 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@derekcollison PTAL, again.
e66055b
to
0eaf2a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think we are looking good, still want to see some tests.
server/client.go
Outdated
// FIXME(dlc), allow limits to printable payload. | ||
c.Tracef("<<- MSG_PAYLOAD: [%q]", msg[:len(msg)-LEN_CR_LF]) | ||
|
||
opts := c.srv.getOpts() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could just do
maxTrace := c.srv.getOpts().MaxTracedMsgLen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
0eaf2a3
to
cd214fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for your patience. |
Resolves #None
Changes proposed in this pull request:
/cc @nats-io/core