Skip to content

Commit

Permalink
Merge pull request #231 from tsg/fix_mongo_response_time
Browse files Browse the repository at this point in the history
Fix negative response times for MongoDB.
  • Loading branch information
ruflin committed Sep 8, 2015
2 parents b70fdd8 + 61b5242 commit 93afb9b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 1 addition & 4 deletions protos/mongodb/mongodb_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ type MongodbStream struct {

data []byte

parseOffset int
bytesReceived int

message *MongodbMessage
}

// Parser moves to next message in stream
func (stream *MongodbStream) PrepareForNewMessage() {
stream.data = stream.data[stream.message.messageLength:]
stream.message = &MongodbMessage{Ts: stream.message.Ts}
stream.message = nil
}

// The private data of a parser instance
Expand Down
2 changes: 1 addition & 1 deletion protos/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (redis *Redis) Init(test_mode bool, results chan common.MapStr) error {
func (stream *RedisStream) PrepareForNewMessage() {
stream.data = stream.data[stream.parseOffset:]
stream.parseOffset = 0
stream.message = &RedisMessage{Ts: stream.message.Ts}
stream.message = nil
stream.message.Bulks = []string{}
}

Expand Down
Binary file added tests/pcaps/mongodb_reply_request_reply.pcap
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/test_0025_mongodb_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,20 @@ def test_write_errors(self):
assert o["method"] == "insert"
assert o["status"] == "Error"
assert len(o["mongodb.error"]) > 0

def test_request_after_reply(self):
"""
Tests that the response time is correctly captured when a single
reply is seen before the request.
This is a regression test for bug #216.
"""
self.render_config_template(
mongodb_ports=[27017]
)
self.run_packetbeat(pcap="mongodb_reply_request_reply.pcap",
debug_selectors=["mongodb"])

objs = self.read_output()
o = objs[0]
assert o["type"] == "mongodb"
assert o["responsetime"] >= 0

0 comments on commit 93afb9b

Please sign in to comment.