Moving inbound tracing to the caller (client.parse)

Tracing for outgoing operations is always done while
holding the client lock.

Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
Matthias Hanel
2020-03-04 17:31:18 -05:00
parent fe373ac597
commit 6a1c3fc29b
7 changed files with 130 additions and 131 deletions

View File

@@ -221,7 +221,10 @@ func (c *client) parse(buf []byte) error {
} else {
arg = buf[c.as : i-c.drop]
}
if err := c.processPub(arg, trace); err != nil {
if trace {
c.traceInOp("PUB", arg)
}
if err := c.processPub(arg); err != nil {
return err
}
c.drop, c.as, c.state = 0, i+1, MSG_PAYLOAD
@@ -278,7 +281,10 @@ func (c *client) parse(buf []byte) error {
} else {
c.msgBuf = buf[c.as : i+1]
}
c.processInboundMsg(c.msgBuf, trace)
if trace {
c.traceMsg(c.msgBuf)
}
c.processInboundMsg(c.msgBuf)
c.argBuf, c.msgBuf = nil, nil
c.drop, c.as, c.state = 0, i+1, OP_START
// Drop all pub args
@@ -320,7 +326,10 @@ func (c *client) parse(buf []byte) error {
} else {
arg = buf[c.as : i-c.drop]
}
if err := c.processAccountSub(arg, trace); err != nil {
if trace {
c.traceInOp("A+", arg)
}
if err := c.processAccountSub(arg); err != nil {
return err
}
c.drop, c.as, c.state = 0, i+1, OP_START
@@ -356,6 +365,9 @@ func (c *client) parse(buf []byte) error {
} else {
arg = buf[c.as : i-c.drop]
}
if trace {
c.traceInOp("A-", arg)
}
c.processAccountUnsub(arg)
c.drop, c.as, c.state = 0, i+1, OP_START
default:
@@ -408,13 +420,25 @@ func (c *client) parse(buf []byte) error {
switch c.kind {
case CLIENT:
_, err = c.processSub(arg, false, trace)
if trace {
c.traceInOp("SUB", arg)
}
_, err = c.processSub(arg, false)
case ROUTER:
err = c.processRemoteSub(arg, trace)
if trace {
c.traceInOp("RS+", arg)
}
err = c.processRemoteSub(arg)
case GATEWAY:
err = c.processGatewayRSub(arg, trace)
if trace {
c.traceInOp("RS+", arg)
}
err = c.processGatewayRSub(arg)
case LEAF:
err = c.processLeafSub(arg, trace)
if trace {
c.traceInOp("LS+", arg)
}
err = c.processLeafSub(arg)
}
if err != nil {
return err
@@ -520,13 +544,25 @@ func (c *client) parse(buf []byte) error {
switch c.kind {
case CLIENT:
err = c.processUnsub(arg, trace)
if trace {
c.traceInOp("UNSUB", arg)
}
err = c.processUnsub(arg)
case ROUTER:
err = c.processRemoteUnsub(arg, trace)
if trace && c.srv != nil {
c.traceInOp("RS-", arg)
}
err = c.processRemoteUnsub(arg)
case GATEWAY:
err = c.processGatewayRUnsub(arg, trace)
if trace {
c.traceInOp("RS-", arg)
}
err = c.processGatewayRUnsub(arg)
case LEAF:
err = c.processLeafUnsub(arg, trace)
if trace {
c.traceInOp("LS-", arg)
}
err = c.processLeafUnsub(arg)
}
if err != nil {
return err
@@ -554,6 +590,9 @@ func (c *client) parse(buf []byte) error {
case OP_PING:
switch b {
case '\n':
if trace {
c.traceInOp("PING", nil)
}
c.processPing()
c.drop, c.state = 0, OP_START
}
@@ -574,6 +613,9 @@ func (c *client) parse(buf []byte) error {
case OP_PONG:
switch b {
case '\n':
if trace {
c.traceInOp("PONG", nil)
}
c.processPong()
c.drop, c.state = 0, OP_START
}
@@ -639,7 +681,10 @@ func (c *client) parse(buf []byte) error {
} else {
arg = buf[c.as : i-c.drop]
}
if err := c.processConnect(arg, trace); err != nil {
if trace {
c.traceInOp("CONNECT", removePassFromTrace(arg))
}
if err := c.processConnect(arg); err != nil {
return err
}
c.drop, c.state = 0, OP_START
@@ -695,9 +740,15 @@ func (c *client) parse(buf []byte) error {
}
var err error
if c.kind == ROUTER || c.kind == GATEWAY {
err = c.processRoutedMsgArgs(arg, trace)
if trace {
c.traceInOp("RMSG", arg)
}
err = c.processRoutedMsgArgs(arg)
} else if c.kind == LEAF {
err = c.processLeafMsgArgs(arg, trace)
if trace {
c.traceInOp("LMSG", arg)
}
err = c.processLeafMsgArgs(arg)
}
if err != nil {
return err
@@ -929,10 +980,19 @@ func (c *client) clonePubArg(trace bool) error {
switch c.kind {
case ROUTER, GATEWAY:
return c.processRoutedMsgArgs(c.argBuf, trace)
if trace {
c.traceInOp("RMSG", c.argBuf)
}
return c.processRoutedMsgArgs(c.argBuf)
case LEAF:
return c.processLeafMsgArgs(c.argBuf, trace)
if trace {
c.traceInOp("LMSG", c.argBuf)
}
return c.processLeafMsgArgs(c.argBuf)
default:
return c.processPub(c.argBuf, trace)
if trace {
c.traceInOp("PUB", c.argBuf)
}
return c.processPub(c.argBuf)
}
}