mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-24 00:17:37 +01:00
SERVER-93699: Remove shell-only testing code from opcounters_active.js (#26319)
GitOrigin-RevId: 694acd84471d3000fb911cf5a993cbc96ed2191e
This commit is contained in:
parent
34822e2e1f
commit
7184dd30da
@ -184,7 +184,6 @@ globals:
|
||||
shellPrintHelper: true
|
||||
shellAutocomplete: true
|
||||
__autocomplete__: true
|
||||
getActiveCommands: true
|
||||
defaultPrompt: true
|
||||
___it___: true
|
||||
__promptWrapper__: true
|
||||
|
@ -1,35 +0,0 @@
|
||||
// checks that db.serverStatus will not throw errors when metrics tree is not present.
|
||||
//
|
||||
// @tags: [
|
||||
// # The test runs commands that are not allowed with security token: mapreduce.
|
||||
// not_allowed_with_signed_security_token
|
||||
// ]
|
||||
|
||||
// Test the getActiveCommands function
|
||||
// Should remove the listCollections section but keep the rest
|
||||
var testInput = {
|
||||
"isMaster": {"failed": NumberLong(0), "total": NumberLong(3)},
|
||||
"mapreduce": {"failed": NumberLong(0), "total": NumberLong(1)},
|
||||
"listCollections": {"failed": NumberLong(0), "total": NumberLong(0)}
|
||||
};
|
||||
var testExpected = {
|
||||
"isMaster": {"failed": NumberLong(0), "total": NumberLong(3)},
|
||||
"mapreduce": {"failed": NumberLong(0), "total": NumberLong(1)}
|
||||
};
|
||||
var testResult = getActiveCommands(testInput);
|
||||
|
||||
assert.eq(testResult, testExpected, "getActiveCommands did not return the expected result");
|
||||
|
||||
// Test that the serverstatus helper works
|
||||
var result = db.serverStatus();
|
||||
assert.neq(undefined, result, tojson(result));
|
||||
// Test that the metrics tree returns
|
||||
assert.neq(undefined, result.metrics, tojson(result));
|
||||
// Test that the metrics.commands tree returns
|
||||
assert.neq(undefined, result.metrics.commands, tojson(result));
|
||||
// Test that the metrics.commands.serverStatus value is non-zero
|
||||
assert.neq(0, result.metrics.commands.serverStatus.total, tojson(result));
|
||||
|
||||
// Test that the command returns successfully when no metrics tree is present
|
||||
var result = db.serverStatus({"metrics": 0});
|
||||
assert.eq(undefined, result.metrics, tojson(result));
|
12
jstests/core/opcounters_basic.js
Normal file
12
jstests/core/opcounters_basic.js
Normal file
@ -0,0 +1,12 @@
|
||||
// Checks that db.serverStatus will not throw errors when metrics tree is not present.
|
||||
|
||||
{
|
||||
const result = db.serverStatus().metrics.commands;
|
||||
// Test that the metrics.commands.serverStatus value is non-zero
|
||||
assert.neq(0, db.serverStatus().metrics.commands.serverStatus.total, tojson(result));
|
||||
}
|
||||
{
|
||||
// Test that the command returns successfully when no metrics tree is present
|
||||
const result = db.serverStatus({"metrics": 0});
|
||||
assert.eq(undefined, result.metrics, tojson(result));
|
||||
}
|
@ -1046,44 +1046,13 @@ DB.prototype.serverBuildInfo = function() {
|
||||
this.getSiblingDB("admin")._runCommandWithoutApiStrict({buildinfo: 1}));
|
||||
};
|
||||
|
||||
// Used to trim entries from the metrics.commands that have never been executed
|
||||
getActiveCommands = function(tree) {
|
||||
var result = {};
|
||||
for (var i in tree) {
|
||||
if (!tree.hasOwnProperty(i))
|
||||
continue;
|
||||
if (tree[i].hasOwnProperty("total")) {
|
||||
if (tree[i].total > 0) {
|
||||
result[i] = tree[i];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (i == "<UNKNOWN>") {
|
||||
if (tree[i] > 0) {
|
||||
result[i] = tree[i];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Handles nested commands
|
||||
var subStatus = getActiveCommands(tree[i]);
|
||||
if (Object.keys(subStatus).length > 0) {
|
||||
result[i] = tree[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
DB.prototype.serverStatus = function(options) {
|
||||
var cmd = {serverStatus: 1};
|
||||
if (options) {
|
||||
Object.extend(cmd, options);
|
||||
}
|
||||
var res = this._adminCommand(cmd);
|
||||
// Only prune if we have a metrics tree with commands.
|
||||
if (res.metrics && res.metrics.commands) {
|
||||
res.metrics.commands = getActiveCommands(res.metrics.commands);
|
||||
}
|
||||
return res;
|
||||
|
||||
return this._adminCommand(cmd);
|
||||
};
|
||||
|
||||
DB.prototype.hostInfo = function() {
|
||||
|
Loading…
Reference in New Issue
Block a user