Skip to content

Commit

Permalink
Correctly ignore command types we don't understand.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tudor Golubenco committed Jun 12, 2015
1 parent 04fff5b commit 7aeef3d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion protos/pgsql/pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (pgsql *Pgsql) pgsqlMessageParser(s *PgsqlStream) (bool, bool) {
m.end = s.parseOffset
m.Query = string(s.data[m.start+5 : m.end-1]) //without string termination
m.toExport = true
logp.Debug("pgsqldetailed", "Simple Query", "%s", m.Query)
logp.Debug("pgsqldetailed", "Simple Query: %s", m.Query)
return true, true
} else {
// wait for more
Expand Down Expand Up @@ -542,6 +542,11 @@ func (pgsql *Pgsql) pgsqlMessageParser(s *PgsqlStream) (bool, bool) {
if len(s.data[s.parseOffset:]) >= length+1 {
s.parseOffset += 1 //type
s.parseOffset += length
m.end = s.parseOffset

// ok and complete, but ignore
m.toExport = false
return true, true
} else {
// wait for more
logp.Debug("pgsqldetailed", "Wait for more data 6")
Expand Down Expand Up @@ -675,6 +680,7 @@ func (pgsql *Pgsql) Parse(pkt *protos.Packet, tcptuple *common.TcpTuple,
}

ok, complete := pgsql.pgsqlMessageParser(priv.Data[dir])
//logp.Debug("pgsqldetailed", "MessageParser returned ok=%v complete=%v", ok, complete)
if !ok {
// drop this tcp stream. Will retry parsing with the next
// segment in it
Expand Down
Binary file added tests/pcaps/pgsql_rt.pcap
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/test_0009_pgsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,19 @@ def test_insert_error(self):
assert o["status"] == "Error"
assert o["pgsql.error_code"] == "23505"
assert o["pgsql.iserror"] is True

def test_login_rt(self):
"""
Response time for a query happing shortly after a command type we don't
understand shouldn't have it's rt affected. Regression test for #
"""
self.render_config_template(
pgsql_ports=[5432]
)
self.run_packetbeat(pcap="pgsql_rt.pcap")

objs = self.read_output()
assert len(objs) == 1
o = objs[0]
assert o["method"] == "SELECT"
assert o["responsetime"] == 38

0 comments on commit 7aeef3d

Please sign in to comment.