Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SERVER-4729: log slow queries + improved test

  • Loading branch information...
commit 5899a6daa5170289b9db04a41670de7677acd03f 1 parent 816af21
Brandon Diamond authored erh committed
Showing with 42 additions and 0 deletions.
  1. +1 −0  db/ops/query.cpp
  2. +41 −0 jstests/getlog2.js
View
1  db/ops/query.cpp
@@ -816,6 +816,7 @@ namespace mongo {
curop.debug().ns = ns;
curop.debug().ntoreturn = pq.getNumToReturn();
+ curop.debug().query = jsobj;
curop.setQuery(jsobj);
if ( pq.couldBeCommand() ) {
View
41 jstests/getlog2.js
@@ -0,0 +1,41 @@
+// tests getlog as well as slow querying logging
+
+glcol = db.getLogTest2;
+glcol.drop()
+
+contains = function(arr, func) {
+ var i = arr.length;
+ while (i--) {
+ if (func(arr[i])) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// test doesn't work when talking to mongos
+if(db.isMaster().msg != "isdbgrid") {
+ // run a slow query
+ glcol.save({ "SENTINEL": 1 });
+ glcol.findOne({ "SENTINEL": 1, "$where": function() { sleep(1000); return true; } });
+
+ // run a slow update
+ glcol.update({ "SENTINEL": 1, "$where": function() { sleep(1000); return true; } }, { "x": "x" });
+
+ 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" );
+
+ // ensure that slow query is logged in detail
+ assert( contains(resp.log, function(v) {
+ print(v);
+ return v.indexOf(" query ") != -1 && v.indexOf("query:") != -1 && v.indexOf("SENTINEL") != -1;
+ }) );
+
+ // same, but for update
+ assert( contains(resp.log, function(v) {
+ print(v);
+ return v.indexOf(" update ") != -1 && v.indexOf("query:") != -1 && v.indexOf("SENTINEL") != -1;
+ }) );
+}
Please sign in to comment.
Something went wrong with that request. Please try again.