Skip to content

Commit 7aeef3d

Browse files
author
Tudor Golubenco
committed
Correctly ignore command types we don't understand.
We used to glue packets together waiting for one that we understand, but one side effect was that we pick the wrong start time for the transaction. This fixes #160.
1 parent 04fff5b commit 7aeef3d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

protos/pgsql/pgsql.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ func (pgsql *Pgsql) pgsqlMessageParser(s *PgsqlStream) (bool, bool) {
430430
m.end = s.parseOffset
431431
m.Query = string(s.data[m.start+5 : m.end-1]) //without string termination
432432
m.toExport = true
433-
logp.Debug("pgsqldetailed", "Simple Query", "%s", m.Query)
433+
logp.Debug("pgsqldetailed", "Simple Query: %s", m.Query)
434434
return true, true
435435
} else {
436436
// wait for more
@@ -542,6 +542,11 @@ func (pgsql *Pgsql) pgsqlMessageParser(s *PgsqlStream) (bool, bool) {
542542
if len(s.data[s.parseOffset:]) >= length+1 {
543543
s.parseOffset += 1 //type
544544
s.parseOffset += length
545+
m.end = s.parseOffset
546+
547+
// ok and complete, but ignore
548+
m.toExport = false
549+
return true, true
545550
} else {
546551
// wait for more
547552
logp.Debug("pgsqldetailed", "Wait for more data 6")
@@ -675,6 +680,7 @@ func (pgsql *Pgsql) Parse(pkt *protos.Packet, tcptuple *common.TcpTuple,
675680
}
676681

677682
ok, complete := pgsql.pgsqlMessageParser(priv.Data[dir])
683+
//logp.Debug("pgsqldetailed", "MessageParser returned ok=%v complete=%v", ok, complete)
678684
if !ok {
679685
// drop this tcp stream. Will retry parsing with the next
680686
// segment in it

tests/pcaps/pgsql_rt.pcap

2.94 KB
Binary file not shown.

tests/test_0009_pgsql.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,19 @@ def test_insert_error(self):
4646
assert o["status"] == "Error"
4747
assert o["pgsql.error_code"] == "23505"
4848
assert o["pgsql.iserror"] is True
49+
50+
def test_login_rt(self):
51+
"""
52+
Response time for a query happing shortly after a command type we don't
53+
understand shouldn't have it's rt affected. Regression test for #
54+
"""
55+
self.render_config_template(
56+
pgsql_ports=[5432]
57+
)
58+
self.run_packetbeat(pcap="pgsql_rt.pcap")
59+
60+
objs = self.read_output()
61+
assert len(objs) == 1
62+
o = objs[0]
63+
assert o["method"] == "SELECT"
64+
assert o["responsetime"] == 38

0 commit comments

Comments
 (0)