2012-02-08 22:04:08 +01:00
|
|
|
// tests getlog as well as slow querying logging
|
2018-01-31 01:45:42 +01:00
|
|
|
//
|
|
|
|
// @tags: [
|
|
|
|
// # This test attempts to perform a find command and see that it ran using the getLog command.
|
|
|
|
// # The former operation may be routed to a secondary in the replica set, whereas the latter must
|
|
|
|
// # be routed to the primary.
|
|
|
|
// assumes_read_preference_unchanged,
|
|
|
|
// does_not_support_stepdowns,
|
|
|
|
// ]
|
2012-02-08 22:04:08 +01:00
|
|
|
|
2019-03-28 20:06:23 +01:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
2017-10-15 03:54:02 +02:00
|
|
|
|
2019-03-28 20:06:23 +01:00
|
|
|
// We turn off gossiping the mongo shell's clusterTime because it causes the slow command log
|
|
|
|
// messages to get truncated since they'll exceed 512 characters. The truncated log messages
|
|
|
|
// will fail to match the find and update patterns defined later on in this test.
|
|
|
|
TestData.skipGossipingClusterTime = true;
|
2012-02-08 22:04:08 +01:00
|
|
|
|
2019-03-28 20:06:23 +01:00
|
|
|
const glcol = db.getLogTest2;
|
|
|
|
glcol.drop();
|
|
|
|
|
|
|
|
function contains(arr, func) {
|
|
|
|
let i = arr.length;
|
|
|
|
while (i--) {
|
|
|
|
if (func(arr[i])) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-08 22:04:08 +01:00
|
|
|
}
|
2019-03-28 20:06:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// test doesn't work when talking to mongos
|
|
|
|
if (db.isMaster().msg === "isdbgrid") {
|
|
|
|
return;
|
2012-02-08 22:04:08 +01:00
|
|
|
}
|
|
|
|
|
2019-03-28 20:06:23 +01:00
|
|
|
// 1. Run a slow query
|
2016-03-09 18:17:50 +01:00
|
|
|
glcol.save({"SENTINEL": 1});
|
|
|
|
glcol.findOne({
|
|
|
|
"SENTINEL": 1,
|
|
|
|
"$where": function() {
|
|
|
|
sleep(1000);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2012-02-08 22:04:08 +01:00
|
|
|
|
2019-03-28 20:06:23 +01:00
|
|
|
const query = assert.commandWorked(db.adminCommand({getLog: "global"}));
|
|
|
|
assert(query.log, "no log field");
|
|
|
|
assert.gt(query.log.length, 0, "no log lines");
|
|
|
|
|
|
|
|
// Ensure that slow query is logged in detail.
|
|
|
|
assert(contains(query.log, function(v) {
|
|
|
|
print(v);
|
|
|
|
const opString = db.getMongo().useReadCommands() ? " find " : " query ";
|
|
|
|
const filterString = db.getMongo().useReadCommands() ? "filter:" : "command:";
|
|
|
|
return v.indexOf(opString) != -1 && v.indexOf(filterString) != -1 &&
|
|
|
|
v.indexOf("keysExamined:") != -1 && v.indexOf("docsExamined:") != -1 &&
|
|
|
|
v.indexOf("SENTINEL") != -1;
|
|
|
|
}));
|
|
|
|
|
|
|
|
// 2. 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
|
|
|
|
2019-03-28 20:06:23 +01:00
|
|
|
const update = assert.commandWorked(db.adminCommand({getLog: "global"}));
|
|
|
|
assert(update.log, "no log field");
|
|
|
|
assert.gt(update.log.length, 0, "no log lines");
|
2012-02-08 22:04:08 +01:00
|
|
|
|
2019-03-28 20:06:23 +01:00
|
|
|
// Ensure that slow update is logged in deail.
|
|
|
|
assert(contains(update.log, function(v) {
|
2016-05-28 23:55:12 +02:00
|
|
|
print(v);
|
2017-04-28 20:18:50 +02:00
|
|
|
return v.indexOf(" update ") != -1 && v.indexOf("command") != -1 &&
|
2016-05-28 23:55:12 +02:00
|
|
|
v.indexOf("keysExamined:") != -1 && v.indexOf("docsExamined:") != -1 &&
|
|
|
|
v.indexOf("SENTINEL") != -1;
|
|
|
|
}));
|
2019-03-28 20:06:23 +01:00
|
|
|
})();
|