2012-02-08 22:04:08 +01:00
|
|
|
// tests getlog as well as slow querying logging
|
|
|
|
|
|
|
|
glcol = db.getLogTest2;
|
2016-02-04 18:29:01 +01:00
|
|
|
glcol.drop();
|
2012-02-08 22:04:08 +01:00
|
|
|
|
|
|
|
contains = function(arr, func) {
|
|
|
|
var i = arr.length;
|
|
|
|
while (i--) {
|
|
|
|
if (func(arr[i])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-02-04 18:29:01 +01:00
|
|
|
};
|
2012-02-08 22:04:08 +01:00
|
|
|
|
|
|
|
// test doesn't work when talking to mongos
|
2016-03-09 18:17:50 +01:00
|
|
|
if (db.isMaster().msg != "isdbgrid") {
|
|
|
|
// run a slow query
|
|
|
|
glcol.save({"SENTINEL": 1});
|
|
|
|
glcol.findOne({
|
|
|
|
"SENTINEL": 1,
|
|
|
|
"$where": function() {
|
|
|
|
sleep(1000);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2012-02-08 22:04:08 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// run a slow update
|
2016-05-28 23:55:12 +02:00
|
|
|
glcol.update({
|
|
|
|
"SENTINEL": 1,
|
|
|
|
"$where": function() {
|
|
|
|
sleep(1000);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{"x": "x"});
|
2012-02-08 22:04:08 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
var resp = db.adminCommand({getLog: "global"});
|
|
|
|
assert(resp.ok == 1, "error executing getLog command");
|
|
|
|
assert(resp.log, "no log field");
|
|
|
|
assert(resp.log.length > 0, "no log lines");
|
2012-02-08 22:04:08 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// ensure that slow query is logged in detail
|
2016-05-28 23:55:12 +02:00
|
|
|
assert(contains(resp.log, function(v) {
|
|
|
|
print(v);
|
|
|
|
var opString = db.getMongo().useReadCommands() ? " find " : " query ";
|
|
|
|
var filterString = db.getMongo().useReadCommands() ? "filter:" : "query:";
|
|
|
|
return v.indexOf(opString) != -1 && v.indexOf(filterString) != -1 &&
|
|
|
|
v.indexOf("keysExamined:") != -1 && v.indexOf("docsExamined:") != -1 &&
|
|
|
|
v.indexOf("SENTINEL") != -1;
|
|
|
|
}));
|
2012-02-08 22:04:08 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
// same, but for update
|
2016-05-28 23:55:12 +02:00
|
|
|
assert(contains(resp.log, function(v) {
|
|
|
|
return v.indexOf(" update ") != -1 && v.indexOf("query") != -1 &&
|
|
|
|
v.indexOf("keysExamined:") != -1 && v.indexOf("docsExamined:") != -1 &&
|
|
|
|
v.indexOf("SENTINEL") != -1;
|
|
|
|
}));
|
2012-02-08 22:04:08 +01:00
|
|
|
}
|