Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix negative response times for MongoDB. #231

Merged
merged 2 commits into from
Sep 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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