summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2017-07-12 09:22:58 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2017-07-12 09:22:58 -0400
commit02c46a3d4b270530335f542ad2926c50f1ba1b1f (patch)
tree9d8955d1077f529e9567da8f62d5aa07bddff652 /jstests
parentc92d85fea435f64aedec07a2b42cbc16833ede82 (diff)
downloadmongo-02c46a3d4b270530335f542ad2926c50f1ba1b1f.tar.gz
SERVER-28495 FTDC for MongoS
Diffstat (limited to 'jstests')
-rw-r--r--jstests/auth/lib/commands_lib.js5
-rw-r--r--jstests/core/diagdata.js26
-rw-r--r--jstests/libs/ftdc.js102
-rw-r--r--jstests/noPassthrough/ftdc_setdirectory.js118
-rw-r--r--jstests/noPassthroughWithMongod/ftdc_params.js54
5 files changed, 229 insertions, 76 deletions
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js
index 701e8080f1d..d1e677af08b 100644
--- a/jstests/auth/lib/commands_lib.js
+++ b/jstests/auth/lib/commands_lib.js
@@ -2756,7 +2756,6 @@ var authCommandsLib = {
{
testname: "getDiagnosticData",
command: {getDiagnosticData: 1},
- skipSharded: true,
testcases: [
{
runOnDb: adminDbName,
@@ -2765,6 +2764,10 @@ var authCommandsLib = {
{resource: {cluster: true}, actions: ["serverStatus"]},
{resource: {cluster: true}, actions: ["replSetGetStatus"]},
{resource: {db: "local", collection: "oplog.rs"}, actions: ["collStats"]},
+ {
+ resource: {cluster: true},
+ actions: ["connPoolStats"]
+ }, // Only needed against mongos
]
},
{runOnDb: firstDbName, roles: {}},
diff --git a/jstests/core/diagdata.js b/jstests/core/diagdata.js
index 490e4a3eb2b..6938f8c5102 100644
--- a/jstests/core/diagdata.js
+++ b/jstests/core/diagdata.js
@@ -1,4 +1,5 @@
// Test that verifies getDiagnosticData returns FTDC data
+load('jstests/libs/ftdc.js');
(function() {
"use strict";
@@ -6,28 +7,5 @@
// Verify we require admin database
assert.commandFailed(db.diagdata.runCommand("getDiagnosticData"));
- // We need to retry a few times if run this test immediately after mongod is started as FTDC may
- // not have run yet.
- var foundGoodDocument = false;
-
- for (var i = 0; i < 60; ++i) {
- var result = db.adminCommand("getDiagnosticData");
- assert.commandWorked(result);
-
- var data = result.data;
-
- if (!data.hasOwnProperty("start")) {
- // Wait a little longer for FTDC to start
- sleep(500);
- } else {
- // Check for a few common properties to ensure we got data
- assert(data.hasOwnProperty("serverStatus"),
- "does not have 'serverStatus' in '" + tojson(data) + "'");
- assert(data.hasOwnProperty("end"), "does not have 'end' in '" + tojson(data) + "'");
- foundGoodDocument = true;
- }
- }
- assert(foundGoodDocument,
- "getDiagnosticData failed to return a non-empty command, is FTDC running?");
-
+ verifyGetDiagnosticData(db.getSiblingDB('admin'));
})();
diff --git a/jstests/libs/ftdc.js b/jstests/libs/ftdc.js
new file mode 100644
index 00000000000..7d327d39852
--- /dev/null
+++ b/jstests/libs/ftdc.js
@@ -0,0 +1,102 @@
+/**
+ * Utility test functions for FTDC
+ */
+'use strict';
+
+/**
+ * Verify that getDiagnosticData is working correctly.
+ */
+function verifyGetDiagnosticData(adminDb) {
+ // We need to retry a few times if run this test immediately after mongod is started as FTDC may
+ // not have run yet.
+ var foundGoodDocument = false;
+
+ for (var i = 0; i < 60 && foundGoodDocument == false; ++i) {
+ var result = adminDb.runCommand("getDiagnosticData");
+ assert.commandWorked(result);
+
+ var data = result.data;
+
+ if (!data.hasOwnProperty("start")) {
+ // Wait a little longer for FTDC to start
+ jsTestLog("Running getDiagnosticData: " + tojson(result));
+
+ sleep(500);
+ } else {
+ // Check for a few common properties to ensure we got data
+ assert(data.hasOwnProperty("serverStatus"),
+ "does not have 'serverStatus' in '" + tojson(data) + "'");
+ assert(data.hasOwnProperty("end"), "does not have 'end' in '" + tojson(data) + "'");
+ foundGoodDocument = true;
+
+ jsTestLog("Got good getDiagnosticData: " + tojson(result));
+ }
+ }
+
+ assert(foundGoodDocument,
+ "getDiagnosticData failed to return a non-empty command, is FTDC running?");
+}
+
+/**
+ * Validate all the common FTDC parameters are set correctly and can be manipulated.
+ */
+function verifyCommonFTDCParameters(adminDb, isEnabled) {
+ // Are we running against MongoS?
+ var isMongos = ("isdbgrid" == adminDb.runCommand("ismaster").msg);
+
+ // Check the defaults are correct
+ //
+ function getparam(field) {
+ var q = {getParameter: 1};
+ q[field] = 1;
+
+ var ret = adminDb.runCommand(q);
+ return ret[field];
+ }
+
+ // Verify the defaults are as we documented them
+ assert.eq(getparam("diagnosticDataCollectionEnabled"), isEnabled);
+ assert.eq(getparam("diagnosticDataCollectionPeriodMillis"), 1000);
+ assert.eq(getparam("diagnosticDataCollectionDirectorySizeMB"), 200);
+ assert.eq(getparam("diagnosticDataCollectionFileSizeMB"), 10);
+ assert.eq(getparam("diagnosticDataCollectionSamplesPerChunk"), 300);
+ assert.eq(getparam("diagnosticDataCollectionSamplesPerInterimUpdate"), 10);
+
+ function setparam(obj) {
+ var ret = adminDb.runCommand(Object.extend({setParameter: 1}, obj));
+ return ret;
+ }
+
+ if (!isMongos) {
+ // The MongoS specific behavior for diagnosticDataCollectionEnabled is tested in
+ // ftdc_setdirectory.js.
+ assert.commandWorked(setparam({"diagnosticDataCollectionEnabled": 1}));
+ }
+ assert.commandWorked(setparam({"diagnosticDataCollectionPeriodMillis": 100}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionDirectorySizeMB": 10}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionFileSizeMB": 1}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionSamplesPerChunk": 2}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionSamplesPerInterimUpdate": 2}));
+
+ // Negative tests - set values below minimums
+ assert.commandFailed(setparam({"diagnosticDataCollectionPeriodMillis": 1}));
+ assert.commandFailed(setparam({"diagnosticDataCollectionDirectorySizeMB": 1}));
+ assert.commandFailed(setparam({"diagnosticDataCollectionSamplesPerChunk": 1}));
+ assert.commandFailed(setparam({"diagnosticDataCollectionSamplesPerInterimUpdate": 1}));
+
+ // Negative test - set file size bigger then directory size
+ assert.commandWorked(setparam({"diagnosticDataCollectionDirectorySizeMB": 10}));
+ assert.commandFailed(setparam({"diagnosticDataCollectionFileSizeMB": 100}));
+
+ // Negative test - set directory size less then file size
+ assert.commandWorked(setparam({"diagnosticDataCollectionDirectorySizeMB": 100}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionFileSizeMB": 50}));
+ assert.commandFailed(setparam({"diagnosticDataCollectionDirectorySizeMB": 10}));
+
+ // Reset
+ assert.commandWorked(setparam({"diagnosticDataCollectionFileSizeMB": 10}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionDirectorySizeMB": 200}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionPeriodMillis": 1000}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionSamplesPerChunk": 300}));
+ assert.commandWorked(setparam({"diagnosticDataCollectionSamplesPerInterimUpdate": 10}));
+} \ No newline at end of file
diff --git a/jstests/noPassthrough/ftdc_setdirectory.js b/jstests/noPassthrough/ftdc_setdirectory.js
new file mode 100644
index 00000000000..c1173055e2a
--- /dev/null
+++ b/jstests/noPassthrough/ftdc_setdirectory.js
@@ -0,0 +1,118 @@
+/**
+ * Test that verifies FTDC works in mongos.
+ */
+load('jstests/libs/ftdc.js');
+
+(function() {
+ 'use strict';
+ let testPath1 = MongoRunner.toRealPath('ftdc_setdir1');
+ let testPath2 = MongoRunner.toRealPath('ftdc_setdir2');
+ let testPath3 = MongoRunner.toRealPath('ftdc_setdir3');
+ let testLog3 = testPath3 + "mongos_ftdc.log";
+
+ // Make the log file directory for mongos.
+ mkdir(testPath3);
+
+ // Startup 3 mongos:
+ // 1. Normal MongoS with no log file to verify FTDC can be startup at runtime with a path.
+ // 2. MongoS with explict diagnosticDataCollectionDirectoryPath setParameter at startup.
+ // 3. MongoS with log file to verify automatic FTDC path computation works.
+ let st = new ShardingTest({
+ shards: 1,
+ mongos: {
+ s0: {verbose: 0},
+ s1: {setParameter: {diagnosticDataCollectionDirectoryPath: testPath2}},
+ s2: {logpath: testLog3}
+ }
+ });
+
+ let admin1 = st.s0.getDB('admin');
+ let admin2 = st.s1.getDB('admin');
+ let admin3 = st.s2.getDB('admin');
+
+ function setParam(admin, obj) {
+ var ret = admin.runCommand(Object.extend({setParameter: 1}, obj));
+ return ret;
+ }
+
+ function getParam(admin, field) {
+ var q = {getParameter: 1};
+ q[field] = 1;
+
+ var ret = admin.runCommand(q);
+ assert.commandWorked(ret);
+ return ret[field];
+ }
+
+ // Verify FTDC can be started at runtime.
+ function verifyFTDCDisabledOnStartup() {
+ jsTestLog("Running verifyFTDCDisabledOnStartup");
+ verifyCommonFTDCParameters(admin1, false);
+
+ // 1. Try to enable and fail
+ assert.commandFailed(setParam(admin1, {"diagnosticDataCollectionEnabled": 1}));
+
+ // 2. Set path and succeed
+ assert.commandWorked(
+ setParam(admin1, {"diagnosticDataCollectionDirectoryPath": testPath2}));
+
+ // 3. Set path again and fail
+ assert.commandFailed(
+ setParam(admin1, {"diagnosticDataCollectionDirectoryPath": testPath2}));
+
+ // 4. Enable successfully
+ assert.commandWorked(setParam(admin1, {"diagnosticDataCollectionEnabled": 1}));
+
+ // 5. Validate getDiagnosticData returns FTDC data now
+ jsTestLog("Verifying FTDC getDiagnosticData");
+ verifyGetDiagnosticData(admin1);
+ }
+
+ // Verify FTDC is already running if there was a path set at startup.
+ function verifyFTDCStartsWithPath() {
+ jsTestLog("Running verifyFTDCStartsWithPath");
+ verifyCommonFTDCParameters(admin2, true);
+
+ // 1. Set path fail
+ assert.commandFailed(
+ setParam(admin2, {"diagnosticDataCollectionDirectoryPath": testPath2}));
+
+ // 2. Enable successfully
+ assert.commandWorked(setParam(admin2, {"diagnosticDataCollectionEnabled": 1}));
+
+ // 3. Validate getDiagnosticData returns FTDC data now
+ jsTestLog("Verifying FTDC getDiagnosticData");
+ verifyGetDiagnosticData(admin2);
+ }
+
+ function normpath(path) {
+ return path.replace(/\\/g, "/");
+ }
+
+ // Verify FTDC is already running if there was a path set at startup.
+ function verifyFTDCStartsWithLogFile() {
+ jsTestLog("Running verifyFTDCStartsWithLogFile");
+ verifyCommonFTDCParameters(admin3, true);
+
+ // 1. Verify that path is computed correctly.
+ let computedPath = getParam(admin3, "diagnosticDataCollectionDirectoryPath");
+ assert.eq(normpath(computedPath), normpath(testPath3 + "mongos_ftdc.diagnostic.data"));
+
+ // 2. Set path fail
+ assert.commandFailed(
+ setParam(admin3, {"diagnosticDataCollectionDirectoryPath": testPath2}));
+
+ // 3. Enable successfully
+ assert.commandWorked(setParam(admin3, {"diagnosticDataCollectionEnabled": 1}));
+
+ // 4. Validate getDiagnosticData returns FTDC data now
+ jsTestLog("Verifying FTDC getDiagnosticData");
+ verifyGetDiagnosticData(admin3);
+ }
+
+ verifyFTDCDisabledOnStartup();
+ verifyFTDCStartsWithPath();
+ verifyFTDCStartsWithLogFile();
+
+ st.stop();
+})();
diff --git a/jstests/noPassthroughWithMongod/ftdc_params.js b/jstests/noPassthroughWithMongod/ftdc_params.js
index ced6c1b5675..08714040fcb 100644
--- a/jstests/noPassthroughWithMongod/ftdc_params.js
+++ b/jstests/noPassthroughWithMongod/ftdc_params.js
@@ -1,58 +1,10 @@
// FTDC test cases
//
+load('jstests/libs/ftdc.js');
+
(function() {
'use strict';
var admin = db.getSiblingDB("admin");
- // Check the defaults are correct
- //
- function getparam(field) {
- var q = {getParameter: 1};
- q[field] = 1;
-
- var ret = admin.runCommand(q);
- return ret[field];
- }
-
- // Verify the defaults are as we documented them
- assert.eq(getparam("diagnosticDataCollectionEnabled"), true);
- assert.eq(getparam("diagnosticDataCollectionPeriodMillis"), 1000);
- assert.eq(getparam("diagnosticDataCollectionDirectorySizeMB"), 200);
- assert.eq(getparam("diagnosticDataCollectionFileSizeMB"), 10);
- assert.eq(getparam("diagnosticDataCollectionSamplesPerChunk"), 300);
- assert.eq(getparam("diagnosticDataCollectionSamplesPerInterimUpdate"), 10);
-
- function setparam(obj) {
- var ret = admin.runCommand(Object.extend({setParameter: 1}, obj));
- return ret;
- }
-
- assert.commandWorked(setparam({"diagnosticDataCollectionEnabled": 1}));
- assert.commandWorked(setparam({"diagnosticDataCollectionPeriodMillis": 100}));
- assert.commandWorked(setparam({"diagnosticDataCollectionDirectorySizeMB": 10}));
- assert.commandWorked(setparam({"diagnosticDataCollectionFileSizeMB": 1}));
- assert.commandWorked(setparam({"diagnosticDataCollectionSamplesPerChunk": 2}));
- assert.commandWorked(setparam({"diagnosticDataCollectionSamplesPerInterimUpdate": 2}));
-
- // Negative tests - set values below minimums
- assert.commandFailed(setparam({"diagnosticDataCollectionPeriodMillis": 1}));
- assert.commandFailed(setparam({"diagnosticDataCollectionDirectorySizeMB": 1}));
- assert.commandFailed(setparam({"diagnosticDataCollectionSamplesPerChunk": 1}));
- assert.commandFailed(setparam({"diagnosticDataCollectionSamplesPerInterimUpdate": 1}));
-
- // Negative test - set file size bigger then directory size
- assert.commandWorked(setparam({"diagnosticDataCollectionDirectorySizeMB": 10}));
- assert.commandFailed(setparam({"diagnosticDataCollectionFileSizeMB": 100}));
-
- // Negative test - set directory size less then file size
- assert.commandWorked(setparam({"diagnosticDataCollectionDirectorySizeMB": 100}));
- assert.commandWorked(setparam({"diagnosticDataCollectionFileSizeMB": 50}));
- assert.commandFailed(setparam({"diagnosticDataCollectionDirectorySizeMB": 10}));
-
- // Reset
- assert.commandWorked(setparam({"diagnosticDataCollectionFileSizeMB": 10}));
- assert.commandWorked(setparam({"diagnosticDataCollectionDirectorySizeMB": 200}));
- assert.commandWorked(setparam({"diagnosticDataCollectionPeriodMillis": 1000}));
- assert.commandWorked(setparam({"diagnosticDataCollectionSamplesPerChunk": 300}));
- assert.commandWorked(setparam({"diagnosticDataCollectionSamplesPerInterimUpdate": 10}));
+ verifyCommonFTDCParameters(admin, true);
})();