From 7aeef3de312a8dd3bbd237b2f1de19d09bc4f6e9 Mon Sep 17 00:00:00 2001 From: Tudor Golubenco Date: Fri, 12 Jun 2015 19:26:11 +0200 Subject: [PATCH] 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. --- protos/pgsql/pgsql.go | 8 +++++++- tests/pcaps/pgsql_rt.pcap | Bin 0 -> 3012 bytes tests/test_0009_pgsql.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/pcaps/pgsql_rt.pcap diff --git a/protos/pgsql/pgsql.go b/protos/pgsql/pgsql.go index d07e30b76a4..05f7b32484a 100644 --- a/protos/pgsql/pgsql.go +++ b/protos/pgsql/pgsql.go @@ -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 @@ -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") @@ -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 diff --git a/tests/pcaps/pgsql_rt.pcap b/tests/pcaps/pgsql_rt.pcap new file mode 100644 index 0000000000000000000000000000000000000000..764f399252c93e3cc667915f29dbccf48be5144c GIT binary patch literal 3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?r+sU{2=$u6}J zlbUXuA|}L`+VOhFtej4EsG_0{00q1Ew+mMB4>T--ebYV8?wc2kVA{#rapTGAWcSTV zIhfa-EwxM{r3dT+encFAM;3hGJi-^ij5cSloTK{h0h+S)(pz7}L?2D~FXQ`j6C?b{ i<;jjd(3~gXf1>c3-Ge>y9PfG?o#_0$+4&L)_x=aXv7EmE literal 0 HcmV?d00001 diff --git a/tests/test_0009_pgsql.py b/tests/test_0009_pgsql.py index 7aeb65db29f..9bbb6e0a1ef 100644 --- a/tests/test_0009_pgsql.py +++ b/tests/test_0009_pgsql.py @@ -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