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

allow limit to traced message #1057

Merged

Conversation

andyxning
Copy link
Contributor

Resolves #None

Changes proposed in this pull request:

  • allow limit to traced message

/cc @nats-io/core

@andyxning andyxning force-pushed the allow_limits_to_traced_message branch from 97c25cf to cdee4ab Compare July 5, 2019 08:31
Copy link
Member

@derekcollison derekcollison left a 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 {
Copy link
Member

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] = '.'
Copy link
Member

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 '...'.

@andyxning andyxning force-pushed the allow_limits_to_traced_message branch 8 times, most recently from 8050f92 to 10a4884 Compare July 10, 2019 09:20
@andyxning
Copy link
Contributor Author

@derekcollison What about this?

server/client.go Outdated

origLength := len(msg) - LEN_CR_LF
var msgToWrite []byte
if origLength > c.srv.opts.MaxTracedMessagePrintableLen {
Copy link
Member

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.

Copy link
Contributor Author

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("..."))
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer shorter names here.

Copy link
Contributor Author

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.

Copy link
Member

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 {
Copy link
Member

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?

Copy link
Contributor Author

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.

@andyxning andyxning force-pushed the allow_limits_to_traced_message branch from 10a4884 to f700d21 Compare July 12, 2019 05:49
@andyxning
Copy link
Contributor Author

@derekcollison Comments addressed. PTAL.

@andyxning andyxning force-pushed the allow_limits_to_traced_message branch 3 times, most recently from 1f2df4f to 6ea0067 Compare July 12, 2019 07:50
Copy link
Member

@derekcollison derekcollison left a 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 {
Copy link
Member

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/reload.go Show resolved Hide resolved
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
Copy link
Member

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])
}

Copy link
Member

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"`
Copy link
Member

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.

Copy link
Contributor Author

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.

@andyxning andyxning force-pushed the allow_limits_to_traced_message branch from 6ea0067 to 1f52ac4 Compare July 14, 2019 01:51
@andyxning
Copy link
Contributor Author

@kozlovic @derekcollison Comments addressed. PTAL.

@andyxning andyxning force-pushed the allow_limits_to_traced_message branch from 1f52ac4 to 5b62b62 Compare July 14, 2019 02:00
Copy link
Member

@derekcollison derekcollison left a 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
Copy link
Member

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.

Copy link
Contributor Author

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")
Copy link
Member

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.

Copy link
Contributor Author

@andyxning andyxning Jul 14, 2019

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derekcollison PTAL, again.

@andyxning andyxning force-pushed the allow_limits_to_traced_message branch 2 times, most recently from e66055b to 0eaf2a3 Compare July 14, 2019 05:13
Copy link
Member

@derekcollison derekcollison left a 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()
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@andyxning andyxning force-pushed the allow_limits_to_traced_message branch from 0eaf2a3 to cd214fc Compare July 15, 2019 03:39
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekcollison
Copy link
Member

Thanks for your patience.

@derekcollison derekcollison merged commit 7a3fb4e into nats-io:master Jul 15, 2019
@andyxning andyxning deleted the allow_limits_to_traced_message branch July 15, 2019 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants